diff options
author | Waylan Limberg <waylan.limberg@icloud.com> | 2015-06-20 17:39:06 -0400 |
---|---|---|
committer | Waylan Limberg <waylan.limberg@icloud.com> | 2015-06-20 17:39:06 -0400 |
commit | 904d4e6d9c8910c3feca52c82382486d51505a3b (patch) | |
tree | c5a488e7e58ce7461a39a8837b576942257a7f27 | |
parent | f3a8cb947eaf7318990f3d27e963bdd2787b4196 (diff) | |
parent | 644e32c2b130f29cb16e154b1e0c281575c10427 (diff) | |
download | markdown-904d4e6d9c8910c3feca52c82382486d51505a3b.tar.gz markdown-904d4e6d9c8910c3feca52c82382486d51505a3b.tar.bz2 markdown-904d4e6d9c8910c3feca52c82382486d51505a3b.zip |
Merge pull request #419 from mitya57/master
Use a different approach to fix the smarty bug
-rw-r--r-- | markdown/extensions/smarty.py | 19 | ||||
-rw-r--r-- | tests/basic/inline-html-simple.html | 3 | ||||
-rw-r--r-- | tests/basic/inline-html-simple.txt | 2 | ||||
-rw-r--r-- | tests/extensions/smarty.html | 2 | ||||
-rw-r--r-- | tests/extensions/smarty.txt | 2 |
5 files changed, 16 insertions, 12 deletions
diff --git a/markdown/extensions/smarty.py b/markdown/extensions/smarty.py index 223f2ad..600d74c 100644 --- a/markdown/extensions/smarty.py +++ b/markdown/extensions/smarty.py @@ -83,7 +83,7 @@ smartypants.py license: from __future__ import unicode_literals from . import Extension -from ..inlinepatterns import HtmlPattern +from ..inlinepatterns import HtmlPattern, HTML_RE from ..odict import OrderedDict from ..treeprocessors import InlineProcessor @@ -147,6 +147,8 @@ closingSingleQuotesRegex2 = r"(?<=%s)'(\s|s\b)" % closeClass remainingSingleQuotesRegex = "'" remainingDoubleQuotesRegex = '"' +HTML_STRICT_RE = HTML_RE + r'(?!\>)' + class SubstituteTextPattern(HtmlPattern): def __init__(self, pattern, replace, markdown_instance): @@ -211,10 +213,10 @@ class SmartyExtension(Extension): rightAngledQuotePattern = SubstituteTextPattern( r'\>\>', (self.substitutions['right-angle-quote'],), md ) - self.angledQuotesPatterns.add( + self.inlinePatterns.add( 'smarty-left-angle-quotes', leftAngledQuotePattern, '_begin' ) - self.angledQuotesPatterns.add( + self.inlinePatterns.add( 'smarty-right-angle-quotes', rightAngledQuotePattern, '>smarty-left-angle-quotes' @@ -249,18 +251,17 @@ class SmartyExtension(Extension): self.educateEllipses(md) if configs['smart_quotes']: self.educateQuotes(md) + if configs['smart_angled_quotes']: + self.educateAngledQuotes(md) + # Override HTML_RE from inlinepatterns.py so that it does not + # process tags with duplicate closing quotes. + md.inlinePatterns["html"] = HtmlPattern(HTML_STRICT_RE, md) if configs['smart_dashes']: self.educateDashes(md) inlineProcessor = InlineProcessor(md) inlineProcessor.inlinePatterns = self.inlinePatterns md.treeprocessors.add('smarty', inlineProcessor, '_end') md.ESCAPED_CHARS.extend(['"', "'"]) - if configs['smart_angled_quotes']: - self.angledQuotesPatterns = OrderedDict() - self.educateAngledQuotes(md) - angledQuotesProcessor = InlineProcessor(md) - angledQuotesProcessor.inlinePatterns = self.angledQuotesPatterns - md.treeprocessors.add('smarty-angledquotes', angledQuotesProcessor, '<inline') def makeExtension(*args, **kwargs): diff --git a/tests/basic/inline-html-simple.html b/tests/basic/inline-html-simple.html index 2159e1d..0f2633c 100644 --- a/tests/basic/inline-html-simple.html +++ b/tests/basic/inline-html-simple.html @@ -57,4 +57,5 @@ Blah <hr class="foo" id="bar" > -<p><some <a href="http://example.com">weird</a> stuff></p>
\ No newline at end of file +<p><some <a href="http://example.com">weird</a> stuff></p> +<p><some>> <<unbalanced>> <<brackets></p>
\ No newline at end of file diff --git a/tests/basic/inline-html-simple.txt b/tests/basic/inline-html-simple.txt index 7210750..359aca4 100644 --- a/tests/basic/inline-html-simple.txt +++ b/tests/basic/inline-html-simple.txt @@ -68,3 +68,5 @@ Hr's: <hr class="foo" id="bar" > <some [weird](http://example.com) stuff> + +<some>> <<unbalanced>> <<brackets>
\ No newline at end of file diff --git a/tests/extensions/smarty.html b/tests/extensions/smarty.html index a4ec1a0..50cf774 100644 --- a/tests/extensions/smarty.html +++ b/tests/extensions/smarty.html @@ -24,7 +24,7 @@ Anführungszeichen-»Chevrons«</p> Escaped ellipsis...</p> <p>‘Escaped "quotes" in real ones’<br /> '“Real” quotes in escaped ones'</p> -<p>Skip <code>"code" -- --- 'spans' ...</code>.</p> +<p>Skip <code><<all>> "code" -- --- 'spans' ...</code>.</p> <pre><code>Also skip "code" 'blocks' foo -- bar --- baz ... </code></pre>
\ No newline at end of file diff --git a/tests/extensions/smarty.txt b/tests/extensions/smarty.txt index d7cba6a..f2f4041 100644 --- a/tests/extensions/smarty.txt +++ b/tests/extensions/smarty.txt @@ -31,7 +31,7 @@ Escaped ellipsis\... 'Escaped \"quotes\" in real ones' \'"Real" quotes in escaped ones\' -Skip `"code" -- --- 'spans' ...`. +Skip `<<all>> "code" -- --- 'spans' ...`. Also skip "code" 'blocks' foo -- bar --- baz ... |