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
Markdown formatting syntax is not processed within block-level HTML tags. E.g., you can’t use Markdown-style emphasis inside an HTML block.
In fact, the current behavior exactly matches the reference implementation. Therefore, I'm surprised this ever worked for you. If anything, I would consider the old behavior a bug.
You may want to consider using the md_in_html extension. However, note that html and body tags are not listed among block-level tags there. Markdown content is considered an HTML fragment, which is to be inserted within an HTML document. Therefore, the entire document is expected to be within a body tag. That being the case, html and body tags should not be within Markdown content.
In fact, the html and body tags have never been included in the list of block-level tags in our codebase (including prior to #803). I can only guess as to why you were getting the behavior you were before. Presumably, the lack of a closing tag was confusing the parser as the old implementation expected XHTML (which required closing tags to be valid). The new implementation parses HTML5 which is much more forgiving. Why that was resulting in the html not being wrapped in a p I have no idea. But is does explain why the Markdown content was previously being parsed and it no longer is. In any event, as the current behavior is intentional, I have no inclination to dig through the old code to figure out what it was doing.
Regardless, you can override/alter the list of block-level tags via an extension. Feel free to create your own third-party extension which adds html, block. and any other tags you want to be considered block-level. For that matter, you don't even need an extension, Just alter an instance of the markdown.Markdown class:
Of course, your Markdown content still won't be parsed as Markdown, so that doesn't really help you. Perhaps a better approach would be to use the md_in_html extension and set markdown=block on the html and body tags. That should force them to be parsed as block level tags and allow the Markdown content within to be parsed as Markdown.
Perhaps a better approach would be to use the md_in_html extension and set markdown=block on the html and body` tags. That should force them to be parsed as block level tags and allow the Markdown content within to be parsed as Markdown.
If you meant it like this, with v3.4, it doesn't seem to work:
$ cat /tmp/test_case.md
<!DOCTYPE html>
<html markdown=block>
<body markdown=block>
Should be **bold**
(Note, <body> needs to be unindented to pick 0-column markdown.)
I am curious if there is a reason to not just specify html by default? I do understand that it is stated to not work, but I wonder if there is a strong justification to not just add html?
I wonder if there is a strong justification to not just add html?
The reason is as I stated earlier...
Markdown content is considered an HTML fragment, which is to be inserted within an HTML document. Therefore, the entire document is expected to be within a body tag. That being the case, html and body tags should not be within Markdown content.
Truth be told, I didn't remember that the body tag was included. I question whether it should be.
On the other hand, I agree that html and body tags are "elements which Markdown should not be mucking up the contents of" as noted in a code comment. So maybe we should add it.
(These are two separate lists? 🤔)
Yes, the old list was left at markdown/util.py to maintain backward compatibility as various older third party extensions have used it. Truth be told, we can probably remove it by now. I forgot it was still there.
Activity
waylan commentedon Nov 28, 2022
The syntax rules state:
In fact, the current behavior exactly matches the reference implementation. Therefore, I'm surprised this ever worked for you. If anything, I would consider the old behavior a bug.
You may want to consider using the md_in_html extension. However, note that
htmlandbodytags are not listed among block-level tags there. Markdown content is considered an HTML fragment, which is to be inserted within an HTML document. Therefore, the entire document is expected to be within abodytag. That being the case,htmlandbodytags should not be within Markdown content.In fact, the
htmlandbodytags have never been included in the list of block-level tags in our codebase (including prior to #803). I can only guess as to why you were getting the behavior you were before. Presumably, the lack of a closing tag was confusing the parser as the old implementation expected XHTML (which required closing tags to be valid). The new implementation parses HTML5 which is much more forgiving. Why that was resulting in thehtmlnot being wrapped in apI have no idea. But is does explain why the Markdown content was previously being parsed and it no longer is. In any event, as the current behavior is intentional, I have no inclination to dig through the old code to figure out what it was doing.Regardless, you can override/alter the list of block-level tags via an extension. Feel free to create your own third-party extension which adds
html,block. and any other tags you want to be considered block-level. For that matter, you don't even need an extension, Just alter an instance of themarkdown.Markdownclass:Of course, your Markdown content still won't be parsed as Markdown, so that doesn't really help you. Perhaps a better approach would be to use the md_in_html extension and set
markdown=blockon thehtmlandbodytags. That should force them to be parsed as block level tags and allow the Markdown content within to be parsed as Markdown.As there is no bug, I am closing this as wontfix.
kernc commentedon Nov 28, 2022
If you meant it like this, with v3.4, it doesn't seem to work:
(Note,
<body>needs to be unindented to pick 0-column markdown.)It does works after also setting:
but this then can't be used from the command line.
Wouldn't you add
htmlto defaultBLOCK_LEVEL_ELEMENTSlikebodyis?markdown/markdown/util.py
Lines 43 to 44 in e3604b4
markdown/markdown/core.py
Lines 82 to 83 in e3604b4
(These are two separate lists? 🤔)
My use case is a simple .md file that compiles directly into the whole HTML page, circumventing the need for a separate templating engine.
facelessuser commentedon Nov 28, 2022
I am curious if there is a reason to not just specify
htmlby default? I do understand that it is stated to not work, but I wonder if there is a strong justification to not just addhtml?waylan commentedon Nov 28, 2022
The reason is as I stated earlier...
Truth be told, I didn't remember that the
bodytag was included. I question whether it should be.On the other hand, I agree that
htmlandbodytags are "elements which Markdown should not be mucking up the contents of" as noted in a code comment. So maybe we should add it.Yes, the old list was left at
markdown/util.pyto maintain backward compatibility as various older third party extensions have used it. Truth be told, we can probably remove it by now. I forgot it was still there.