Skip to content

Commit 7aae61b

Browse files
Add special case for closing nested quotes
Fixes #1514.
1 parent 0ad5b0a commit 7aae61b

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

docs/changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
* Ensure `<center>` is treated like a block-level element (#1481).
2828
* Ensure that `abbr` extension respects `AtomicString` and does not process
2929
perceived abbreviations in these strings (#1512).
30+
* The `smarty` extension correctly renders nested closing quotes (#1514).
3031

3132
## [3.7] -- 2024-08-16
3233

markdown/extensions/smarty.py

+5-1
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

+16
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ 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+
)
59+
self.assertMarkdownRenders(
60+
'<span>He replied, "She said \'Hello.\'"</span>',
61+
'<p><span>He replied, &ldquo;She said &lsquo;Hello.&rsquo;&rdquo;</span></p>'
62+
)
4763
self.assertMarkdownRenders(
4864
'"quoted" text and **bold "quoted" text**',
4965
'<p>&ldquo;quoted&rdquo; text and <strong>bold &ldquo;quoted&rdquo; text</strong></p>'

0 commit comments

Comments
 (0)