smu icon indicating copy to clipboard operation
smu copied to clipboard

Embedded HTML tags get wrapped in <p> tags

Open clark800 opened this issue 1 year ago • 3 comments

The readme says: "You can include arbitrary HTML code in your documents. The HTML will be passed through to the resulting document without modification."

But when you embed top-level HTML tags like "div", they get wrapped in "p" tags. I think the ideal behavior would as the readme suggests, which is to not add the "p" tags.

clark800 avatar Jul 26 '23 21:07 clark800

What would be the rule? I don't think this should apply for all top level tags. E.g.

Welcome!

<b>Be nice to each other!<b>

Thanks.

should add paragraph tags around each block including the middle one. So would they only be left out for block level tags?

karlb avatar Jul 28 '23 08:07 karlb

Yeah, I think changing the behavior for block-level tags only would make sense. Then somehow disable markdown processing until the corresponding closing tag. Maybe keep a counter of non-commented, non-quoted open (+1) and close (-1) tags of the same tag type and it ends when the counter reaches zero? I think it's fair to assume that the HTML is valid and tags/comments/quotes are balanced. If that's too complicated, I think you could also just count the tags that start at the beginning of the line and make it a user requirement that these are not commented or quoted.

clark800 avatar Jul 28 '23 23:07 clark800

Looks like the official rules say that block-level tags should be treated differently:

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. Markdown is smart enough not to add extra 
(unwanted) <p> tags around HTML block-level tags.

https://daringfireball.net/projects/markdown/syntax#html

Based on the description, it sounds like just counting corresponding open and close tags at the beginning of lines would be sufficient.

clark800 avatar Sep 27 '23 22:09 clark800