aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--markdown/extensions/smarty.py20
-rw-r--r--tests/extensions/smarty.html6
-rw-r--r--tests/extensions/smarty.txt7
3 files changed, 20 insertions, 13 deletions
diff --git a/markdown/extensions/smarty.py b/markdown/extensions/smarty.py
index 90d0c41..18f9217 100644
--- a/markdown/extensions/smarty.py
+++ b/markdown/extensions/smarty.py
@@ -106,9 +106,6 @@ doubleQuoteStartRe = r'^"(?=%s\\B)' % punctClass
doubleQuoteSetsRe = r""""'(?=\w)"""
singleQuoteSetsRe = r"""'"(?=\w)"""
-# Special case for decade abbreviations (the '80s):
-decadeAbbrRe = r"""\b'(?=\d{2}s)"""
-
# Get most opening double quotes:
openingDoubleQuotesRegex = canonicalize("""
%s # symbols before the quote
@@ -150,9 +147,7 @@ closingSingleQuotesRegex2 = canonicalize(r"""
remainingSingleQuotesRegex = "'"
remainingDoubleQuotesRegex = '"'
-for name in ('mdash', 'ndash', 'hellip', 'lsquo', 'rsquo', 'ldquo', 'rdquo'):
- locals()[name] = '&%s;' % name
-
+lsquo, rsquo, ldquo, rdquo = '‘', '’', '“', '”'
class SubstituteTextPattern(HtmlPattern):
def __init__(self, pattern, replace, markdown_instance):
@@ -178,9 +173,11 @@ class SmartyExtension(Extension):
'smart_ellipses': [True, 'Educate ellipses']
}
for key, value in configs:
- if value.lower() in ('true', 1):
+ if not isinstance(value, str):
+ value = bool(value)
+ elif value.lower() in ('true', 't', 'yes', 'y', '1'):
value = True
- elif value.lower() in ('false', 0):
+ elif value.lower() in ('false', 'f', 'no', 'n', '0'):
value = False
else:
raise ValueError('Cannot parse bool value: %s' % value)
@@ -195,14 +192,14 @@ class SmartyExtension(Extension):
md.inlinePatterns.add(name, pattern, after)
def educateDashes(self, md):
- emDashesPattern = SubstituteTextPattern(r'(?<!-)---(?!-)', mdash, md)
- enDashesPattern = SubstituteTextPattern(r'(?<!-)--(?!-)', ndash, md)
+ emDashesPattern = SubstituteTextPattern(r'(?<!-)---(?!-)', '&mdash;', md)
+ enDashesPattern = SubstituteTextPattern(r'(?<!-)--(?!-)', '&ndash;', md)
md.inlinePatterns.add('smarty-em-dashes', emDashesPattern, '>entity')
md.inlinePatterns.add('smarty-en-dashes', enDashesPattern,
'>smarty-em-dashes')
def educateEllipses(self, md):
- ellipsesPattern = SubstituteTextPattern(r'(?<!\.)\.{3}(?!\.)', hellip, md)
+ ellipsesPattern = SubstituteTextPattern(r'(?<!\.)\.{3}(?!\.)', '&hellip;', md)
md.inlinePatterns.add('smarty-ellipses', ellipsesPattern, '>entity')
def educateQuotes(self, md):
@@ -230,6 +227,7 @@ class SmartyExtension(Extension):
self.educateDashes(md)
if configs['smart_ellipses']:
self.educateEllipses(md)
+ md.ESCAPED_CHARS.extend(['"', "'"])
def makeExtension(configs=None):
return SmartyExtension(configs)
diff --git a/tests/extensions/smarty.html b/tests/extensions/smarty.html
index 2485ab7..fbd15af 100644
--- a/tests/extensions/smarty.html
+++ b/tests/extensions/smarty.html
@@ -7,10 +7,14 @@ one two &lsquo;60s<br />
&lsquo;60s</p>
<p>&ldquo;Isn&rsquo;t this fun&rdquo;? &mdash; she said&hellip;<br />
&ldquo;&lsquo;Quoted&rsquo; words in a larger quote.&rdquo;<br />
+&lsquo;Quoted &ldquo;words&rdquo; in a larger quote.&rsquo;<br />
&ldquo;quoted&rdquo; text and <strong>bold &ldquo;quoted&rdquo; text</strong><br />
&lsquo;quoted&rsquo; text and <strong>bold &lsquo;quoted&rsquo; text</strong><br />
em-dashes (&mdash;) and ellipes (&hellip;)<br />
&ldquo;<a href="http://example.com">Link</a>&rdquo; &mdash; she said.</p>
<hr />
<p>Escaped -- ndash<br />
-Escaped ellipsis...</p> \ No newline at end of file
+'Escaped' "quotes"<br />
+Escaped ellipsis...</p>
+<p>&lsquo;Escaped "quotes" in real ones&rsquo;<br />
+'&ldquo;Real&rdquo; quotes in escaped ones'</p> \ No newline at end of file
diff --git a/tests/extensions/smarty.txt b/tests/extensions/smarty.txt
index 4015f71..5b5ece7 100644
--- a/tests/extensions/smarty.txt
+++ b/tests/extensions/smarty.txt
@@ -8,6 +8,7 @@ one two '60s
"Isn't this fun"? --- she said...
"'Quoted' words in a larger quote."
+'Quoted "words" in a larger quote.'
"quoted" text and **bold "quoted" text**
'quoted' text and **bold 'quoted' text**
em-dashes (---) and ellipes (...)
@@ -16,4 +17,8 @@ em-dashes (---) and ellipes (...)
--- -- ---
Escaped \-- ndash
-Escaped ellipsis\... \ No newline at end of file
+\'Escaped\' \"quotes\"
+Escaped ellipsis\...
+
+'Escaped \"quotes\" in real ones'
+\'"Real" quotes in escaped ones\' \ No newline at end of file