karlb / smu

Simple MarkUp - markdown/commonmark like syntax
http://karlb.github.io/smu/
MIT License
55 stars 5 forks source link

Embedded HTML tags get wrapped in <p> tags #14

Open clark800 opened 1 year ago

clark800 commented 1 year ago

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.

karlb commented 1 year ago

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?

clark800 commented 1 year ago

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 commented 1 year ago

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.