From 621cac4163420dc1c5b18d4bc97254a4378d53f5 Mon Sep 17 00:00:00 2001
From: Dmitry Shachnev
Date: Fri, 19 Jun 2015 14:54:09 +0300
Subject: [PATCH 1/4] Revert "smarty: Use a separate processor for angled
quotes"
That commit caused a regression where `<<` and `>>` inside code
blocks were wrongly replaced with double quotes.
This reverts commit 5029d829c1532f31adc9acbf54d88bb469a69a4f.
---
markdown/extensions/smarty.py | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/markdown/extensions/smarty.py b/markdown/extensions/smarty.py
index 223f2adc4..46e54c1ec 100644
--- a/markdown/extensions/smarty.py
+++ b/markdown/extensions/smarty.py
@@ -211,10 +211,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'
@@ -249,18 +249,14 @@ def extendMarkdown(self, md, md_globals):
self.educateEllipses(md)
if configs['smart_quotes']:
self.educateQuotes(md)
+ if configs['smart_angled_quotes']:
+ self.educateAngledQuotes(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, '
Date: Fri, 19 Jun 2015 15:19:20 +0300
Subject: [PATCH 2/4] Add a test to make sure quotes processor does not touch
code blocks
---
tests/extensions/smarty.html | 2 +-
tests/extensions/smarty.txt | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/extensions/smarty.html b/tests/extensions/smarty.html
index a4ec1a05f..50cf77440 100644
--- a/tests/extensions/smarty.html
+++ b/tests/extensions/smarty.html
@@ -24,7 +24,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 ...
\ No newline at end of file
diff --git a/tests/extensions/smarty.txt b/tests/extensions/smarty.txt
index d7cba6a61..f2f4041b5 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 `<> "code" -- --- 'spans' ...`.
Also skip "code" 'blocks'
foo -- bar --- baz ...
From 93d79416d155857202c9ef156ae467d4f1fea037 Mon Sep 17 00:00:00 2001
From: Dmitry Shachnev
Date: Sat, 20 Jun 2015 15:41:05 +0300
Subject: [PATCH 3/4] Override regex for html inline pattern when
smart_angled_quotes is true
Add a restriction that the closing angled quote should not be duplicate,
so that we can use our own pattern for handling duplicate quotes.
---
markdown/extensions/smarty.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/markdown/extensions/smarty.py b/markdown/extensions/smarty.py
index 46e54c1ec..600d74cd6 100644
--- a/markdown/extensions/smarty.py
+++ b/markdown/extensions/smarty.py
@@ -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
@@ -147,6 +147,8 @@
remainingSingleQuotesRegex = "'"
remainingDoubleQuotesRegex = '"'
+HTML_STRICT_RE = HTML_RE + r'(?!\>)'
+
class SubstituteTextPattern(HtmlPattern):
def __init__(self, pattern, replace, markdown_instance):
@@ -251,6 +253,9 @@ def extendMarkdown(self, md, md_globals):
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)
From 644e32c2b130f29cb16e154b1e0c281575c10427 Mon Sep 17 00:00:00 2001
From: Dmitry Shachnev
Date: Sat, 20 Jun 2015 15:45:30 +0300
Subject: [PATCH 4/4] Add a test for duplicate angled quotes without smarty
extension
---
tests/basic/inline-html-simple.html | 3 ++-
tests/basic/inline-html-simple.txt | 2 ++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/tests/basic/inline-html-simple.html b/tests/basic/inline-html-simple.html
index 2159e1dcb..0f2633cfe 100644
--- a/tests/basic/inline-html-simple.html
+++ b/tests/basic/inline-html-simple.html
@@ -57,4 +57,5 @@
-weird stuff>
\ No newline at end of file
+weird stuff>
+> <> <
\ No newline at end of file
diff --git a/tests/basic/inline-html-simple.txt b/tests/basic/inline-html-simple.txt
index 7210750d8..359aca4e5 100644
--- a/tests/basic/inline-html-simple.txt
+++ b/tests/basic/inline-html-simple.txt
@@ -68,3 +68,5 @@ Hr's:
+
+> <> <
\ No newline at end of file