Skip to content

smarty: double sets of quotes not working at end #1514

Closed
@ChrisMayfield

Description

@ChrisMayfield

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, &ldquo;She said &lsquo;Hello.&rsquo;&ldquo;</p>

The &ldquo; at the end of this example should be &rdquo;.

The quote marks were replaced in this order:

  1. openingSingleQuotesRegex
  2. closingSingleQuotesRegex
  3. openingDoubleQuotesRegex
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions