Skip to content

Port upstream code fence info string model#70

Merged
Renakoni merged 1 commit into
mainfrom
sync/upstream-4856-code-fence-info-source
Jul 10, 2026
Merged

Port upstream code fence info string model#70
Renakoni merged 1 commit into
mainfrom
sync/upstream-4856-code-fence-info-source

Conversation

@Renakoni

@Renakoni Renakoni commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Upstream

Ports marktext/marktext#4856: marktext/marktext#4856

This is stacked on #69 (sync/upstream-4861-prism-dependency-order) because the new live Muya tests import the editor Prism path, and Android main still has the pre-#4861 Prism dynamic import issue that causes unrelated latex / yaml module resolution errors under Vitest.

Android relevance

Android uses Muya for the WebView editor, including fenced code block parsing, live language input editing, serialization, and Prism highlighting. The upstream bug affects mobile editor behavior directly:

  • ```js title="app.js" is currently reduced to js in the model.
  • Editing the language input truncates at the first whitespace and drops attributes.
  • Using the whole info string as a CSS language-* token can crash or produce invalid class handling unless highlighting derives only the first word.

Changes

  • Treat meta.lang as the full fenced code info string, matching CommonMark's model.
  • Add firstWordOfInfo() and use it where the actual syntax-highlight language is needed.
  • Load Prism from the derived first word, not from the full info string.
  • Render/highlight code blocks using the derived language token so attributes do not leak into language-* classes.
  • Let the language input edit and persist the whole info string instead of truncating it.
  • Keep markdown serialization emitting meta.lang verbatim.
  • Add focused regression coverage for parser model, helper behavior, live code-block rendering, and language-input editing.

Verification

  • pnpm --dir third_party/muya exec vitest run src/utils/__tests__/firstWordOfInfo.spec.ts src/state/__tests__/infoStringModel.spec.ts src/block/content/codeBlockContent/__tests__/infoStringHighlight.spec.ts src/block/content/langInputContent/__tests__/editInfoString.spec.ts src/state/__tests__/blockSerialization.spec.ts
  • pnpm build

@Renakoni Renakoni force-pushed the sync/upstream-4861-prism-dependency-order branch from 1ade516 to 4ae69c7 Compare July 10, 2026 02:45
Base automatically changed from sync/upstream-4861-prism-dependency-order to main July 10, 2026 02:58
@Renakoni Renakoni force-pushed the sync/upstream-4856-code-fence-info-source branch from 192be0c to 2d49a16 Compare July 10, 2026 03:05
@Renakoni

Copy link
Copy Markdown
Owner Author

Reviewed for the Android client: relevant (live fenced-code parsing, language-input editing, highlighting) and the port itself is faithful to upstream #4856 — meta.lang becomes the verbatim info string, firstWordOfInfo() derives the highlight language at the Prism-load and language-* class sites, and the lang input stops truncating attributes on edit.

Two problems needed fixing before this could land:

  1. The branch was stacked on the pre-fix Port upstream Prism dependency order fix #69 commit. Its history carried the original sync/upstream-4861 commit whose glob change broke app-context Prism loading (fixed before Port upstream Prism dependency order fix #69 merged). Rebased with --onto so only the info-string commit replays on current main — a plain rebase would have resurrected the broken glob.
  2. Head-on collision with the already-merged Port upstream code fence info string fix #68 (upstream #4770). Main had the interim model (lang = first word + separate meta.info with a staleness guard); this PR implements the upstream model (lang = whole info string). The rebase applied "cleanly" but produced a duplicate const info declaration (compile error) and left both mechanisms half-alive. Reconciled toward the upstream model, which is the right long-term shape for a fork that keeps porting upstream code-block changes: removed meta.info, its serializer guard, and its type field; kept #4770's four round-trip regressions (they now validate the new model — coverage continuity); dropped only the stale-info guard test, whose failure mode is impossible once there is a single source of truth.

Also audited every remaining meta.lang consumer under the full-string model: the OT language-input sync stores the verbatim string (intended), highlighting and Prism loading go through firstWordOfInfo/alias resolution before touching language-* classes, diagram detection matches on the first word, and the frontmatter serializer switch operates on frontmatter langs, not fence info strings.

Verified: info-string spec battery 41/41 (including the updated #4770 spec), Muya gate 207 files / 1406 green, markdown rendering + editing E2E 9/9 (fenced code, math, Mermaid detection under the new model), app unit 258, production build green.

@Renakoni Renakoni merged commit 06b6dc1 into main Jul 10, 2026
5 checks passed
@Renakoni Renakoni deleted the sync/upstream-4856-code-fence-info-source branch July 10, 2026 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant