erusev / parsedown-extra

Markdown Extra Extension for Parsedown

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

<p markdown="1"> shows unexpected behavior

moefuerst opened this issue · comments

With Markdown Extra it is possible to put Markdown-formatted text inside any block-level tag. When I try that with Parsedown Extra for a p element however, it does not produce the desired result.

With Markdown Extra,

<p class="my-class" markdown="1">
   This Markdown paragraph has *my-class*.
</p>

translates to

<p class="my-class">
This Markdown paragraph has <em>my-class</em>.
</p>

Parsedown Extra wraps it in an additional ptag:

<p class="my-class">
<p>This Markdown paragraph has <em>my-class</em>.</p>
</p>

(You can test this easily with http://parsedown.org/extra/)

This is a really annoying behavior and make it impossible to use paragraph <p> tags with classes.
As the nested <p> tag construct is not valid usually browsers translate this to three <p> tags in a row.
The workaround to use <div> tag to set the class only works when the class does not have to be on the <p> tag only.
Would be interesting to know if this is considered as bug and if yes if it's planed to be fixed.
Is there another workaround known how to prevent from adding this additional <p> tag?

Consider that with something like:

<p class="my-class" markdown="1">
```
Foo
```
</p>

You'd want the result to be

<p class="my-class" markdown="1">
<pre><code>
Foo</code></pre>
</p>

And not

<p class="my-class" markdown="1">
Foo
</p>

Similarly writing text as you have is markdown syntax for a paragraph, and so there isn't a reason that one shouldn't be rendered as a result in the context of the markdown syntax.

Also consider that the result of

<div class="my-class" markdown="1">
   This Markdown paragraph has *my-class*.
</div>

Should be

<div class="my-class" markdown="1">
<p>This Markdown paragraph has <em>my-class</em>.</p>
</div>

And so the difference here is that of surrounding HTML.
Parsedown isn't a HTML parser, and so while the result here may not be semantically correct, it's not really a decision that Parsedown can be expected to make without becoming a HTML parser to integrate variants on this case.