smarty: double sets of quotes not working at end · Issue #1514 · Python-Markdown/markdown (original) (raw)
The following example renders incorrectly:
import markdown
text = ''' He replied, "She said 'Hello.'" '''
html = markdown.markdown(text, extensions=['smarty']) print(html)
The output is:
<p>He replied, “She said ‘Hello.’“</p>
The “
at the end of this example should be ”
.
The quote marks were replaced in this order:
- openingSingleQuotesRegex
- closingSingleQuotesRegex
- openingDoubleQuotesRegex
- remainingDoubleQuotesRegex
Unfortunately:
- closingDoubleQuotesRegex didn't match, because the
"
is not followed by a space (it's the last character of the string, which is stripped prior to replacement). - closingDoubleQuotesRegex2 didn't match, because of the closing single quote replacement (i.e., the intermediate data in
SubstituteTextPattern.handleMatch()
contains\u0003
before the"
).
One possible way to fix this issue might be to change closingDoubleQuotesRegex to r'"(?=\s|$)'
(i.e., double quote followed by whitespace or end of string). However that doesn't work in general, so a special case is likely needed.