Closed Kristinita closed 7 months ago
If I recall, @waylan has specifically stated in the past that md_in_html
is mainly meant for root level HTML. That means HTML nested in indented constructs, such as lists are not expected to work.
With that said, I do wish they did work. As an alternative, you can use the pymdownx.blocks.html
extension:
import markdown
MD = """
/// html | div.KiraCustomClass
**This is a Markdown**
///
1. Kira first list item
/// html | div.KiraCustomClass
**This is also Markdown**
///
1. Kira second list item
"""
html = markdown.markdown(
MD,
extensions=['pymdownx.blocks.html']
)
print(html)
<div class="KiraCustomClass">
<p><strong>This is a Markdown</strong></p>
</div>
<ol>
<li>
<p>Kira first list item</p>
<div class="KiraCustomClass">
<p><strong>This is also Markdown</strong></p>
</div>
</li>
<li>
<p>Kira second list item</p>
</li>
</ol>
Status: RESOLVED :heavy_check_mark:
I get expected behavior for MCVE and real examples when I use pymdownx.blocks.html
instead of md_in_html
.
Thanks.
Type: Documentation changes 📜
has specifically stated in the past that md_in_html is mainly meant for root level HTML. That means HTML nested in indented constructs, such as lists are not expected to work.
If so, I think it would be a nice to add this to the md_in_html
documentation to prevent users from trying to use md_in_html
not for root level HTML. I also think it would be nice to add to the documentation why md_in_html
meant for root level HTML. Users like me may not understand why this was intended.
Thanks.
The reason for this behavior is based on the original Markdown rules, which state in part (emphasis added):
The only restrictions are that block-level HTML elements — e.g.
<div>
,<table>
,<pre>
,<p>
, etc. — must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces.
The md-in-html extension relies on the standard rules for identifying what is considered a "block-level" element. If you want to diverge from the standard rules, then you need to look at third-party extensions.
1. Summary
If I use HTML tags with “markdown="1"” in child elements of the
<li>
tag, Python Markdown successfully converts Markdown to HTML but doesn’t removemarkdown="1"
— the attribute, non-valid in production HTML.It looks like a bug. I didn’t find in the documentation for the “Markdown in HTML” plugin why my syntax is incorrect.
2. MCVE
2.1. KiraDivInsideList.md
2.2. Command
2.3. Behavior
2.3.1. Expected
2.3.2. Actual
For the first
<div>
Python Markdown removemarkdown="1"
, but for my<div>
inside<li>
,markdown="1"
still remains.3. Validity
<li>
can contain any element that is valid in<body>
. I haven’t found reasons why I can’t use<div>
with a custom class inside<li>
as in my example.4. Environment
Thanks.