[PATCH 2 of 4] doc: translate from :hg:`help config` to a valid link to hgrc.5.html

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Thu Feb 11 09:18:26 EST 2016


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1455200134 -32400
#      Thu Feb 11 23:15:34 2016 +0900
# Node ID ca4a0f06eefd9db09635ec7c88da1c41e79c6b3b
# Parent  55f023455fd8450ffe8807058c2cb75ae1a87281
doc: translate from :hg:`help config` to a valid link to hgrc.5.html

Before this patch, ":hg:`help config`" in online help text is
translated to a link to "hg.1.html#config" in HTML, even though actual
"hg help config" shows not help for "hg config" command but "config"
help topic, and all of current ":hg:`help config`" expects the latter.

This patch translates from ":hg:`help config`" in online help text to
a link to "hgrc.5.html" in HTML as expected.

This patch also allows ":hg:`help -c COMMAND`" style to link
"hg.1.html#COMMAND" for readability.

diff --git a/doc/runrst b/doc/runrst
--- a/doc/runrst
+++ b/doc/runrst
@@ -30,10 +30,19 @@ def role_hg(name, rawtext, text, lineno,
     linktext = nodes.literal(rawtext, text)
     parts = text.split()
     cmd, args = parts[1], parts[2:]
+    refuri = "hg.1.html#%s" % cmd
     if cmd == 'help' and args:
-        cmd = args[0] # link to 'dates' for 'hg help dates'
+        if args[0] == 'config':
+            # :hg:`help config`
+            refuri = "hgrc.5.html"
+        elif len(args) >= 2 and args[0] == '-c':
+            # :hg:`help -c COMMAND ...` is equivalent to :hg:`COMMAND`
+            # (mainly for :hg:`help -c config`)
+            refuri = "hg.1.html#%s" % args[1]
+        else:
+            refuri = "hg.1.html#%s" % args[0]
     node = nodes.reference(rawtext, '', linktext,
-                           refuri="hg.1.html#%s" % cmd)
+                           refuri=refuri)
     return [node], []
 
 roles.register_local_role("hg", role_hg)


More information about the Mercurial-devel mailing list