LectureRechercheRadarCadre d'investissement
Connexion / Inscription
← Retour à la lecture
ActualitésSujet · ProseMirrorMatériel4 min de lectureRédaction DisconfirmAI

ProseMirror Product Developer: Under Tree-Based Document Architecture, Your Markdown Source Is Lost on the First Save

A developer with three years of experience building ProseMirror-based products argues, through a version-by-version review of mainstream Markdown conversion library source code, that when a JSON document tree is the source of truth and Markdown is merely its serialized output, the user's original writing is inevitably altered upon the first save. They propose an alternative approach where the Markdown source itself is authoritative, implemented via CodeMirror 6's decoration system for WYSIWYG editing, providing specific benchmark data on incremental parsing and explaining architectural differences in collaborative editing.

2026-10-29 11:29 GMT+8

A developer with three years of experience working on ProseMirror-related products published a long-form post on V2EX, reviewing the source code of mainstream Markdown conversion libraries version by version. They present an architectural judgment: when the authority of a document lies in its JSON tree and Markdown is merely one way to print it, the source code you wrote is already gone by the time you hit save for the first time.

They cite examples from the most commonly used implementations. prosemirror-markdown 1.13.4 hardcodes italics and bold as asterisks; underline emphasis you write changes after one save. Unordered lists default to asterisks, so your habit of using hyphens disappears. Ordered lists are renumbered, and line-ending double spaces for line breaks are uniformly changed to backslashes. If it encounters syntax it doesn't recognize, it throws an error; the default schema lacks tables, footnotes, and strikethrough. Tiptap's official @tiptap/markdown 3.30 similarly hardcodes bold and italic formatting. Nodes without corresponding renderers output empty strings, causing content to silently disappear. The community-maintained tiptap-markdown has ceased maintenance; when encountering nodes it cannot express, it outputs placeholders. Tables with merged cells degrade to HTML, losing column alignment information.

Connexion / Inscription
LectureRechercheRadarCadre d'investissement

The author emphasizes these are not bugs but inevitable results of the architecture. Since there is only one printing method, the source code you wrote is already gone upon the first save. This might not matter for personal note-taking, but it is critical for three scenarios: documents stored in Git show full-screen format changes even when modifying a single character; AI modifies only one section but normalizes the writing style of the entire document; the same file needs to be used across VS Code, static site generators, and other Markdown tools.

The author then tests the actual limitations of Markdown syntax itself. Using micromark 4.0.2 with GFM extensions, they tested item by item: table cells can only contain inline content; placing a list or code block inside will break the table immediately. Bold text cannot be nested within inline code, nor can links be nested within links. Chinese punctuation causes bolding to fail—CommonMark determines whether asterisks can start or end emphasis by checking if the surrounding characters are punctuation or whitespace. Chinese quotes and parentheses are punctuation, followed immediately by Han characters, so the rule deems them invalid. English writers rarely encounter this issue, but Chinese writers face it daily.

The author's solution is MSFE (Markdown Source-First Editor), making the Markdown source itself authoritative. Complex blocks store data within code fences, rendering as editable multi-dimensional tables within MSFE, while appearing as plain code segments in GitHub or VS Code that do not break or get lost. Collaborative editing operates on the Markdown source itself—a single Yjs text object. Since any segment of text is valid Markdown, there is no issue of deleting nodes due to structural invalidity.

They implement WYSIWYG using CodeMirror 6 decorations and widgets: headings appear larger, markup symbols are hidden, tables are drawn as tables, and formulas are rendered as formulas, while the underlying text remains unchanged. Three views—the document view, live preview, and source view—are different presentations on the same CodeMirror instance. Switching between them requires no conversion, preserving selection ranges and undo history.

Regarding performance, they provide proof of reuse for Lezer's Markdown incremental parsing. The parser records which intervals are reused verbatim, allowing the editor to skip unchanged parts. For a 1 MiB document with continuous input over 20 iterations, syntax tree visits dropped from 107,760 to 1,380 (a 98.7% reduction); syntax tree comparisons dropped from 153,940 to 660 (a 99.6% reduction). Where proofs fail, the system falls back to full comparison, ensuring correctness is unaffected.

The author explicitly acknowledges the costs of source-first approaches: every input requires updating the syntax tree, making large files slow. MSFE is currently in alpha, and its API is subject to change. The open-source portion is licensed under MIT; commercial components include AI document reading/writing, displaying changes and annotations in a 'pending review' format. They also promote the QuireKit editor ecosystem, including Classic, a page-based document editor based on ProseMirror.

Notable boundaries exist: these performance figures are self-reported benchmarks. The portability of the code fence solution for complex blocks—i.e., whether other Markdown tools can recognize and edit structured data within fences—has not been verified by third parties. The author's core argument (that tree-based authority leads to source loss) is built on reading specific library versions' source code and is verifiable; however, the long-term maintenance costs and ecosystem compatibility of the alternative solution remain open questions.

Sources

  • v2ex.comV2EX↗
Sujet

ProseMirror

ProseMirror 作为富文本编辑器框架,其核心架构将文档视为 JSON 树,Markdown 仅作为序列化输出格式。这一设计导致用户在编辑时保留的原始 Markdown 语法(如列表符号、强调标记)在保存时会被“规范化”改写,造成源码…

4 étapes1 piècesMis à jour 2026-10-30 14:29

Comment on en est arrivé là

  1. 2015-11-09ProseMirror 创始人 Marijn Haverbeke 在社区论坛确认,当前 Markdown 转换是有损的,会丢失缩进、换行和列表标记等细节,且无损序列化是一个尚未完成的大工程。discuss.prosemirror.net ↗
  2. 2025-04-30开发者在 ProseMirror 论坛提问如何解决 Tiptap 中空段落被 Markdown 序列化器剥离的问题,Marijn 回复称 CommonMark 本身不支持表达空段落,建议通过语义化节点而非空白字符控制布局。discuss.prosemirror.net ↗
  3. 2025-01-17一位 Electron 应用开发者询问如何将 ProseMirror 事务映射回纯文本偏移量以保留原始 Markdown 语法(如代码块围栏类型),Marijn 指出这需要极其复杂的逻辑或自定义序列化器,因为 Markdown 标记插入位置规则复杂。discuss.prosemirror.net ↗

Ce qui reste non résolu

  • 是否存在成熟的开源方案能在不修改 ProseMirror 核心模型的前提下实现 Markdown 源码的无损往返?
  • 主流笔记软件(如 Notion, Obsidian)如何在用户体验层面掩盖或处理这种序列化带来的格式差异?
  • 随着 AI 代理直接读写 Markdown 文件的普及,这种基于树的编辑器架构是否会成为阻碍自动化工作流的主要瓶颈?
Lire le sujet complet →
Continuer la recherche →