##// END OF EJS Templates
doc: translate from :hg:`help config.SECTION` to a valid link to hgrc.5.html...
FUJIWARA Katsunori -
r28076:18c6b271 default
parent child Browse files
Show More
@@ -1,58 +1,61 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 #
2 #
3 # runrst - register custom roles and run correct writer
3 # runrst - register custom roles and run correct writer
4 #
4 #
5 # Copyright 2010 Matt Mackall <mpm@selenic.com> and others
5 # Copyright 2010 Matt Mackall <mpm@selenic.com> and others
6 #
6 #
7 # This software may be used and distributed according to the terms of the
7 # This software may be used and distributed according to the terms of the
8 # GNU General Public License version 2 or any later version.
8 # GNU General Public License version 2 or any later version.
9
9
10 """usage: %s WRITER args...
10 """usage: %s WRITER args...
11
11
12 where WRITER is the name of a Docutils writer such as 'html' or 'manpage'
12 where WRITER is the name of a Docutils writer such as 'html' or 'manpage'
13 """
13 """
14
14
15 import sys
15 import sys
16 try:
16 try:
17 from docutils.parsers.rst import roles
17 from docutils.parsers.rst import roles
18 from docutils.core import publish_cmdline
18 from docutils.core import publish_cmdline
19 from docutils import nodes, utils
19 from docutils import nodes, utils
20 except ImportError:
20 except ImportError:
21 sys.stderr.write("abort: couldn't generate documentation: docutils "
21 sys.stderr.write("abort: couldn't generate documentation: docutils "
22 "module is missing\n")
22 "module is missing\n")
23 sys.stderr.write("please install python-docutils or see "
23 sys.stderr.write("please install python-docutils or see "
24 "http://docutils.sourceforge.net/\n")
24 "http://docutils.sourceforge.net/\n")
25 sys.exit(-1)
25 sys.exit(-1)
26
26
27 def role_hg(name, rawtext, text, lineno, inliner,
27 def role_hg(name, rawtext, text, lineno, inliner,
28 options={}, content=[]):
28 options={}, content=[]):
29 text = "hg " + utils.unescape(text)
29 text = "hg " + utils.unescape(text)
30 linktext = nodes.literal(rawtext, text)
30 linktext = nodes.literal(rawtext, text)
31 parts = text.split()
31 parts = text.split()
32 cmd, args = parts[1], parts[2:]
32 cmd, args = parts[1], parts[2:]
33 refuri = "hg.1.html#%s" % cmd
33 refuri = "hg.1.html#%s" % cmd
34 if cmd == 'help' and args:
34 if cmd == 'help' and args:
35 if args[0] == 'config':
35 if args[0] == 'config':
36 # :hg:`help config`
36 # :hg:`help config`
37 refuri = "hgrc.5.html"
37 refuri = "hgrc.5.html"
38 elif args[0].startswith('config.'):
39 # :hg:`help config.SECTION...`
40 refuri = "hgrc.5.html#%s" % args[0].split('.', 2)[1]
38 elif len(args) >= 2 and args[0] == '-c':
41 elif len(args) >= 2 and args[0] == '-c':
39 # :hg:`help -c COMMAND ...` is equivalent to :hg:`COMMAND`
42 # :hg:`help -c COMMAND ...` is equivalent to :hg:`COMMAND`
40 # (mainly for :hg:`help -c config`)
43 # (mainly for :hg:`help -c config`)
41 refuri = "hg.1.html#%s" % args[1]
44 refuri = "hg.1.html#%s" % args[1]
42 else:
45 else:
43 refuri = "hg.1.html#%s" % args[0]
46 refuri = "hg.1.html#%s" % args[0]
44 node = nodes.reference(rawtext, '', linktext,
47 node = nodes.reference(rawtext, '', linktext,
45 refuri=refuri)
48 refuri=refuri)
46 return [node], []
49 return [node], []
47
50
48 roles.register_local_role("hg", role_hg)
51 roles.register_local_role("hg", role_hg)
49
52
50 if __name__ == "__main__":
53 if __name__ == "__main__":
51 if len(sys.argv) < 2:
54 if len(sys.argv) < 2:
52 sys.stderr.write(__doc__ % sys.argv[0])
55 sys.stderr.write(__doc__ % sys.argv[0])
53 sys.exit(1)
56 sys.exit(1)
54
57
55 writer = sys.argv[1]
58 writer = sys.argv[1]
56 del sys.argv[1]
59 del sys.argv[1]
57
60
58 publish_cmdline(writer_name=writer)
61 publish_cmdline(writer_name=writer)
General Comments 0
You need to be logged in to leave comments. Login now