Repository navigation
Parsing errors and content lost when saving Markdown #525
Description
These examples show parsing errors and content lost when Comark saves Markdown. Reproduced on Comark 0.8.1 and main at b17f456.
Keep a case unchecked until its fix is merged and verified. Each linked PR is a proposed fix; cases without a fix link have no matching open PR found. Playground links use the preview from #526. Open the Formatted tab to see what changes when the Markdown is saved.
Markdown loses content when saved
References: GFM task lists and CommonMark fenced code blocks. Cases 2–4 concern Comark components.
- 1. Task items with nested blocks lose their text and indent following blocks as code. playground · Fix: #527 (open)
- 2.
::table{src="data.csv"}is saved as an empty table. playground · Fix: #527 (open) - 3.
:comment[a note]disappears. playground · Fix: #527 (open) - 4.
:math[x]becomes$x$instead of staying a component. playground · Fix: #527 (open) - 5. Fenced code loses trailing blank lines and spaces. playground · Fix: #527 (open)
Text moves out of HTML tags
Also reported in #505. Reference: CommonMark raw HTML.
- 6. Raw
<details>inside::tabs-itemloses its nesting and content. Also tracked in Inline HTML inside a block component loses its content (0.8) #505. playground · Fix: #506 (open) - 7. Text moves outside its HTML tag when that tag is inside emphasis, a link, or a heading. playground · Fix: #506 (open)
HTML parsing
References: CommonMark raw HTML, HTML blocks, soft line breaks, and browser HTML tree construction. For malformed HTML, the expected output follows how browsers parse it.
- 8. Newlines inside HTML disappear, joining words and script lines. playground
- 9. An HTML block with JSX-style attributes, such as
<div style={{a: 1}}>, becomes literal text instead of remaining HTML. playground · Fix: #530 (open) - 10. An HTML tag left open inside a paragraph swallows later blocks. playground · Fix: #530 (open)
- 11.
</br>disappears instead of producing the line break browsers give it. playground · Fix: #530 (open) - 12. A second
<p>nests inside the first instead of closing it. playground · Fix: #530 (open) - 13. Images,
<br>, and custom elements inside HTML split or lose their paragraph. playground · Fix: #530 (open) - 14. An HTML tag left open in a list changes the text order and adds a
<fragment>element. playground · Fix: #530 (open) - 15. Standalone HTML comments gain a
<p>wrapper. Comark also fails to recognize<!--- --->as a comment. playground · Fix: #530 (open) - 16. Raw
<pre><code>content renders its tags and entities literally. playground · Fix: #530 (open) - 17.
autoUnwrapremoves a<p>written by the author and moves its attributes onto the parent. playground · Fix: #530 (open) - 18. Duplicate HTML attributes keep the last value rather than the first. playground · Fix: #530 (open)
- 19.
html({ markdown: false })leaves character references encoded in HTML text. · Fix: #530 (open)
Markdown structure and autolinks
References: CommonMark images, ATX headings, fenced code blocks, block quotes, list items, GFM tables, and GFM autolinks.
- 20. Decorative Markdown images lose
alt="". playground - 21. Empty ATX headings disappear. playground
- 22. A code block's language disappears when it is written as
{x}. playground - 23. Bare URLs and emails differ from GFM for
.devaddresses, underscores in hosts, non-numeric ports, emphasis around URLs, and percent-encoded link text. playground · example 2 · example 3 · example 4 - 24. markdown-exit parses some indented blockquote lines, code fences inside lists, and table rows inside list items differently from the spec. playground · example 2 · example 3
Comark attributes and frontmatter
CommonMark does not define these Comark extensions: attributes and frontmatter.
- 25. An unclosed attribute group, such as
a {b c, deletes the rest of the line. playground - 26.
--- xcloses frontmatter too early. A leading byte order mark stops Comark from finding frontmatter. playground · example 2 - 27. Invalid YAML frontmatter makes
parseMarkdownthrow. Report the invalid YAML without losing the document. playground
Callouts and footnotes
CommonMark does not define these extensions. References: GitHub alerts and Comark footnotes.
- 28.
> [!NOTE] TitlemovesTitleinto the body when saved. fix(stringify): fix renderMarkdown round-trip losses from #525 #527 leaves this out because the parser and renderers need to agree on how to store the title. playground - 29. Footnote definitions do not parse Markdown. The plugin also deletes definition-like lines inside code blocks and uses the last duplicate definition. playground · example 2 · example 3
Code changes when rendered, and large paragraphs crash
Reference: CommonMark fenced code blocks. Cases 30 and 31 need the API reproductions below.
- 30.
@comark/htmladds indentation inside nested code and escapes>in<style>/<script>, changing their content. - 31. A paragraph with many children throws
RangeError:parseMarkdown("https://x.com/a ".repeat(65536)).
Examples that need the API
Cases 30, 19, and 31
import { parseMarkdown } from "comark";
import { renderHtmlFromDocument } from "@comark/html";
import html from "comark/plugins/html";
// 30: Code indentation changes, and the CSS selector becomes a > b.
console.log(await renderHtmlFromDocument(await parseMarkdown(
"- x\n\n ```\n a\n b\n ```\n\n<style>\na > b {}\n</style>"
)));
// 19: Expected HTML text is "<b> & x", not "<b> & x".
console.log((await parseMarkdown("<div>\n<b> & x\n</div>", {
plugins: [html({ markdown: false })]
})).nodes);
// 31: RangeError: Maximum call stack size exceeded.
await parseMarkdown("https://x.com/a ".repeat(65536));
Activity
[-]renderMarkdown round trip drops or changes content: task items, components named table/comment/math, trailing blank lines, callout titles[/-][+]Markdown Comark gets wrong: renderMarkdown round-trip losses, and parsing differences from CommonMark/GFM[/+][-]Markdown Comark gets wrong: renderMarkdown round-trip losses, and parsing differences from CommonMark/GFM[/-][+]Track Comark parsing and Markdown round-trip cases by category and PR[/+][-]Track Comark parsing and Markdown round-trip cases by category and PR[/-][+]Parsing errors and content lost when saving Markdown[/+]