diff --git a/docs/changelog.md b/docs/changelog.md index 29ff8d31..fe5aca58 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Ensure `
` 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 diff --git a/markdown/extensions/smarty.py b/markdown/extensions/smarty.py index d669e69b..c1817e63 100644 --- a/markdown/extensions/smarty.py +++ b/markdown/extensions/smarty.py @@ -134,6 +134,8 @@ #

He said, "'Quoted' words in a larger quote."

doubleQuoteSetsRe = r""""'(?=\w)""" singleQuoteSetsRe = r"""'"(?=\w)""" +doubleQuoteSetsRe2 = r'(?<=%s)\'"' % closeClass +singleQuoteSetsRe2 = r"(?<=%s)\"'" % closeClass # Special case for decade abbreviations (the '80s): decadeAbbrRe = r"(? None: (doubleQuoteStartRe, (rdquo,)), (doubleQuoteSetsRe, (ldquo + lsquo,)), (singleQuoteSetsRe, (lsquo + ldquo,)), + (doubleQuoteSetsRe2, (rsquo + rdquo,)), + (singleQuoteSetsRe2, (rdquo + rsquo,)), (decadeAbbrRe, (rsquo,)), (openingSingleQuotesRegex, (1, lsquo)), (closingSingleQuotesRegex, (rsquo,)), diff --git a/tests/test_syntax/extensions/test_smarty.py b/tests/test_syntax/extensions/test_smarty.py index 0228ddf0..03585517 100644 --- a/tests/test_syntax/extensions/test_smarty.py +++ b/tests/test_syntax/extensions/test_smarty.py @@ -44,6 +44,22 @@ def test_basic(self): '\'Quoted "words" in a larger quote.\'', '

‘Quoted “words” in a larger quote.’

' ) + self.assertMarkdownRenders( + '"Quoted words at the \'end.\'"', + '

“Quoted words at the ‘end.’”

' + ) + self.assertMarkdownRenders( + '\'Quoted words at the "end."\'', + '

‘Quoted words at the “end.”’

' + ) + self.assertMarkdownRenders( + '(He replied, "She said \'Hello.\'")', + '

(He replied, “She said ‘Hello.’”)

' + ) + self.assertMarkdownRenders( + 'He replied, "She said \'Hello.\'"', + '

He replied, “She said ‘Hello.’”

' + ) self.assertMarkdownRenders( '"quoted" text and **bold "quoted" text**', '

“quoted” text and bold “quoted” text

'