Skip to content

Commit 904d4e6

Browse files
committed
Merge pull request #419 from mitya57/master
Use a different approach to fix the smarty bug
2 parents f3a8cb9 + 644e32c commit 904d4e6

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

markdown/extensions/smarty.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383

8484
from __future__ import unicode_literals
8585
from . import Extension
86-
from ..inlinepatterns import HtmlPattern
86+
from ..inlinepatterns import HtmlPattern, HTML_RE
8787
from ..odict import OrderedDict
8888
from ..treeprocessors import InlineProcessor
8989

@@ -147,6 +147,8 @@
147147
remainingSingleQuotesRegex = "'"
148148
remainingDoubleQuotesRegex = '"'
149149

150+
HTML_STRICT_RE = HTML_RE + r'(?!\>)'
151+
150152

151153
class SubstituteTextPattern(HtmlPattern):
152154
def __init__(self, pattern, replace, markdown_instance):
@@ -211,10 +213,10 @@ def educateAngledQuotes(self, md):
211213
rightAngledQuotePattern = SubstituteTextPattern(
212214
r'\>\>', (self.substitutions['right-angle-quote'],), md
213215
)
214-
self.angledQuotesPatterns.add(
216+
self.inlinePatterns.add(
215217
'smarty-left-angle-quotes', leftAngledQuotePattern, '_begin'
216218
)
217-
self.angledQuotesPatterns.add(
219+
self.inlinePatterns.add(
218220
'smarty-right-angle-quotes',
219221
rightAngledQuotePattern,
220222
'>smarty-left-angle-quotes'
@@ -249,18 +251,17 @@ def extendMarkdown(self, md, md_globals):
249251
self.educateEllipses(md)
250252
if configs['smart_quotes']:
251253
self.educateQuotes(md)
254+
if configs['smart_angled_quotes']:
255+
self.educateAngledQuotes(md)
256+
# Override HTML_RE from inlinepatterns.py so that it does not
257+
# process tags with duplicate closing quotes.
258+
md.inlinePatterns["html"] = HtmlPattern(HTML_STRICT_RE, md)
252259
if configs['smart_dashes']:
253260
self.educateDashes(md)
254261
inlineProcessor = InlineProcessor(md)
255262
inlineProcessor.inlinePatterns = self.inlinePatterns
256263
md.treeprocessors.add('smarty', inlineProcessor, '_end')
257264
md.ESCAPED_CHARS.extend(['"', "'"])
258-
if configs['smart_angled_quotes']:
259-
self.angledQuotesPatterns = OrderedDict()
260-
self.educateAngledQuotes(md)
261-
angledQuotesProcessor = InlineProcessor(md)
262-
angledQuotesProcessor.inlinePatterns = self.angledQuotesPatterns
263-
md.treeprocessors.add('smarty-angledquotes', angledQuotesProcessor, '<inline')
264265

265266

266267
def makeExtension(*args, **kwargs):

tests/basic/inline-html-simple.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@
5757

5858
<hr class="foo" id="bar" >
5959

60-
<p><some <a href="http://example.com">weird</a> stuff></p>
60+
<p><some <a href="http://example.com">weird</a> stuff></p>
61+
<p><some>&gt; &lt;<unbalanced>&gt; &lt;<brackets></p>

tests/basic/inline-html-simple.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@ Hr's:
6868
<hr class="foo" id="bar" >
6969

7070
<some [weird](http://example.com) stuff>
71+
72+
<some>> <<unbalanced>> <<brackets>

tests/extensions/smarty.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
Escaped ellipsis...</p>
2525
<p>&lsquo;Escaped "quotes" in real ones&rsquo;<br />
2626
'&ldquo;Real&rdquo; quotes in escaped ones'</p>
27-
<p>Skip <code>"code" -- --- 'spans' ...</code>.</p>
27+
<p>Skip <code>&lt;&lt;all&gt;&gt; "code" -- --- 'spans' ...</code>.</p>
2828
<pre><code>Also skip "code" 'blocks'
2929
foo -- bar --- baz ...
3030
</code></pre>

tests/extensions/smarty.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Escaped ellipsis\...
3131
'Escaped \"quotes\" in real ones'
3232
\'"Real" quotes in escaped ones\'
3333

34-
Skip `"code" -- --- 'spans' ...`.
34+
Skip `<<all>> "code" -- --- 'spans' ...`.
3535

3636
Also skip "code" 'blocks'
3737
foo -- bar --- baz ...

0 commit comments

Comments
 (0)