Skip to content

Parsing errors and content lost when saving Markdown #525

Open

Description

@onmax

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.

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. autoUnwrap removes 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 .dev addresses, 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. --- x closes frontmatter too early. A leading byte order mark stops Comark from finding frontmatter. playground · example 2
  • 27. Invalid YAML frontmatter makes parseMarkdown throw. Report the invalid YAML without losing the document. playground

Callouts and footnotes

CommonMark does not define these extensions. References: GitHub alerts and Comark footnotes.

Code changes when rendered, and large paragraphs crash

Reference: CommonMark fenced code blocks. Cases 30 and 31 need the API reproductions below.

  • 30. @comark/html adds 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 &gt; 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 "&lt;b&gt; &amp; x".
console.log((await parseMarkdown("<div>\n&lt;b&gt; &amp; x\n</div>", {
  plugins: [html({ markdown: false })]
})).nodes);

// 31: RangeError: Maximum call stack size exceeded.
await parseMarkdown("https://x.com/a ".repeat(65536));

Runnable checks for all cases.

Activity

  1. changed the title [-]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[/+] on Oct 31, 2026
  2. changed the title [-]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[/+] on Nov 1, 2026
  3. changed the title [-]Track Comark parsing and Markdown round-trip cases by category and PR[/-] [+]Parsing errors and content lost when saving Markdown[/+] on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions