snarkdown icon indicating copy to clipboard operation
snarkdown copied to clipboard

Links inside bold/italic text result in invalid HTML

Open pbock opened this issue 7 years ago • 0 comments

Links inside runs of bold or italic text are rendered as invalid HTML.

For example, the following Markdown:

foo **[link](https://example.com)** bar

is rendered as:

foo <strong><a href="https://example.com">link</strong></a><strong> bar</strong>

whilst the expected output would be:

foo <strong><a href="https://example.com">link</a></strong> bar

More examples here.

Two things are unexpected here:

  1. The output is invalid because the <strong> and <a> tags are closed in the same order in which they're opened.
  2. The <strong> tag is then re-opened and not closed until the end of the text, causing more of the text to be bold than intended.

The same happens when using __ instead of **, as well as with italics (_ or *).

When the formatting is inside the link, the result is as expected:

foo [**link**](https://example.com) bar

This renders as:

foo <a href=\"https://example.com\"><strong>link</strong></a> bar

pbock avatar May 30 '18 10:05 pbock