Markup round-trip drops fence language in "``` bash", trailing "\#" in headings, and "\|" inside inline code in table cells

オープン 初心者向け
#1,452 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, markdown, typescript
領域
frontend

調査の方向性

issue が挙げている 3 箇所から始めてください: CodeBlockSpecs/index.ts (split の前に fence info string を trim する)、HeadingSpecs/utils.ts (headingToMarkdown は末尾の # をエスケープする必要がある)、CodeSpecs (テーブルセル内のインラインコード内の | をエスケープする)。提供された repro.js をパッケージに対して実行し、保存された各文字列が破損したドキュメントへ再パースされるのを確認してください。完了とは、3 つの round-trip ケースすべてがコードブロックの言語、見出しの末尾ハッシュ、テーブルセルを保持していることを意味します。

索引モデルが issue の本文から書いたものです。

説明

Parsing Markdown into the WYSIWYG document and serializing it back (markupParser.parse -> serializer.serialize, used when opening Markdown in the default WYSIWYG mode and saving or switching to Markup mode) corrupts the document in three cases:

  1. A fenced code block with leading whitespace in its info string (``` bash) loses its language ("bash" becomes "").
  2. A heading ending in whitespace and an escaped hash (# not heading \#) is serialized without the backslash (# not heading #), so the trailing # is stripped as a closing ATX sequence on the next parse.
  3. Inline code containing \| inside a table cell (| `x \| y` | z |) is serialized with an unescaped pipe (|`x | y`|z|), so the next parse splits the cell at | and drops trailing cells.

Playground (opens in WYSIWYG mode; switch to Markdown markup via the gear menu to see the serialized output, then back to WYSIWYG to see the re-parsed document):
https://preview.gravity-ui.com/md-editor/?path=%2Fstory%2Fplayground--story&markup=lz%3AAYgECMEMGcAsCgB2AHAtqAlqAHvEx54BiURAewBdRYBTSAEw0QHNQAdIwgH1ElB-D94XAFwBaCaIliuw0MGzseAT2D9QAL35A

Reproduction (repro.js):

const {ExtensionsManager} = require('@gravity-ui/markdown-editor/core');
const {
  BaseSchemaSpecs,
  CodeSpecs,
  CodeBlockSpecs,
  HeadingSpecs,
  TableSpecs,
} = require('@gravity-ui/markdown-editor/specs');

const {markupParser, serializer} = new ExtensionsManager({
  extensions: (b) =>
    b
      .use(BaseSchemaSpecs, {})
      .use(CodeSpecs)
      .use(CodeBlockSpecs, {})
      .use(HeadingSpecs, {})
      .use(TableSpecs),
}).buildDeps();

for (const md of [
  '``` bash\nnpm i x\n```',
  '# not heading \\#',
  '| a | b |\n|:---|:---|\n| `x \\| y` | z |',
]) {
  const doc1 = markupParser.parse(md);
  const saved = serializer.serialize(doc1);
  const doc2 = markupParser.parse(saved);
  console.log('saved:', JSON.stringify(saved));
  console.log('doc1 :', doc1.toString(), JSON.stringify(doc1.firstChild.attrs));
  console.log('doc2 :', doc2.toString());
  console.log('---');
}

Run:

npm init -y && npm i @gravity-ui/[email protected] && node repro.js

Actual output:

saved: "```\nnpm i x\n```"
doc1 : doc(code_block("npm i x")) {"data-language":"","data-markup":"```","data-line":null}
doc2 : doc(code_block("npm i x"))
---
saved: "# not heading #"
doc1 : doc(heading("not heading #")) {"level":1,"data-line":null}
doc2 : doc(heading("not heading"))
---
saved: "\n|a|b|\n|:---|:---|\n|`x | y`|z|\n"
doc1 : doc(table(thead(tr(th("a"), th("b"))), tbody(tr(td(code("x | y")), td("z"))))) {}
doc2 : doc(table(thead(tr(th("a"), th("b"))), tbody(tr(td("`x"), td("y`")))))
---

Expected output:

  • Case 1 keeps "data-language": "bash" on doc1 and serializes as "```bash\nnpm i x\n```".
  • Case 2 escapes the trailing # so doc2 stays doc(heading("not heading #")).
  • Case 3 keeps | escaped as \| inside inline code in table cells (per https://github.github.com/gfm/#tables-extension-) so doc2 stays doc(table(thead(tr(th("a"), th("b"))), tbody(tr(td(code("x | y")), td("z"))))).

In CodeBlockSpecs/index.ts, tok.info.split(/\s+/) runs without .trim() first (unlike markdown-it's fence renderer); in HeadingSpecs/utils.ts, headingToMarkdown only escapes hash-only headings (/^#+[ \t\r\n]*$/); and CodeSpecs sets escape: false without escaping | when inside a table cell.

Versions tested: @gravity-ui/[email protected] (npm latest) and main (b633420) on Node.js v26.13.0.

Credit: https://ucsbplse.github.io/

主要言語
TypeScript
スター
428
フォーク
48
平均マージ
5日 15時間
マージ済み PR(30日)
47

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

gravity-ui/markdown-editor のほかの issue

gravity-ui/markdown-editor の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。