Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions markdown/extensions/smarty.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

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

Expand Down Expand Up @@ -147,6 +147,8 @@
remainingSingleQuotesRegex = "'"
remainingDoubleQuotesRegex = '"'

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


class SubstituteTextPattern(HtmlPattern):
def __init__(self, pattern, replace, markdown_instance):
Expand Down Expand Up @@ -211,10 +213,10 @@ def educateAngledQuotes(self, md):
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'
Expand Down Expand Up @@ -249,18 +251,17 @@ def extendMarkdown(self, md, md_globals):
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):
Expand Down
3 changes: 2 additions & 1 deletion tests/basic/inline-html-simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@

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

<p><some <a href="http://example.com">weird</a> stuff></p>
<p><some <a href="http://example.com">weird</a> stuff></p>
<p><some>&gt; &lt;<unbalanced>&gt; &lt;<brackets></p>
2 changes: 2 additions & 0 deletions tests/basic/inline-html-simple.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ Hr's:
<hr class="foo" id="bar" >

<some [weird](http://example.com) stuff>

<some>> <<unbalanced>> <<brackets>
2 changes: 1 addition & 1 deletion tests/extensions/smarty.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Escaped ellipsis...</p>
<p>&lsquo;Escaped "quotes" in real ones&rsquo;<br />
'&ldquo;Real&rdquo; quotes in escaped ones'</p>
<p>Skip <code>"code" -- --- 'spans' ...</code>.</p>
<p>Skip <code>&lt;&lt;all&gt;&gt; "code" -- --- 'spans' ...</code>.</p>
<pre><code>Also skip "code" 'blocks'
foo -- bar --- baz ...
</code></pre>
2 changes: 1 addition & 1 deletion tests/extensions/smarty.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...