Skip to content

[lexical-markdown] Bug Fix: code spans should bind tighter than text-match transformers#8688

Merged
etrepum merged 1 commit into
facebook:mainfrom
etrepum:claude/jolly-hamilton-922inp
Jun 12, 2026
Merged

[lexical-markdown] Bug Fix: code spans should bind tighter than text-match transformers#8688
etrepum merged 1 commit into
facebook:mainfrom
etrepum:claude/jolly-hamilton-922inp

Conversation

@etrepum

@etrepum etrepum commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Description

Inline code (code) has the highest inline parsing precedence in Markdown and must never be partially consumed by a text-match transformer. When a code-format match and a text-match (e.g. the playground equation $...$ or a link) partially overlapped, the importer incorrectly applied the text match. For example `$a` `$b` parsed into a single equation instead of two code spans.

Prefer the code format whenever it conflicts with a text match, unless the text match fully wraps the code span (in which case the backticks are part of the match's raw content).

Closes #8687

Test plan

New unit tests

…match transformers

Inline code (`code`) has the highest inline parsing precedence in Markdown
and must never be partially consumed by a text-match transformer. When a
code-format match and a text-match (e.g. the playground equation `$...$` or
a link) partially overlapped, the importer incorrectly applied the text
match. For example `` `$a` `$b` `` parsed into a single equation instead of
two code spans.

findOutermostTextFormatTransformer now tags its result with isCodeSpan
(true by transformer identity when the chosen match is the code span), so
the reconciliation in importTextTransformers can deterministically prefer
the code format whenever it conflicts with a text match, unless the text
match fully wraps the code span (in which case the backticks are part of
the match's raw content).

Fixes facebook#8687

https://claude.ai/code/session_01KMePdiz855Y9DYP7BPeDcg
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 12, 2026
@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Jun 12, 2026 5:57pm
lexical-playground Ready Ready Preview, Comment Jun 12, 2026 5:57pm

Request Review

@potatowagon potatowagon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed by Navi (Tater Thoughts Bobblehead) on behalf of @potatowagon.

LGTM

What this does: Fixes code spans (\...`) binding tighter than text-match transformers (e.g. equation $...$) during markdown import. Previously, `$a` `$b`` could be incorrectly consumed by the equation text-match transformer spanning across the code spans.

What I checked:

  1. Logic correctness: The fix correctly tags isCodeSpan from findOutermostTextFormatTransformer by identity-comparing against codeTransformer. In importTextTransformers, when both a text-format and text-match are found and the format is a code span, it checks whether the text-match fully wraps the code span (in which case the text-match wins) or not (code span wins). This implements the correct precedence per CommonMark spec where code spans bind tighter.

  2. Edge cases: The wrapping condition (startIndex <= ... && endIndex >= ...) correctly handles the case where a text-match legitimately contains code span syntax as raw content. The else branch (code span wins) properly nullifies foundTextMatch so processing continues normally.

  3. Test coverage: New test case \$a` `$b`` directly exercises the bug from #8687. Round-trip test validates both import and export.

  4. No regressions: Existing test for \$$hello`still passes (code span containing equation-like text). No API changes, no new exports. TheisCodeSpan` field is internal to the markdown import pipeline.

  5. www compat: No removed/renamed exports, no changed function signatures. Safe for Meta internal consumers.

CI: Core tests all green (unit 22.x+24.x, browser all platforms, integrity, integration, e2e canary chromium). Some platform e2e tests still pending but unrelated to this change.

Ready to approve.

@etrepum etrepum added this pull request to the merge queue Jun 12, 2026
Merged via the queue into facebook:main with commit d4ad0f1 Jun 12, 2026
54 checks passed
@etrepum etrepum mentioned this pull request Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

4 participants