vsch / flexmark-java

CommonMark/Markdown Java parser with source level AST. CommonMark 0.28, emulation of: pegdown, kramdown, markdown.pl, MultiMarkdown. With HTML to MD, MD to PDF, MD to DOCX conversion modules.
BSD 2-Clause "Simplified" License
2.28k stars 270 forks source link

Link text for inline content fails to inline MultiMarkdown-style image references #408

Open jingibus opened 4 years ago

jingibus commented 4 years ago

Followup for #407:

With newly landed fixes, the following example works correctly in ParserEmulationProfile.MULTI_MARKDOWN:

[![][moon]](/uri)

[moon]: moon.jpg

yields:

<p><a href=\"/uri\"><img src=\"moon.jpg\" alt=\"\" /></a></p>

However, MultiMarkdown format image references with width and height included do not.

[![][moon]](/uri)

[moon]: moon.jpg width: 80px height: 90px

yields:

<p><a href=\"/uri\">![][moon]</a></p>
<p>[moon]: moon.jpg width: 80px height: 90px</p>

MultiMarkdown-style image references that include width and height metadata fail to parse the inner content as an ImageRef.

More info:

This repro is not quite as crystal clear as the previous one, because out of the box ParserEmulationProfile.MULTI_MARKDOWN does not render the correct HTML for the following non-inline content case:

![][moon]

[moon]: moon.jpg width: 80px height: 90px

yields:

<p>![][moon]</p>
<p>[moon]: moon.jpg width: 80px height: 90px</p>

It does, however, parse this as an ImageRef, which has been good enough to get me to the goal line in my project.

vsch commented 4 years ago

@jingibus, parser family currently affects mostly list item nuances particular to a family, not all the possible extensions present in the markdown parser.

MultiMarkdown has a lot of extensions which are not implemented or would require writing new extensions.

As a workaround you can use the attributes extension then you can add any attributes to almost any node. For references the attributes need to be specified after the definition to keep them away from the reference definition line.

![][moon]

[moon]: moon.jpg
{width=80px height=90px}

Renders as:

<p><img src="moon.jpg" alt="" width="80px" height="90px" /></p>
jingibus commented 4 years ago

Thank you for the information. I have an opportunity to "clean up" Markdown source when it's imported into the system, so if the attributes will emit cleanly that workaround should serve.

I may have time to do the extensions work as well if it's not too much hassle.