Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering code comment as heading in html inside markdown #315

Open
toonarmycaptain opened this issue Sep 2, 2022 · 2 comments
Open

Rendering code comment as heading in html inside markdown #315

toonarmycaptain opened this issue Sep 2, 2022 · 2 comments
Milestone

Comments

@toonarmycaptain
Copy link

toonarmycaptain commented Sep 2, 2022

We're embedding some pyscript inside out markdown, and having some trouble with code comments being rendered as headings:

It appears to be an issue within a custom tag where there is a blank line before the line prefaced with the #

To reproduce:

$ python3
Python 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mistune
>>> mistune.__version__
'2.0.4'
>>> mistune.html(r'''<some-tag>
... 
... # a comment
... something with # a trailing comment
... </some-tag>
... 
... ''')
'<some-tag>\n<h1>a comment</h1>\n<p>something with # a trailing comment</p>\n</some-tag>\n'

What is expected:

The code/comments within the custom tags (in our case they're <py-script></py-script>) should not be interpreted as markdown (there weren't in a pre-2.x version of mistune), and produce:
<some-tag>\n<p># a comment</p>\n<p>something with # a trailing comment</p>\n</some-tag>\n

When there is no blank line preceeding the code comment, this behavior is not observed:

>>> mistune.html(r'''<some-tag>
... # a comment
... something with # a trailing comment
... </some-tag>''')
'<some-tag>\n# a comment\nsomething with # a trailing comment\n</some-tag>\n'
@lepture
Copy link
Owner

lepture commented Nov 25, 2022

This is because mistune v2 is following commonmark's HTML rule, you can check the result in commonmark demo.

@lepture
Copy link
Owner

lepture commented Nov 25, 2022

Put it into v3:

Adding another HTML parsing rule.

@lepture lepture added this to the Version 3 milestone Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants