Show More
@@ -1,47 +1,49 | |||||
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 " | |||
|
24 | "http://docutils.sourceforge.net/\n") | |||
23 | sys.exit(-1) |
|
25 | sys.exit(-1) | |
24 |
|
26 | |||
25 | def role_hg(name, rawtext, text, lineno, inliner, |
|
27 | def role_hg(name, rawtext, text, lineno, inliner, | |
26 | options={}, content=[]): |
|
28 | options={}, content=[]): | |
27 | text = "hg " + utils.unescape(text) |
|
29 | text = "hg " + utils.unescape(text) | |
28 | linktext = nodes.literal(rawtext, text) |
|
30 | linktext = nodes.literal(rawtext, text) | |
29 | parts = text.split() |
|
31 | parts = text.split() | |
30 | cmd, args = parts[1], parts[2:] |
|
32 | cmd, args = parts[1], parts[2:] | |
31 | if cmd == 'help' and args: |
|
33 | if cmd == 'help' and args: | |
32 | cmd = args[0] # link to 'dates' for 'hg help dates' |
|
34 | cmd = args[0] # link to 'dates' for 'hg help dates' | |
33 | node = nodes.reference(rawtext, '', linktext, |
|
35 | node = nodes.reference(rawtext, '', linktext, | |
34 | refuri="hg.1.html#%s" % cmd) |
|
36 | refuri="hg.1.html#%s" % cmd) | |
35 | return [node], [] |
|
37 | return [node], [] | |
36 |
|
38 | |||
37 | roles.register_local_role("hg", role_hg) |
|
39 | roles.register_local_role("hg", role_hg) | |
38 |
|
40 | |||
39 | if __name__ == "__main__": |
|
41 | if __name__ == "__main__": | |
40 | if len(sys.argv) < 2: |
|
42 | if len(sys.argv) < 2: | |
41 | sys.stderr.write(__doc__ % sys.argv[0]) |
|
43 | sys.stderr.write(__doc__ % sys.argv[0]) | |
42 | sys.exit(1) |
|
44 | sys.exit(1) | |
43 |
|
45 | |||
44 | writer = sys.argv[1] |
|
46 | writer = sys.argv[1] | |
45 | del sys.argv[1] |
|
47 | del sys.argv[1] | |
46 |
|
48 | |||
47 | publish_cmdline(writer_name=writer) |
|
49 | publish_cmdline(writer_name=writer) |
General Comments 0
You need to be logged in to leave comments.
Login now