Markup round-trip drops fence language in "``` bash", trailing "\#" in headings, and "\|" inside inline code in table cells
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 74/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, markdown, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Bắt đầu từ ba vị trí mà issue nêu tên: CodeBlockSpecs/index.ts (cắt tỉa fence info string trước split), HeadingSpecs/utils.ts (headingToMarkdown phải escape một # ở cuối), và CodeSpecs (escape | bên trong inline code trong ô bảng). Chạy repro.js được cung cấp với package để thấy từng chuỗi đã lưu được parse lại thành tài liệu bị hỏng. Hoàn thành nghĩa là cả ba trường hợp round-trip giữ nguyên ngôn ngữ của code block, hash ở cuối heading và các ô bảng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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:
- A fenced code block with leading whitespace in its info string (
``` bash) loses its language ("bash"becomes""). - 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. - 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"ondoc1and serializes as"```bash\nnpm i x\n```". - Case 2 escapes the trailing
#sodoc2staysdoc(heading("not heading #")). - Case 3 keeps
|escaped as\|inside inline code in table cells (per https://github.github.com/gfm/#tables-extension-) sodoc2staysdoc(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/
- Ngôn ngữ chính
- TypeScript
- Star
- 428
- Fork
- 48
- Merge trung bình
- 5 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 47
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của gravity-ui/markdown-editor
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
gravity-ui/markdown-editor#1293 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Markup mode: `colorify` does not detect existing `{color}(...)` wrapper when switching colorsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
gravity-ui/markdown-editor#1129 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
gravity-ui/markdown-editor#1450 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
gravity-ui/markdown-editor#1331 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Shared `slotsTokenizer` for directive blocksCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
gravity-ui/markdown-editor#1301 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của gravity-ui/markdown-editor
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
software-mansion/argent#1946 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
podman-desktop/podman-desktop#20216 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Type] Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
WordPress/ai#1386 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 5 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
omdsh-dev/DSH-better-sidebar#1205 ·
Maintainer thường phản hồi trong vòng 3 ngày