Repository navigation
Don't apply smarty-pants inside inline HTML tags - #735
Open
LuisFigueroaG wants to merge 2 commits into
Open
LuisFigueroaG wants to merge 2 commits into
LuisFigueroaG wants to merge 2 commits into
Conversation
smarty-pants ran over the whole span text, so quotes in tag attributes and the dashes in HTML comments were turned into entities, breaking the markup (e.g. <img src="a.png" alt="b"> became src="a.png” ...). Swap tags and comments out for placeholders while the substitutions run, which also makes the footnote-ref special case unnecessary. Fixes trentm#150
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #150
With the
smarty-pantsextra on, the quote and dash substitutions ran over the whole span text, inline HTML tags included. Quotes inside attributes were turned into entities and broke the tag:Inline HTML comments broke too, because
--became an en dash:<!-- note -->came out as<!– note –>.The footnote case from the original report was already handled by a special case in
SmartyPants.runthat changedclass="footnote-ref”back, but other tags still had the problem.What I changed:
SmartyPants.runnow swaps the inline tags and comments for hash placeholders first, using the existing_sorta_html_tokenize_re. Then it does the substitutions and puts the tags back. Since the placeholders aren't whitespace, the text around a tag looks the same to the quote regexes as it did before, so output outside tags doesn't change. With tags skipped, the footnote special case isn't needed any more, so I removed it.footnotes_smarty-pantsstill passes.To check that nothing else changed, I ran every
.textfile in the test dirs through master and through this branch withsmarty-pantson (alone and withfootnotes,fenced-code-blocksandtables). The only differences were inside tags (src/width/titleattributes and<!-- -->comments), plus the randomly encoded mailto links, which are different on every run anyway.Tests:
tm-cases/smarty_pants_html_attributes_issue150covers an<img>with double-quoted attributes, an<a>with a single-quotedtitle, quotes inside a<span>, and an inline comment containing--. It fails without the fix.make testone: 289 tests, OK (288 on master)pycodestyle lib/markdown2.py: 413 lines vs 415 on master (no new warnings)make testredos: 7 tests, OK