Skip to content

Commit

Permalink
smarty: Add a special case for 's at the beginning of the token
Browse files Browse the repository at this point in the history
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 Python-Markdown#1305.
  • Loading branch information
mitya57 authored and waylan committed May 22, 2023
1 parent 965c06c commit dba8025
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/change_log/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ title: Change Log
Python-Markdown Change Log
=========================

*under development*: version 3.4.4 (a bug-fix release).

* Add a special case for initial 's to smarty extension (#1305).

March 23, 2023: version 3.4.3 (a bug-fix release).

* Restore console script (#1327).
Expand Down
2 changes: 1 addition & 1 deletion markdown/extensions/smarty.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@

# Single closing quotes:
closingSingleQuotesRegex = r"(?<=%s)'(?!\s|s\b|\d)" % closeClass
closingSingleQuotesRegex2 = r"(?<=%s)'(\s|s\b)" % closeClass
closingSingleQuotesRegex2 = r"'(\s|s\b)"

# All remaining quotes should be opening ones
remainingSingleQuotesRegex = r"'"
Expand Down
4 changes: 4 additions & 0 deletions tests/test_syntax/extensions/test_smarty.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def test_basic(self):
'"Ellipsis within quotes..."',
'<p>&ldquo;Ellipsis within quotes&hellip;&rdquo;</p>'
)
self.assertMarkdownRenders(
"*Custer*'s Last Stand",
"<p><em>Custer</em>&rsquo;s Last Stand</p>"
)

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

0 comments on commit dba8025

Please sign in to comment.