ref: 779d73e4fdfa3ddc5b77d1ef0e04aa92b5f89e88
parent: 74e0e0c740f58d3e0e1643dca7d3dfe9d895c41b
author: Simon Howard <fraggle@soulsphere.org>
date: Sun May 27 16:36:09 EDT 2018
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).
--- a/man/docgen
+++ b/man/docgen
@@ -320,10 +320,16 @@
# 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