##// END OF EJS Templates
runrst: try to be more helpful if docutils is not installed
Nicolas Dumazet -
r11707:13d79a7b stable
parent child Browse files
Show More
@@ -1,42 +1,47 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 try:
17 from docutils.core import publish_cmdline
17 from docutils.parsers.rst import roles
18 from docutils import nodes, utils
18 from docutils.core import publish_cmdline
19 from docutils import nodes, utils
20 except ImportError:
21 sys.stderr.write("abort: couldn't generate documentation: docutils "
22 "module is missing\n")
23 sys.exit(-1)
19
24
20 def role_hg(name, rawtext, text, lineno, inliner,
25 def role_hg(name, rawtext, text, lineno, inliner,
21 options={}, content=[]):
26 options={}, content=[]):
22 text = "hg " + utils.unescape(text)
27 text = "hg " + utils.unescape(text)
23 linktext = nodes.literal(rawtext, text)
28 linktext = nodes.literal(rawtext, text)
24 parts = text.split()
29 parts = text.split()
25 cmd, args = parts[1], parts[2:]
30 cmd, args = parts[1], parts[2:]
26 if cmd == 'help' and args:
31 if cmd == 'help' and args:
27 cmd = args[0] # link to 'dates' for 'hg help dates'
32 cmd = args[0] # link to 'dates' for 'hg help dates'
28 node = nodes.reference(rawtext, '', linktext,
33 node = nodes.reference(rawtext, '', linktext,
29 refuri="hg.1.html#%s" % cmd)
34 refuri="hg.1.html#%s" % cmd)
30 return [node], []
35 return [node], []
31
36
32 roles.register_local_role("hg", role_hg)
37 roles.register_local_role("hg", role_hg)
33
38
34 if __name__ == "__main__":
39 if __name__ == "__main__":
35 if len(sys.argv) < 2:
40 if len(sys.argv) < 2:
36 sys.stderr.write(__doc__ % sys.argv[0])
41 sys.stderr.write(__doc__ % sys.argv[0])
37 sys.exit(1)
42 sys.exit(1)
38
43
39 writer = sys.argv[1]
44 writer = sys.argv[1]
40 del sys.argv[1]
45 del sys.argv[1]
41
46
42 publish_cmdline(writer_name=writer)
47 publish_cmdline(writer_name=writer)
General Comments 0
You need to be logged in to leave comments. Login now