From 85ad18071d61925168387934e4e6f9f82462c292 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Sat, 27 Jul 2013 16:21:00 +0400 Subject: Some fixes requested by @waylan, cleanup and tests improvements --- markdown/extensions/smarty.py | 20 +++++++++----------- tests/extensions/smarty.html | 6 +++++- tests/extensions/smarty.txt | 7 ++++++- 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'(?entity') md.inlinePatterns.add('smarty-en-dashes', enDashesPattern, '>smarty-em-dashes') def educateEllipses(self, md): - ellipsesPattern = SubstituteTextPattern(r'(?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 ‘60s
‘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 (…)
Link” — she said.


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 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 -- cgit v1.2.3