You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect HTML output for code span containing </> #1528
In markdown==3.8, a code span containing the string "`</>`" is incorrectly rendered. Instead of producing the expected HTML output with the characters escaped, it strips the content entirely:
This issue appears specific to the combination </>. Would appreciate any insight into whether this is a known bug, an edge case in the parser, or an intentional (though surprising) behavior. Thanks!
As far as I can tell, the </> is processed and stripped before the code block is handled, so `` is empty and not processed as a code block. I don't know why, but that will need more analysis.
We can see that in the second test that </> is never seen:
==== Test1
Start tag: html
Start tag: body
Data : <
End tag : body
End tag : html
None
==== Test2
Start tag: html
Start tag: body
End tag : body
End tag : html
None
I'm not sure what to do with this info currently. From what I can tell, the parser looks at it as a tag, but since it has no name, it is never reported or sent to the handler; it just gets ignored. While this is fine for an HTML parser (browsers do this) a Markdown parser wants to capture that content.
I've figured out a hacky way to capture and process </>. We have to sneak it in and capture it under something else (start tag, etc.), then we just check for it and send it to data instead.
It should be noted that putting a space anywhere in </> (< />, </ >, or < / >) also allows this to work with no code modification. The problem only arises when we have exactly </>.
There may be a less ugly way to handle these than my experimental hack, but as a starting point, the hack does seem to work.
I've pushed a PR to get a discussion going. What I have works, and I've added tests that illustrate what happens in various scenarios. This is basically my current proposal. I am open to other creative approaches, but if no better solution can be determined, then I would vote just to move ahead with it as I don't think ignoring </> is the right approach.
Activity
facelessuser commentedon Apr 25, 2025
It looks like a bug to me, but it'll need some investigation though to understand why this is happening.
facelessuser commentedon Apr 25, 2025
As far as I can tell, the
</>is processed and stripped before the code block is handled, so``is empty and not processed as a code block. I don't know why, but that will need more analysis.facelessuser commentedon Apr 26, 2025
So, I was digging deeper into this. This appears to be something that HTMLParser is doing.
Consider the following example:
We can see that in the second test that
</>is never seen:I'm not sure what to do with this info currently. From what I can tell, the parser looks at it as a tag, but since it has no name, it is never reported or sent to the handler; it just gets ignored. While this is fine for an HTML parser (browsers do this) a Markdown parser wants to capture that content.
facelessuser commentedon Apr 26, 2025
I've figured out a hacky way to capture and process
</>. We have to sneak it in and capture it under something else (start tag, etc.), then we just check for it and send it to data instead.It should be noted that putting a space anywhere in
</>(< />,</ >, or< / >) also allows this to work with no code modification. The problem only arises when we have exactly</>.There may be a less ugly way to handle these than my experimental hack, but as a starting point, the hack does seem to work.
This seems to work when patched into Markdown without breaking any tests:
So moving forward, we would just need to settle on the least egregious hack.
Fix HTML handling of `</>`
facelessuser commentedon Apr 26, 2025
I've pushed a PR to get a discussion going. What I have works, and I've added tests that illustrate what happens in various scenarios. This is basically my current proposal. I am open to other creative approaches, but if no better solution can be determined, then I would vote just to move ahead with it as I don't think ignoring
</>is the right approach.waylan commentedon Apr 26, 2025
@facelessuser thanks for the full analysis. This is a weird edge case, but I can also understand why the HTMLParser would act the way it does.
Fix HTML handling of `</>`
chore(deps): update dependency markdown to v3.10 (#88)