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
admonition extension returns **invalid** html code without blank line. #1329
Comments
Your proposed change alters the HTML output. Note that the HTML output is defined by what docutils outputs for admonitions. We are simply matching their output. In other words, as docutils outputs the title in a I'm assuming the issue it related to the the tab length. Presumably somewhere within the extension tab length is assumed to always be 4. We should instead be pulling the value in from the Markdown class instance. A brief look at the code reveals that we are already, but maybe it is being missed in one obscure location. This will take some digging in to find. This is why we have been working on blocks which don't rely on indentation. You might want to try block based admonitions. They will not suffer from this issue. |
The element doesn't need to be changed, the content is indented and should be seen as an indented code block, but somehow it is included in the summary. We need to ensure it doesn't get inserted into the summary. We'll have to take a look for a way to handle this properly, but I don't think your suggestion is the way to go. As a workaround, if you intend to use an indented code block, put an empty line between admonition headers and the block, and if you did not intend to have an indented code block, ensure the paragraph is not indented as such. |
Further, |
So if I'm understanding correctly, if there is no blank line between the opening line ( I think I know what the problem is. It is related to the workarounds for the pesky block-parser, which splits everything into blocks by blank lines. That means that the entire body of an admonition is not fed in all together (each line-separated-block is fed in separately). Therefore, the code in |
It certainly needs investigation. I'm fairly certain it can be reasonably fixed, but I'd have to dig in and understand the conditions that cause it. |
That doesn't seem to be entirely true — consider the following differences: >>> text = """
... !!! danger "This is not"
... one long admonition title
... """
>>> print(markdown.markdown(text, extensions=['admonition']))
<div class="admonition danger">
<p class="admonition-title">This is not</p>
<p>one long admonition title</p>
</div>
>>> print(markdown.markdown(text, tab_length=2, extensions=['admonition']))
<div class="admonition danger">
<p class="admonition-title">This is not<p>one long admonition title</p>
</p>
</div> It seems to me that >>> text = """
... !!! danger "This is not"
...
... one long admonition title
... """
>>> print(markdown.markdown(text, extensions=['admonition']))
<div class="admonition danger">
<p class="admonition-title">This is not</p>
<p>one long admonition title</p>
</div>
>>> print(markdown.markdown(text, tab_length=2, extensions=['admonition']))
<div class="admonition danger">
<p class="admonition-title">This is not<p>one long admonition title</p>
</p>
</div> |
@ferdnyc, I don't think you understand my statement. Using If you are using tab length 2, you should only indent your admonition content by 2. Indenting the first line in this case by 4 should trigger a code block, but it doesn't. If you use the default tab length of 4, you should indent your admonition content by 4. Indenting the first line in this case by 8 should trigger a code block, but it doesn't. >>> import markdown
>>> md = """
... !!! danger "This is not"
... one long admonition title
... """
>>> print(markdown.markdown(md, tab_length=2, extensions=['admonition']))
<div class="admonition danger">
<p class="admonition-title">This is not</p>
<p>one long admonition title</p>
</div>
>>> md = """
... !!! danger "This is not"
... one long admonition title
... """
>>> print(markdown.markdown(md, tab_length=2, extensions=['admonition']))
<div class="admonition danger">
<p class="admonition-title">This is not<p>one long admonition title</p>
</p>
</div>
>>> md = """
... !!! danger "This is not"
... one long admonition title
... """
>>> print(markdown.markdown(md, tab_length=4, extensions=['admonition']))
<div class="admonition danger">
<p class="admonition-title">This is not</p>
<p>one long admonition title</p>
</div>
>>> md = """
... !!! danger "This is not"
... one long admonition title
... """
>>> print(markdown.markdown(md, tab_length=4, extensions=['admonition']))
<div class="admonition danger">
<p class="admonition-title">This is not<p>one long admonition title</p>
</p>
</div> So, my statement is that what you set the tab length to doesn't matter, it is the handling of the first line indent. Nothing I've seen has proven my statement false. With that said, I haven't had a chance to root cause this issue yet. |
Fair enough. Although, based on the tests I showed, this workaround... doesn't?
|
It's been long enough that I don't recall if I tried out the workaround, or assumed the workaround should work, but you are correct that a new line does not fix the issue. It seems using fenced code blocks does work, or at least when using SuperFences (Python Markdown's |
I should also mention that the new Pymdown Extension's Admontion does not have this issue. A new line between the header is required if indenting as indenting directly under the header is how you specify YAML options >>> import markdown
>>> md = """
... /// danger | This is not
... one long admonition title
... ///
... """
>>> print(markdown.markdown(md, tab_length=2, extensions=['pymdownx.blocks.admonition']))
<div class="admonition danger">
<p class="admonition-title">This is not</p>
<p>one long admonition title</p>
</div>
>>> md = """
... /// danger | This is not
...
... one long admonition title
... ///
... """
>>> print(markdown.markdown(md, tab_length=2, extensions=['pymdownx.blocks.admonition']))
<div class="admonition danger">
<p class="admonition-title">This is not</p>
<pre><code> one long admonition title
</code></pre>
</div> With that said, this has been a reminder that I should try and look into this issue here. |
I think I have this solved, a fix should be coming shortly. |
Fix a corner case in admonitions where if an indented code block was provided as the first block, the output would be malformed. Fixes Python-Markdown#1329
Fix a corner case in admonitions where if an indented code block was provided as the first block, the output would be malformed. Fixes #1329.
Recommended working solution:
The text was updated successfully, but these errors were encountered: