doc: make links for hg role
authorMartin Geisler <mg@aragost.com>
Fri, 23 Apr 2010 09:53:25 +0200
changeset 10974 854ac04d712c
parent 10973 49a07f441496
child 10975 db4d7077f48d
doc: make links for hg role The system has a bit of smartness: :hg:`update` -> links to hg.1.html#update :hg:`help diffs` -> links to hg.1.html#diffs
doc/runrst
--- a/doc/runrst	Thu Apr 22 10:24:49 2010 +0200
+++ b/doc/runrst	Fri Apr 23 09:53:25 2010 +0200
@@ -19,7 +19,14 @@
 
 def role_hg(name, rawtext, text, lineno, inliner,
             options={}, content=[]):
-    node = nodes.literal(rawtext, "hg " + utils.unescape(text, True))
+    text = "hg " + utils.unescape(text)
+    linktext = nodes.literal(rawtext, text)
+    parts = text.split()
+    cmd, args = parts[1], parts[2:]
+    if cmd == 'help' and args:
+        cmd = args[0] # link to 'dates' for 'hg help dates'
+    node = nodes.reference(rawtext, '', linktext,
+                           refuri="hg.1.html#%s" % cmd)
     return [node], []
 
 roles.register_local_role("hg", role_hg)