bastianallgeier / triptrap

MIT License
5 stars 1 forks source link

KirbyTags are wrapped in <p> tags #3

Open hdodov opened 5 years ago

hdodov commented 5 years ago

If I have the following content:

Sample text: (image: quote.png caption: Caption lorem ipsum dolor sit amet)

...I get the following markup:

<p>Sample text: (image: quote.png caption: Caption lorem ipsum dolor sit amet)</p>

That's expected. But when the text is parsed with kirbytext(), the created <figure> tag is put within the <p> tag, which is not valid.

The obvious solution is to save it like that:

Sample text:
(image: quote.png caption: Caption lorem ipsum dolor sit amet)

...which turns into:

<p>Sample text:</p>
<p>(image: quote.png caption: Caption lorem ipsum dolor sit amet)</p>

...and you have the same problem. I don't know how this may be solved efficiently, though. I guess:

The reason this is such a problem is because the browser can't handle block elements inside a <p> tag since the HTML spec does not allow it. Because of that, markup like:

<p>foo <div>bar</div> baz</p>

...is turned by the browser into:

<p>foo </p><div>bar</div> baz<p></p>

...which is bad. You expect one <p> tag and you get two, one of which is empty.