Skip to content

Commit ee76bf3

Browse files
committed
Add special case for closing nested quotes; fixes #1514
1 parent 0ad5b0a commit ee76bf3

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

markdown/extensions/smarty.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@
134134
# <p>He said, "'Quoted' words in a larger quote."</p>
135135
doubleQuoteSetsRe = r""""'(?=\w)"""
136136
singleQuoteSetsRe = r"""'"(?=\w)"""
137+
doubleQuoteSetsRe2 = r'(?<=%s)\'"' % closeClass
138+
singleQuoteSetsRe2 = r"(?<=%s)\"'" % closeClass
137139

138140
# Special case for decade abbreviations (the '80s):
139141
decadeAbbrRe = r"(?<!\w)'(?=\d{2}s)"
@@ -143,7 +145,7 @@
143145

144146
# Double closing quotes:
145147
closingDoubleQuotesRegex = r'"(?=\s)'
146-
closingDoubleQuotesRegex2 = '(?<=%s)"' % closeClass
148+
closingDoubleQuotesRegex2 = r'(?<=%s)"' % closeClass
147149

148150
# Get most opening single quotes:
149151
openingSingleQuotesRegex = r"%s'(?=\w)" % openingQuotesBase
@@ -240,6 +242,8 @@ def educateQuotes(self, md: Markdown) -> None:
240242
(doubleQuoteStartRe, (rdquo,)),
241243
(doubleQuoteSetsRe, (ldquo + lsquo,)),
242244
(singleQuoteSetsRe, (lsquo + ldquo,)),
245+
(doubleQuoteSetsRe2, (rsquo + rdquo,)),
246+
(singleQuoteSetsRe2, (rdquo + rsquo,)),
243247
(decadeAbbrRe, (rsquo,)),
244248
(openingSingleQuotesRegex, (1, lsquo)),
245249
(closingSingleQuotesRegex, (rsquo,)),

tests/test_syntax/extensions/test_smarty.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ def test_basic(self):
4444
'\'Quoted "words" in a larger quote.\'',
4545
'<p>&lsquo;Quoted &ldquo;words&rdquo; in a larger quote.&rsquo;</p>'
4646
)
47+
self.assertMarkdownRenders(
48+
'"Quoted words at the \'end.\'"',
49+
'<p>&ldquo;Quoted words at the &lsquo;end.&rsquo;&rdquo;</p>'
50+
)
51+
self.assertMarkdownRenders(
52+
'\'Quoted words at the "end."\'',
53+
'<p>&lsquo;Quoted words at the &ldquo;end.&rdquo;&rsquo;</p>'
54+
)
55+
self.assertMarkdownRenders(
56+
'(He replied, "She said \'Hello.\'")',
57+
'<p>(He replied, &ldquo;She said &lsquo;Hello.&rsquo;&rdquo;)</p>'
58+
)
4759
self.assertMarkdownRenders(
4860
'"quoted" text and **bold "quoted" text**',
4961
'<p>&ldquo;quoted&rdquo; text and <strong>bold &ldquo;quoted&rdquo; text</strong></p>'

0 commit comments

Comments
 (0)