diff --git a/lib/markdown2.py b/lib/markdown2.py index c572f99f..9e81931b 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -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): @@ -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("<\\1", text) def _encode_backslash_escapes(self, text): @@ -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('"', '"') # b/c of attr quote # To avoid markdown and : diff --git a/test/tm-cases/link_patterns_escape.html b/test/tm-cases/link_patterns_escape.html new file mode 100644 index 00000000..20c42eb4 --- /dev/null +++ b/test/tm-cases/link_patterns_escape.html @@ -0,0 +1,9 @@ +

Recipe 123 and a link to Komodo bug 234 are related.

+ +

This is a link which has a pattern inside the url that shouldn't expand.

+ +

Matched pattern is escaped: PEP 42 might be related too.

+ +

Triple quotes not surrounding a matched pattern: PEP """42""" might be related too.

+ +

"""This is some random text which should not be touched."""

diff --git a/test/tm-cases/link_patterns_escape.opts b/test/tm-cases/link_patterns_escape.opts new file mode 100644 index 00000000..440d5a6d --- /dev/null +++ b/test/tm-cases/link_patterns_escape.opts @@ -0,0 +1,8 @@ +{"extras": ["link-patterns"], + "link_patterns": [ + (re.compile("recipe\s+(\d+)", re.I), r"http://code.activestate.com/recipes/\1/"), + (re.compile("(?:komodo\s+)?bug\s+(\d+)", re.I), r"http://bugs.activestate.com/show_bug.cgi?id=\1"), + (re.compile("PEP\s+(\d+)", re.I), lambda m: "http://www.python.org/dev/peps/pep-%04d/" % int(m.group(1))), + ], +} + diff --git a/test/tm-cases/link_patterns_escape.text b/test/tm-cases/link_patterns_escape.text new file mode 100644 index 00000000..e4cf48af --- /dev/null +++ b/test/tm-cases/link_patterns_escape.text @@ -0,0 +1,9 @@ +"""Recipe 123""" and a link to """Komodo bug 234""" are related. + +This is a link which has a pattern inside the url that shouldn't expand. + +Matched pattern is escaped: """PEP 42""" might be related too. + +Triple quotes not surrounding a matched pattern: PEP """42""" might be related too. + +"""This is some random text which should not be touched."""