##// END OF EJS Templates
doc: make links for hg role...
Martin Geisler -
r10974:854ac04d default
parent child Browse files
Show More
@@ -1,35 +1,42 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 from docutils.parsers.rst import roles
16 from docutils.parsers.rst import roles
17 from docutils.core import publish_cmdline
17 from docutils.core import publish_cmdline
18 from docutils import nodes, utils
18 from docutils import nodes, utils
19
19
20 def role_hg(name, rawtext, text, lineno, inliner,
20 def role_hg(name, rawtext, text, lineno, inliner,
21 options={}, content=[]):
21 options={}, content=[]):
22 node = nodes.literal(rawtext, "hg " + utils.unescape(text, True))
22 text = "hg " + utils.unescape(text)
23 linktext = nodes.literal(rawtext, text)
24 parts = text.split()
25 cmd, args = parts[1], parts[2:]
26 if cmd == 'help' and args:
27 cmd = args[0] # link to 'dates' for 'hg help dates'
28 node = nodes.reference(rawtext, '', linktext,
29 refuri="hg.1.html#%s" % cmd)
23 return [node], []
30 return [node], []
24
31
25 roles.register_local_role("hg", role_hg)
32 roles.register_local_role("hg", role_hg)
26
33
27 if __name__ == "__main__":
34 if __name__ == "__main__":
28 if len(sys.argv) < 2:
35 if len(sys.argv) < 2:
29 sys.stderr.write(__doc__ % sys.argv[0])
36 sys.stderr.write(__doc__ % sys.argv[0])
30 sys.exit(1)
37 sys.exit(1)
31
38
32 writer = sys.argv[1]
39 writer = sys.argv[1]
33 del sys.argv[1]
40 del sys.argv[1]
34
41
35 publish_cmdline(writer_name=writer)
42 publish_cmdline(writer_name=writer)
General Comments 0
You need to be logged in to leave comments. Login now