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