fix(comark): only complete unclosed frontmatter while streaming#269
fix(comark): only complete unclosed frontmatter while streaming#269sandros94 wants to merge 1 commit into
Conversation
|
@sandros94 is attempting to deploy a commit to the NuxtLabs Team on Vercel. A member of the Team first needs to authorize it. |
|
just to be clear, as I stated in the related issue #268 (comment): I'm not really satisfied with this approach, as it basically shifts the issue into another place (essentially the buggy situation happens at streaming rather than static content). I just wanted to open this PR to hope for inspiration, happy if it gets discarded/closed anyway |
|
Thanks @sandros94 for the Pr, But I'm thinking why we need to have thematic PR right at the beginning? Having an extra line before this hr will resolve the issue 🤔 |
True but this wont solve a broken frontmatter, potentially causing a it to throw. Also another thing that come to mind is that One such use case I'm thinking of is someone pasing a markdown string from clipboard that needs to be parsed into AST before injecting it into an editor. If at any level that string gets trimmed and do happens to start with |
🔗 Linked issue
Resolves #268
❓ Type of change
📚 Description
autoCloseMarkdowntreated any leading---as an unclosed frontmatter opener and appended a closing---. That completion only makes sense while streaming; applied to a complete document it caused two bugs:---→---\n---→ parsed as two thematic breaks (and nohrround-tripped, sincerenderMarkdownemits---).---\n<body>→---\n<body>\n---→ looked like valid frontmatter, soparseFrontmatterconsumed the body as YAML and dropped it — contradicting its own contract that an unclosed---stays content.Fix: gate frontmatter completion on
streaming.autoCloseMarkdowngains an optional{ streaming }argument (defaultfalse, backward-compatible — it has no other callers), threaded fromparseviaopts.streaming. A complete document now leaves a leading unclosed---alone, so the tokenizer reads it as a thematic break and keeps any following body; while streaming, partial frontmatter is still auto-completed exactly as before. A secondary non-empty guard means a lone---is never doubled, even mid-stream.Behavior
---[hr, hr][hr]---\n# Heading[](heading lost)[hr, h1]---\ntitle: x\n---\n\n# Body---\ntitle: xTests
---parses to a singlehr.---+ body stays a thematic break + body (swallow).frontmatter partialcases now assert streaming completion, plus new non-streaming cases asserting the body is preserved.📝 Checklist
pnpm verifyand it passes. (pre-existing issues)