From ee76bf31009f6f3b01b441e9cf1004bd26d93417 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Tue, 18 Mar 2025 21:40:56 -0400 Subject: [PATCH 1/3] Add special case for closing nested quotes; fixes #1514 --- markdown/extensions/smarty.py | 6 +++++- tests/test_syntax/extensions/test_smarty.py | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/markdown/extensions/smarty.py b/markdown/extensions/smarty.py index d669e69b0..c1817e634 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 0228ddf02..319f6cb92 100644 --- a/tests/test_syntax/extensions/test_smarty.py +++ b/tests/test_syntax/extensions/test_smarty.py @@ -44,6 +44,18 @@ 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( '"quoted" text and **bold "quoted" text**', '

“quoted” text and bold “quoted” text

' From af6b31a96dd373396f0c8017087a84e2a32f3b34 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Wed, 19 Mar 2025 17:05:38 -0400 Subject: [PATCH 2/3] Add smarty fix to changelog --- docs/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.md b/docs/changelog.md index 29ff8d313..fe5aca58e 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 From a22e74258d9206011a0a51b09a11b913fc8d71c5 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Wed, 19 Mar 2025 17:50:40 -0400 Subject: [PATCH 3/3] Add smarty test for nested quotes in span element --- tests/test_syntax/extensions/test_smarty.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_syntax/extensions/test_smarty.py b/tests/test_syntax/extensions/test_smarty.py index 319f6cb92..035855170 100644 --- a/tests/test_syntax/extensions/test_smarty.py +++ b/tests/test_syntax/extensions/test_smarty.py @@ -56,6 +56,10 @@ def test_basic(self): '(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

'