Repository navigation
feat(muya): preserve ATX and Setext heading source forms - #5878
Conversation
Jocs
left a comment
There was a problem hiding this comment.
I reviewed commit 66728a6f against base 3fcb5ce8, including the parser/serializer boundary, Block projection, transaction completion, creation paths, undo/redo coverage, and cursor APIs.
Recommendation: address the five inline findings before merging. Two are P1 issues (a document-loading exception and code corruption after export/reimport); three are P2 regressions involving language decoding and cursor mapping.
The overall direction is reasonable: separating source forms from semantic metadata, sharing ownership/cloning in SyntaxBlock, and recording required syntax corrections in the same transaction/history entry are useful foundations. Property-level correction operations also reduce interference between unrelated OT edits. However, the separation is incomplete: the lexer, source-form parser, and transaction repair rules each implement part of the Markdown grammar. The parser mismatch and info-string regression illustrate the maintenance risk. Semantic parsing should remain authoritative, while source-form extraction records spelling and transaction repair maintains explicit serialization invariants.
Additional coverage gaps:
- Interactive fence creation still discards source forms. With
preserveSyntax: true, entering~~~~~ jsand pressing Enter produces~~~jsfollowed by a three-tilde closing fence.ParagraphContentusesdefaultCodeSyntaxinstead of extracting the typed fence length and padding. The language-selector creation path should be checked as well. This is a feature-coverage gap, rather than a claim that the old behavior newly regressed. packages/muya/examples/src/data.tsstill documents the old state schema: headings lacksyntax, Setext headings usemeta.underline, and code blocks usemeta.type. These in-repository construction examples should migrate with the schema; this does not require a legacy-state compatibility layer.
Validation: the existing 3,022 unit tests and the 1,347 CommonMark/GFM baseline cases pass locally. Eight additional assertions reproduce the five inline findings. The conformance suite exercises the static HTML renderer, so it does not validate the new state parser/serializer path. Add semantic round-trip checks after editing (parse(print(editedState)) preserves block types, content, and semantic metadata), alongside source-string equality and Block/JSON-state consistency. Include empty-to-nonempty lines, insufficient prefixes, partially expanded tabs, escaped info strings, interactive creation, and cursor APIs. I did not rerun browser E2E tests.
Desktop default integration, external block gaps, EOF/EOL preservation, and other source-form families are explicitly deferred by this PR and are not counted as missing scope here.
Jocs
left a comment
There was a problem hiding this comment.
I found two P2 regressions that I recommend addressing before merge; see the inline comments.
Validation was run on 5981b909: all 3,013 existing unit tests passed after adjusting Vite's file-access setting for the isolated checkout. Focused regression tests reproduced both findings, and the caret-conversion test passes on the PR base. Browser E2E tests were not rerun.
I also checked the subsequent change in 7836af52; it only removes the Setext parsing fallback and does not change either affected path.
Brings in v0.22.0 and v0.23.0 and the start of 0.24.0: Electron 45, GitHub Alerts, foldable headings, per-tab reading mode and --read-only, the docked document outline, multiple folder roots, preview tabs, recent files in quick open, Italian, and the large-document fixes of marktext#4942 and marktext#5863. Conflicts: - muya state/inlineRenderer: marktext#4942 caches reference definitions per candidate state, which supersedes the fork's per-revision cache. Took upstream's; the fork's display math cache in mathPreview stays. - editor.vue: kept the fork's deferred content snapshot (no getState() deep clone per keystroke), document virtualization and camera, on top of upstream's reading mode, shortcut resolvers and image drop. The json-change handler keeps upstream's loadingContent/readOnly guard, the source handoff and reload take upstream's loadingContent blocks, and scrollToHeader reveals folded headings before following the target. publishContentChange uses getSelectionState(). - Print/PDF: the fork's paged preview replaces MarkdownPrint and the printToPDF export path, so printService, its specs and the pdf branch of handleResponseForExport keep the fork's side. marktext#3323 moved image resolution into the engine; exportHtml drops its own image rewrite and keeps the fork's rendered-heading TOC. - marktext#5802's assertExportDestination moves to main/filesystem so Save PDF in the preview refuses the source document too. - syntheticHistory keeps the 53-bit cyrb53 hash over upstream's BigInt FNV-64 (~6 ms per key on a 500 KB note); the store keeps isSameList and drops deep-equal. - Sidebar rows keep draggable alongside preview tabs; locales keep both printPreview and readingMode, and it.json gets the printPreview strings. Merge adjustments: - SET_READ_ONLY publishes the pending snapshot first: a read-only tab drops content changes, so an edit made within 150 ms of entering reading mode would otherwise be missing from the tab. - marktext#5798 moved notices to the bottom-right corner, over the preview's Save PDF and Print buttons, and an export notice stays while hovered. The preview lifts notices clear of its actions while it is open. - Specs: the docked outline is expanded by default and narrows the column, so the virtualization specs open it only when it is closed, measure the settled position and place their target inside the viewport. The camera specs press Control once before measuring, because since marktext#5878 the first key press re-renders the caret's heading with its marks shown. Verified on Windows 11 (175%): typecheck, lint, the desktop unit suite (1467) and the muya unit suite (3978) pass. In background windows the e2e suite (514 passed, 45 failed) fails only where a build of upstream/develop fails on this machine too (copy-anchor-link, document-outline, image clipboard/relative path, 5394, 5685, toc-active-heading, outline-layout, ...: 56 cases in 19 specs there), plus media-viewer cases that flake on both when the 1 px image's resize bar takes the click. print-preview, export-pdf, document-virtualization and sidebar-file-drag pass, and editor-camera passes on screen. reading-mode:54 needs the camera focus fix in the next commit.
Refs #2189. Based on the merged edit-transaction refactor #5872.
Result
Opening and saving headings currently normalizes source spacing and delimiters. Preserve ATX and Setext heading forms by default: editing
## title ###emits## changed ###.This PR is limited to headings. Earlier code-block and other syntax-preservation changes are withdrawn.
Design
textowns the complete editable source line, including indentation, separators, closing hashes and trailing whitespace.meta.levelretains its semantic role; no ATX syntax/body copy.textowns the original body lines and prefixes. Move the complete underline line frommeta.underlineintosyntax.underline; no prefixes array or legacy-state migration layer.All changes are inside
packages/muya. No source buffer, persistent source-offset map, syntax-repair transaction rule or opt-in preservation flag. Block gaps, file-boundary blank lines and EOL bytes remain outside this PR's fidelity guarantee; container marker spelling is unchanged.Validation
Latest follow-up:
9c98b814.git diff --check: passed, existing warnings only. GitHub checks are running for the latest revision.A local full run reused a Vite server that was exiting and failed with connection-refused errors. A fresh, independently owned test server passed the full suite without changing repository test configuration, timeouts or assertions.
9c98b814fixes the four subsequent review regressions: keep a separate list-marker line when the first heading has indentation; share body-bounded formatting across single/multiple blocks; shift non-ATX source selections by the actual inserted prefix; stop block-prefix parsing before interpreting heading body text as a reference definition. Twelve unit and ten browser regressions cover the reported examples and their adjacent cases. Final local validation: unit 3,041, spec 1,347, Chromium 591 passed / 3 existing skips; lint/types/circular checks passed. Fresh CI checks are running for this revision.