mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Smarten punctuation: Fix seld closing script tags causing smarten punctuation to fail
This commit is contained in:
parent
8f979f5877
commit
b1c8a33c1e
@ -378,6 +378,7 @@ import re
|
|||||||
|
|
||||||
# style added by Kovid
|
# style added by Kovid
|
||||||
tags_to_skip_regex = re.compile(r"<(/)?(style|pre|code|kbd|script|math)[^>]*>", re.I)
|
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):
|
def verify_installation(request):
|
||||||
@ -497,6 +498,8 @@ def smartyPants(text, attr=default_smartypants_attr):
|
|||||||
result.append(cur_token[1])
|
result.append(cur_token[1])
|
||||||
skip_match = tags_to_skip_regex.match(cur_token[1])
|
skip_match = tags_to_skip_regex.match(cur_token[1])
|
||||||
if skip_match is not None:
|
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):
|
if not skip_match.group(1):
|
||||||
skipped_tag_stack.append(skip_match.group(2).lower())
|
skipped_tag_stack.append(skip_match.group(2).lower())
|
||||||
in_pre = True
|
in_pre = True
|
||||||
@ -907,6 +910,10 @@ if __name__ == "__main__":
|
|||||||
sp("""<p>He said "Let's write some code." This code here <code>if True:\n\tprint "Okay"</code> is python code.</p>"""),
|
sp("""<p>He said "Let's write some code." This code here <code>if True:\n\tprint "Okay"</code> is python code.</p>"""),
|
||||||
"""<p>He said “Let’s write some code.” This code here <code>if True:\n\tprint "Okay"</code> is python code.</p>""")
|
"""<p>He said “Let’s write some code.” This code here <code>if True:\n\tprint "Okay"</code> is python code.</p>""")
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
sp('''<script/><p>It's ok</p>'''),
|
||||||
|
'''<script/><p>It’s ok</p>''')
|
||||||
|
|
||||||
|
|
||||||
def test_ordinal_numbers(self):
|
def test_ordinal_numbers(self):
|
||||||
self.assertEqual(sp("21st century"), "21st century") # no effect.
|
self.assertEqual(sp("21st century"), "21st century") # no effect.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user