Skip to content

Add special case for closing nested quotes; fixes #1514 #1515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Ensure `<center>` is treated like a block-level element (#1481).
* Ensure that `abbr` extension respects `AtomicString` and does not process
perceived abbreviations in these strings (#1512).
* The `smarty` extension correctly renders nested closing quotes (#1514).

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

Expand Down
6 changes: 5 additions & 1 deletion markdown/extensions/smarty.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@
# <p>He said, "'Quoted' words in a larger quote."</p>
doubleQuoteSetsRe = r""""'(?=\w)"""
singleQuoteSetsRe = r"""'"(?=\w)"""
doubleQuoteSetsRe2 = r'(?<=%s)\'"' % closeClass
singleQuoteSetsRe2 = r"(?<=%s)\"'" % closeClass

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

# Double closing quotes:
closingDoubleQuotesRegex = r'"(?=\s)'
closingDoubleQuotesRegex2 = '(?<=%s)"' % closeClass
closingDoubleQuotesRegex2 = r'(?<=%s)"' % closeClass

# Get most opening single quotes:
openingSingleQuotesRegex = r"%s'(?=\w)" % openingQuotesBase
Expand Down Expand Up @@ -240,6 +242,8 @@ def educateQuotes(self, md: Markdown) -> None:
(doubleQuoteStartRe, (rdquo,)),
(doubleQuoteSetsRe, (ldquo + lsquo,)),
(singleQuoteSetsRe, (lsquo + ldquo,)),
(doubleQuoteSetsRe2, (rsquo + rdquo,)),
(singleQuoteSetsRe2, (rdquo + rsquo,)),
(decadeAbbrRe, (rsquo,)),
(openingSingleQuotesRegex, (1, lsquo)),
(closingSingleQuotesRegex, (rsquo,)),
Expand Down
16 changes: 16 additions & 0 deletions tests/test_syntax/extensions/test_smarty.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ def test_basic(self):
'\'Quoted "words" in a larger quote.\'',
'<p>&lsquo;Quoted &ldquo;words&rdquo; in a larger quote.&rsquo;</p>'
)
self.assertMarkdownRenders(
'"Quoted words at the \'end.\'"',
'<p>&ldquo;Quoted words at the &lsquo;end.&rsquo;&rdquo;</p>'
)
self.assertMarkdownRenders(
'\'Quoted words at the "end."\'',
'<p>&lsquo;Quoted words at the &ldquo;end.&rdquo;&rsquo;</p>'
)
self.assertMarkdownRenders(
'(He replied, "She said \'Hello.\'")',
'<p>(He replied, &ldquo;She said &lsquo;Hello.&rsquo;&rdquo;)</p>'
)
self.assertMarkdownRenders(
'<span>He replied, "She said \'Hello.\'"</span>',
'<p><span>He replied, &ldquo;She said &lsquo;Hello.&rsquo;&rdquo;</span></p>'
)
self.assertMarkdownRenders(
'"quoted" text and **bold "quoted" text**',
'<p>&ldquo;quoted&rdquo; text and <strong>bold &ldquo;quoted&rdquo; text</strong></p>'
Expand Down
Loading