fix: keep emphasis in the text of a rejected reference link - #4059
Merged
UziTech merged 2 commits intoAug 24, 2026
Conversation
|
@AntonioBraga88 is attempting to deploy a commit to the MarkedJS Team on Vercel. A member of the Team first needs to authorize it. |
A reference link candidate whose text already holds a link never becomes a link, but the mask em and strong read still flattened the whole span, so every emphasis marker inside it was invisible. Mask the links the text holds instead of the span, and leave images alone, since an image may hold a link. Fixes CommonMark example 533.
luantaraschi
force-pushed
the
fix/emphasis-in-rejected-link-text
branch
from
August 18, 2026 23:04
088bfc5 to
726aed0
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
styfle
approved these changes
Aug 24, 2026
github-actions Bot
pushed a commit
that referenced
this pull request
Aug 24, 2026
## [18.0.11](v18.0.10...v18.0.11) (2026-08-24) ### Bug Fixes * do not nest a link inside a link ([#4051](#4051)) ([e250e31](e250e31)) * inlineTokens rebuilds the reflink-mask preamble per call ([#4040](#4040)) ([0653c24](0653c24)) * keep emphasis in the text of a rejected reference link ([#4059](#4059)) ([b699db3](b699db3))
max-sixty
pushed a commit
to max-sixty/leaf
that referenced
this pull request
Aug 30, 2026
The weekly vendored-dependency check found `marked` pinned at 18.0.10 in `scripts/vendor-marked.sh` while upstream publishes 18.0.11. The other three pins the check covers — `highlight.js` 11.12.0, `@pierre/diffs` 1.3.6, `shiki` 4.4.3 — are already current, so this is the only drift this week. The fix bumps `MARKED_VERSION` and reruns `scripts/vendor-marked.sh`, so the commit carries the rebuilt `skills/leaf/assets/vendor/marked.esm.js` rather than the version string alone. `vendor-marked.sh` copies upstream's single ESM file, so the bundle tracks the version directly and nothing else feeds it. Verified with `uv run pytest tests` (723 passed, 6 skipped) and the browser file that owns the bundle's only importer, `uv run pytest tests/test_render_conversations.py --run-nightly` (47 passed) — `skills/leaf/assets/runtime/conversation/messages.js` is the sole place `marked.esm.js` is imported. <details><summary>Upstream 18.0.11 release notes</summary> Patch release, three bug fixes, no API change ([v18.0.10...v18.0.11](markedjs/marked@v18.0.10...v18.0.11)): - do not nest a link inside a link ([#4051](markedjs/marked#4051)) - `inlineTokens` rebuilds the reflink-mask preamble per call ([#4040](markedjs/marked#4040)) - keep emphasis in the text of a rejected reference link ([#4059](markedjs/marked#4059)) The bundle is minified, so its diff reads as one reflowed line; the header comment moving from `marked v18.0.10` to `marked v18.0.11` is the readable part. </details> Co-authored-by: leaf-agent <318509791+leaf-agent@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
18.0.10, currentmainat e250e31Markdown flavor: CommonMark|GitHub Flavored Markdown
Description
No issue for this one. It is what is left of the group I listed in #4050 after #4051 landed: the tokenizer now refuses to nest a link inside a link, but the mask that
emStrongreads was not told, so it still treats the rejected candidate as a link and hides every emphasis marker inside it.Expectation
commonmark0.31.2, already a dev dependency here, returns exactly that.Result
The asterisks are printed as text. The reference link and the inner link are both right, only the emphasis is gone. Same with
_, with**, and when the inner link is a reference link instead of an inline one, which is CommonMark example 533.The trigger is narrow but it is ordinary prose: a reference link whose text happens to hold another link. Nothing warns the author, the markers just disappear from the output.
What was attempted
inlineTokensmasks a reference link candidate by replacing the whole span with[aaaa...], soemStrongcannot pair a delimiter outside a link with one inside it. That is the right call when the candidate really is a link, because the link text is tokenized separately.When the text already holds a link the candidate is not a link, #4051 made
outputLinksay so, and the span goes back through the loop as ordinary text. The mask built before the loop still reads[aaaa...]there, so the*never reachesemStrong.The mask now follows the same rule the tokenizer follows. A candidate whose text holds a link keeps its brackets and its emphasis markers visible, and the links inside it are masked instead. Images are left on the old path, since an image may hold a link.
linkInTextanswers the question. It returns ontext.includes('[')before touching a regex, so text without brackets costs nothing, and it skips images in both directions: an image inside link text does not disqualify the outer candidate, and an image candidate is never disqualified by what it holds.I first tried rebuilding the mask from the lexer loop whenever a candidate was rejected. It is a smaller diff and it reads better, but it is quadratic in the number of rejections in one inline run, and a paragraph with 400 of them went from 10.1 ms to 44.6 ms. Given #4040 and #4048 are open on this very block, that seemed like the wrong thing to hand you.
Scope
Fixes CommonMark example 533.
shouldFailcleared intest/specs/commonmark/and intest/specs/gfm/, Links goes from 80 to 81 of 90.512, 520 and 528 are still failing and are not touched here. They share a title with 533 in my grouping but not a cause: they need
_inlineLabelto match more than one level of nested brackets, which is a different change.Measurements
Differential run over 317 inputs, combinations of brackets, emphasis, inline links, reference links, images and code spans, plus every file in
test/specs/new, in both flavors, against the bundledcommonmark:<img ...>against<img ... />Timing on Node 22.20.0, best of five runs:
npm testis green: 1785 spec tests, 191 unit tests, plus umd, cjs, types and lint.Contributor