foxygit / doom Log in
commit 779d73e4fdfa3ddc5b77d1ef0e04aa92b5f89e88
Author:     Simon Howard <fraggle@soulsphere.org>
AuthorDate: Sun May 27 20:36:09 2018 -0400
Commit:     Simon Howard <fraggle@soulsphere.org>
CommitDate: Sun May 27 20:36:09 2018 -0400

    docgen: Fix links when capitalization doesn't match.

    This fixes a couple of broken links on the wiki page when capitalization
    doesn't match page name (since capitalization is significant in Mediawiki).
---
 man/docgen | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/man/docgen b/man/docgen
index 4c203f0a..5114f78c 100755
--- a/man/docgen
+++ b/man/docgen
@@ -320,10 +320,16 @@ def read_wikipages():
 # Add wiki page links

 def add_wiki_links(text):
+    def replace_name(m):
+        linktext = m.group(1)
+        if linktext == pagename:
+            return '[[%s]]' % pagename
+        else:
+            return '[[%s|%s]]' % (pagename, linktext)
+
     for pagename in wikipages:
-        page_re = re.compile('(%s)' % pagename, re.IGNORECASE)
-    #   text = page_re.sub("SHOES", text)
-        text = page_re.sub('[[\\1]]', text)
+        text = re.sub(r'\b(%s)\b' % re.escape(pagename), replace_name,
+                      text, count=0, flags=re.IGNORECASE)

     return text