mity / md4c

C Markdown parser. Fast. SAX-like interface. Compliant to CommonMark specification.
MIT License
755 stars 138 forks source link

Text spills to wrong element (image nesting) #211

Closed step- closed 5 months ago

step- commented 5 months ago

This case involves hard breaks within the text of nested images.

Test subject:
(two spaces after lines 1, 2 and 3)

![outer BR  
![inner BR  
inner image](test.png)  
outer image](./test.png)

cmark:

<p><img src="./test.png" alt="outer BR inner BR inner image outer image" /></p>

Above we see that cmark conflates all text into the alt attribute. This is the recommended way of handling nested images for HTML (as you commented in your source code).

On the other hand something goes the wrong way in md2html, which lets the text in line 4 spill over to the containing <p> element.

mdview:

<p><img src="./test.png" alt="outer BR inner BR inner image"><br>
outer image</p>
mity commented 5 months ago

I think this is duplicate of #210.

step- commented 5 months ago

Now it passes my test suite. I think the reason we aren't seeing this problem after #210 is that now r->image_nesting_level is 1 for the outer image, and 0 when outside any image, so https://github.com/mity/md4c/blob/ca169a9/src/md4c-html.c#L504 doesn't output a hard-break anymore (see also L508 for soft break).