Skip to content

Commit 2fd561a

Browse files
authored
Feature/wikilinks alternative link text (#1)
* Added support for alternative link text for wikilinks extension. * A more clean comparison.
1 parent 5a2fee3 commit 2fd561a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

markdown/extensions/wikilinks.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def extendMarkdown(self, md):
4343
self.md = md
4444

4545
# append to end of inline patterns
46-
WIKILINK_RE = r'\[\[([\w0-9_ -]+)\]\]'
46+
WIKILINK_RE = r'\[\[([\w0-9_ -]+)\|?([^\]]*)\]\]'
4747
wikilinkPattern = WikiLinksInlineProcessor(WIKILINK_RE, self.getConfigs())
4848
wikilinkPattern.md = md
4949
md.inlinePatterns.register(wikilinkPattern, 'wikilink', 75)
@@ -58,9 +58,13 @@ def handleMatch(self, m, data):
5858
if m.group(1).strip():
5959
base_url, end_url, html_class = self._getMeta()
6060
label = m.group(1).strip()
61+
alt_label = m.group(2).strip()
6162
url = self.config['build_url'](label, base_url, end_url)
6263
a = etree.Element('a')
63-
a.text = label
64+
if alt_label:
65+
a.text = alt_label
66+
else:
67+
a.text = label
6468
a.set('href', url)
6569
if html_class:
6670
a.set('class', html_class)

0 commit comments

Comments
 (0)