aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Shachnev <mitya57@gmail.com>2013-07-27 16:21:00 +0400
committerDmitry Shachnev <mitya57@gmail.com>2013-07-27 16:21:00 +0400
commit85ad18071d61925168387934e4e6f9f82462c292 (patch)
tree891a890d8de8452298bb18a8e4703c1940567947
parentc00f686313d656fb87842cf69541f09dce520dfa (diff)
downloadmarkdown-85ad18071d61925168387934e4e6f9f82462c292.tar.gz
markdown-85ad18071d61925168387934e4e6f9f82462c292.tar.bz2
markdown-85ad18071d61925168387934e4e6f9f82462c292.zip
Some fixes requested by @waylan, cleanup and tests improvements
-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 = '&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