Skip to content

Commit dba8025

Browse files
mitya57waylan
authored andcommitted
smarty: Add a special case for 's at the beginning of the token
When 's is not preceded by anything, it probably means that it comes after some HTML tag, so it should be converted to a closing quote. The reference Perl implementation makes the close_class optional and adds a lookahead check for (\s|s\b) when close_class was not matched. Let's copy that behavior by removing closeClass lookbehind check from closingSingleQuotesRegex2. Fixes #1305.
1 parent 965c06c commit dba8025

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

docs/change_log/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ title: Change Log
33
Python-Markdown Change Log
44
=========================
55

6+
*under development*: version 3.4.4 (a bug-fix release).
7+
8+
* Add a special case for initial 's to smarty extension (#1305).
9+
610
March 23, 2023: version 3.4.3 (a bug-fix release).
711

812
* Restore console script (#1327).

markdown/extensions/smarty.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139

140140
# Single closing quotes:
141141
closingSingleQuotesRegex = r"(?<=%s)'(?!\s|s\b|\d)" % closeClass
142-
closingSingleQuotesRegex2 = r"(?<=%s)'(\s|s\b)" % closeClass
142+
closingSingleQuotesRegex2 = r"'(\s|s\b)"
143143

144144
# All remaining quotes should be opening ones
145145
remainingSingleQuotesRegex = r"'"

tests/test_syntax/extensions/test_smarty.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ def test_basic(self):
6464
'"Ellipsis within quotes..."',
6565
'<p>&ldquo;Ellipsis within quotes&hellip;&rdquo;</p>'
6666
)
67+
self.assertMarkdownRenders(
68+
"*Custer*'s Last Stand",
69+
"<p><em>Custer</em>&rsquo;s Last Stand</p>"
70+
)
6771

6872
def test_years(self):
6973
self.assertMarkdownRenders("1440--80's", '<p>1440&ndash;80&rsquo;s</p>')

0 commit comments

Comments
 (0)