markdown-it / markdown-it

Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed
https://markdown-it.github.io
MIT License
17.96k stars 1.7k forks source link

[Bug report] <img> tag is parsed as html_block token #795

Closed meteorlxy closed 3 years ago

meteorlxy commented 3 years ago

<img> tag should be a html_inline token, but it seems to be parsed as html_block token.

https://markdown-it.github.io/#md3=%7B%22source%22%3A%22%3Cimg%20src%3D%5C%22foo.png%5C%22%3E%5Cn%22%2C%22defaults%22%3A%7B%22html%22%3Atrue%2C%22xhtmlOut%22%3Afalse%2C%22breaks%22%3Afalse%2C%22langPrefix%22%3A%22language-%22%2C%22linkify%22%3Atrue%2C%22typographer%22%3Atrue%2C%22_highlight%22%3Atrue%2C%22_strict%22%3Afalse%2C%22_view%22%3A%22debug%22%7D%7D

image

puzrin commented 3 years ago

Works as expected. That's markdown terms, see spec.

Inline elements will be force-wrapped by paragraph: https://markdown-it.github.io/#md3=%7B%22source%22%3A%22%3Cb%3Etest%3C%2Fb%3E%22%2C%22defaults%22%3A%7B%22html%22%3Atrue%2C%22xhtmlOut%22%3Afalse%2C%22breaks%22%3Afalse%2C%22langPrefix%22%3A%22language-%22%2C%22linkify%22%3Atrue%2C%22typographer%22%3Atrue%2C%22_highlight%22%3Atrue%2C%22_strict%22%3Afalse%2C%22_view%22%3A%22src%22%7D%7D

meteorlxy commented 3 years ago

@puzrin ??? That's what I reported. img tag does not work like that!

puzrin commented 3 years ago

https://spec.commonmark.org/dingus/?text=%3Cimg%20src%3D%22foo.png%22%3E%0A%0A%3Cb%3Etest%3C%2Fb%3E

That works exactly as reference parser. Issues like "your parser should work not as reference one" are not welcome.

meteorlxy commented 3 years ago

I see, so this should be reported to commonmark

meteorlxy commented 3 years ago

Alright, found the related issue: https://github.com/commonmark/commonmark-spec/issues/492

puzrin commented 3 years ago

As far as i understand, tags are wrapped with paragraph only if followed with something AND are not in list of "block tags". I don't remember details "why". But there were long forum discussions if anyone wish to dive inside.

meteorlxy commented 3 years ago

@puzrin Thanks for your explanation!

Although it's a little weird, we have to follow the "implicit" spec. (I could not find the related description in commonmark spec... 😅 )

rlidwka commented 3 years ago

Although it's a little weird, we have to follow the "implicit" spec.

https://spec.commonmark.org/0.30/#html-blocks

4.6, condition 7:

Start condition: line begins with a complete open tag (with any tag name other than pre, script, style, or textarea) or a complete closing tag, followed by zero or more spaces and tabs, followed by the end of the line. End condition: line is followed by a blank line.

The spec is very much explicit about this, standalone <img> on its own line is a block tag.