Skip to content

Commit

Permalink
Don't auto link patterns surrounded by """.
Browse files Browse the repository at this point in the history
This allows the prevention of `[WikiWikiWeb](http://wiki.c2.com/?WikiWikiWeb)`
being transformed to `<a href="http://wiki.c2.com/?&lt;a href=&quot;aw.cgi?page=WikiWikiWeb&quot;&gt;WikiWikiWeb&lt;/a&gt;">WikiWikiWeb</a>` when
the pattern linker sees the second WikiCase word by surrounding it with triple quotes: so `[WikiWikiWeb](http://wiki.c2.com/?"""WikiWikiWeb""")`
is now transformed to `<a href="http://wiki.c2.com/?WikiWikiWeb">WikiWikiWeb</a>`.

The function responsible, _do_link_patterns(), already checked for the cases that the pattern was inside square brackets, or
was preceeded by `](` or suffixed by `")`, and skips expanding in these cases. This addition simply adds a check that the pattern is not surrounded
by triple quotes; the triple quotes are stripped from the output.
  • Loading branch information
aelzenaar committed Jan 24, 2019
1 parent a3c378d commit 7b259b9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1772,7 +1772,7 @@ def _code_block_sub(self, match, is_fenced_code_block=False):
lexer_name = lexer_name[3:].strip()
codeblock = rest.lstrip("\n") # Remove lexer declaration line.
formatter_opts = self.extras['code-color'] or {}

# Use pygments only if not using the highlightjs-lang extra
if lexer_name and "highlightjs-lang" not in self.extras:
def unhash_code(codeblock):
Expand Down Expand Up @@ -2146,7 +2146,7 @@ def _encode_amps_and_angles(self, text):
def _encode_incomplete_tags(self, text):
if self.safe_mode not in ("replace", "escape"):
return text

return self._incomplete_tags_re.sub("&lt;\\1", text)

def _encode_backslash_escapes(self, text):
Expand Down Expand Up @@ -2218,6 +2218,11 @@ def _do_link_patterns(self, text):
if text[start - 2:start] == '](' or text[end:end + 2] == '")':
continue

# Do not match against links which are escaped.
if text[start - 3:start] == '"""' and text[end:end + 3] == '"""':
text = text[:start - 3] + text[start:end] + text[end + 3:]
continue

escaped_href = (
href.replace('"', '&quot;') # b/c of attr quote
# To avoid markdown <em> and <strong>:
Expand Down

0 comments on commit 7b259b9

Please sign in to comment.