Fix premature HTML-escaping of inline code #393
Merged
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 #372 by moving HTML-escaping of
codespan
from the parser into the HTML renderer.Passes all tests, and
test_ast_output
is enhanced to cover this case. (I just ranpytest
, are there other tests or any linters I should run?)Before (parse to AST wrongly shows raw codespan content as
&
, which is a bug for use-cases that never render to HTML - for comparison,&
outside of codespan doesn't get escaped):After (pure parse correctly shows raw code content is
&
):After (still works when rendering to HTML):
Use-case example: I have a script which publishes files written in Markdown as Tumblr posts. It walks through Mistune's AST, generating Tumblr's "NPF". I need the raw contents, because Tumblr takes the raw text and does its own HTML rendering+escaping server-side. Currently, my script has to have extra handling for
codespan
tokens to unescape the characters escaped bymistune.util.escape
.P.S. Special thanks to @torokati44 for finding the exact line in the parser that was causing the problem.