bug: fix links with square brackets in inline code break wrapping italics #3785
+3
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Marked version: 16.3.0 / master
Markdown flavor: CommonMark
Description
_#3774Expectation
The following Markdown:
_[a[b]c](http://example.com/_/path)_to be parsed into an emphasized link whose text is a codespan. In HTML this should be:
<p><em><a href="http://example.com/_/path"><code>a[b]c</code></a></em></p>Result
Before the change Marked produced a broken output where the emphasis was split and the link text/URL were parsed separately. The produced HTML looked like:
<p><em>[<code>a[b]c</code>](http://example.com/</em>/path)_</p>What was attempted
Updated the em/strong masking pattern so link text that contains a codespan is treated as a single block to be skipped by the em/strong tokenizer.
Changed the
blockSkipregex inmarked/src/rules.tsso bracketed link text may include backtick codespans (allowing patterns like[`a[b]c`]inside[]) and thus be masked as a unit for em parsing.Added spec tests:
test/specs/new/em_link_brackets.mdtest/specs/new/em_link_brackets.htmlWith that change, the inline tokenizer no longer sees the
_delimiter split across the link and URL, so the emphasis wrapping the link is preserved and the output matches the expectation.Contributor