Smarten punctuation: Fix seld closing script tags causing smarten punctuation to fail

This commit is contained in:
Kovid Goyal 2012-11-23 08:24:51 +05:30
parent 8f979f5877
commit b1c8a33c1e

View File

@ -378,6 +378,7 @@ import re
# style added by Kovid
tags_to_skip_regex = re.compile(r"<(/)?(style|pre|code|kbd|script|math)[^>]*>", re.I)
self_closing_regex = re.compile(r'/\s*>$')
def verify_installation(request):
@ -497,6 +498,8 @@ def smartyPants(text, attr=default_smartypants_attr):
result.append(cur_token[1])
skip_match = tags_to_skip_regex.match(cur_token[1])
if skip_match is not None:
is_self_closing = self_closing_regex.search(skip_match.group()) is not None
if not is_self_closing:
if not skip_match.group(1):
skipped_tag_stack.append(skip_match.group(2).lower())
in_pre = True
@ -907,6 +910,10 @@ if __name__ == "__main__":
sp("""<p>He said &quot;Let's write some code.&quot; This code here <code>if True:\n\tprint &quot;Okay&quot;</code> is python code.</p>"""),
"""<p>He said &#8220;Let&#8217;s write some code.&#8221; This code here <code>if True:\n\tprint &quot;Okay&quot;</code> is python code.</p>""")
self.assertEqual(
sp('''<script/><p>It's ok</p>'''),
'''<script/><p>It&#8217;s ok</p>''')
def test_ordinal_numbers(self):
self.assertEqual(sp("21st century"), "21st century") # no effect.