diff --git a/AGENTS.md b/AGENTS.md
index 41ee89014..a03b6e4c7 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -285,6 +285,7 @@ Every renderer accepts `transformNode` (a function or array of functions returni
## Parser and plugin rules
1. Token-to-AST conversion lives in `packages/comark/src/internal/parse/tree.ts`. Run spec fixtures with `cd packages/comark && pnpm vitest run test/index.test.ts` (or `SPEC=SPEC/COMARK/foo.md pnpm vitest run test/index.test.ts`), and check `test/streaming.test.ts` after parser edits.
+ A fixture has `## Input`, `## AST`, `## HTML` and `## Markdown` sections, plus an optional `## Markdown HTML` for `renderMarkdown(doc, { format: 'markdown/html' })`. Every fixture runs the `markdown/html` check; when the section is missing, it falls back to `## Markdown`. Add the section only when the output differs (components, spans, slots, `:br`).
2. Always import from `markdown-exit/core`, never `markdown-exit`. Only `src/plugins/linkify.ts` imports `linkify-it`, keeping `comark/core` free of `linkify-it` and avoiding `markdown-exit`'s global fuzzy-link rule.
3. Decode HTML entities in attributes with `decodeHTMLAttribute` from `src/internal/entities.ts`, never `entities`, so bundles reuse the single `character-entities` table shipped by `markdown-exit`.
4. After adding or renaming a plugin in `packages/comark/src/plugins/`, add framework wrappers if it has a UI component, then run `pnpm sync-plugins` (also run by `pnpm build` and `pnpm stub`).
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index b385ae522..013d6a9ab 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -74,7 +74,7 @@ cd packages/comark
pnpm vitest run test/parse/sub-sup.test.ts
```
-Parser fixtures live in `packages/comark/SPEC` and run through `test/index.test.ts`. Parser changes should also preserve streaming behavior in `test/streaming.test.ts`.
+Parser fixtures live in `packages/comark/SPEC` and run through `test/index.test.ts`. Each fixture also checks `markdown/html` output against its `## Markdown HTML` section, or against `## Markdown` when that section is missing. Parser changes should also preserve streaming behavior in `test/streaming.test.ts`.
React and Svelte tests include a headless Chromium project. Install the browser if needed:
diff --git a/packages/comark/SPEC/COMARK/attribute-inline-component.md b/packages/comark/SPEC/COMARK/attribute-inline-component.md
index 978a6d963..24673eec9 100644
--- a/packages/comark/SPEC/COMARK/attribute-inline-component.md
+++ b/packages/comark/SPEC/COMARK/attribute-inline-component.md
@@ -60,3 +60,9 @@ Here :in{bool} :in{#id1} :in{.class1} :in{attr="value"}
```md
Here :in{bool} :in{#id1} :in{.class1} :in{attr="value"}
```
+
+## Markdown HTML
+
+```md
+Here
+```
diff --git a/packages/comark/SPEC/COMARK/attribute-span-multiple-classes.md b/packages/comark/SPEC/COMARK/attribute-span-multiple-classes.md
index 3a50b2456..285084fd4 100644
--- a/packages/comark/SPEC/COMARK/attribute-span-multiple-classes.md
+++ b/packages/comark/SPEC/COMARK/attribute-span-multiple-classes.md
@@ -38,3 +38,9 @@ Welcome to [site]{.bg-gradient-to-r.from-primary-600.to-purple-600.bg-clip-text.
```md
Welcome to [site]{.bg-gradient-to-r.from-primary-600.to-purple-600.bg-clip-text.text-transparent}
```
+
+## Markdown HTML
+
+```md
+Welcome to site
+```
diff --git a/packages/comark/SPEC/COMARK/attribute-span-tailwind-class.md b/packages/comark/SPEC/COMARK/attribute-span-tailwind-class.md
index c2cfc9e74..557fa3722 100644
--- a/packages/comark/SPEC/COMARK/attribute-span-tailwind-class.md
+++ b/packages/comark/SPEC/COMARK/attribute-span-tailwind-class.md
@@ -72,3 +72,11 @@ Paint [swatch]{.bg-[#000]} and [box]{.text-[1.5rem]} and [el]{.w-[calc(100%-1rem
Theme [label]{.bg-[#000].text-[14px] #my-id}
```
+
+## Markdown HTML
+
+```md
+Paint swatch and box and el
+
+Theme label
+```
diff --git a/packages/comark/SPEC/COMARK/attribute-span.md b/packages/comark/SPEC/COMARK/attribute-span.md
index 0c14c8dda..641cf2d38 100644
--- a/packages/comark/SPEC/COMARK/attribute-span.md
+++ b/packages/comark/SPEC/COMARK/attribute-span.md
@@ -62,3 +62,9 @@ Here [link]{bool} [link]{#id1} [link]{.class1} [link]{attr="value"}
```md
Here [link]{bool} [link]{#id1} [link]{.class1} [link]{attr="value"}
```
+
+## Markdown HTML
+
+```md
+Here link link link link
+```
diff --git a/packages/comark/SPEC/COMARK/attributes/paragraph+span.md b/packages/comark/SPEC/COMARK/attributes/paragraph+span.md
index ea6a2170c..41eaf8f2d 100644
--- a/packages/comark/SPEC/COMARK/attributes/paragraph+span.md
+++ b/packages/comark/SPEC/COMARK/attributes/paragraph+span.md
@@ -55,3 +55,11 @@ A paragraph [span] {attr="value"}
A paragraph [span]{attr="value"}
```
+
+## Markdown HTML
+
+```md
+A paragraph span {attr="value"}
+
+A paragraph span
+```
diff --git a/packages/comark/SPEC/COMARK/codeblock-indented-content.md b/packages/comark/SPEC/COMARK/codeblock-indented-content.md
index cd2642e8a..96671a634 100644
--- a/packages/comark/SPEC/COMARK/codeblock-indented-content.md
+++ b/packages/comark/SPEC/COMARK/codeblock-indented-content.md
@@ -56,3 +56,16 @@
```
::
```
+
+## Markdown HTML
+
+```md
+
+
+```mdc
+ ::accordion
+ ::
+```
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-PascalCase.md b/packages/comark/SPEC/COMARK/component-PascalCase.md
index 715feccba..07b2ebcdd 100644
--- a/packages/comark/SPEC/COMARK/component-PascalCase.md
+++ b/packages/comark/SPEC/COMARK/component-PascalCase.md
@@ -51,3 +51,15 @@ First Paragraph
Second Paragraph
::
```
+
+## Markdown HTML
+
+```md
+
+
+First Paragraph
+
+Second Paragraph
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-block-in-list-item.md b/packages/comark/SPEC/COMARK/component-block-in-list-item.md
index 2814bb9bc..d19414d79 100644
--- a/packages/comark/SPEC/COMARK/component-block-in-list-item.md
+++ b/packages/comark/SPEC/COMARK/component-block-in-list-item.md
@@ -77,3 +77,19 @@
### Heading
::
```
+
+## Markdown HTML
+
+```md
+- *item one*
+
+
+
+
+
+ ### Heading
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-block-props-backtick.md b/packages/comark/SPEC/COMARK/component-block-props-backtick.md
index 64d03de7d..826da60c2 100644
--- a/packages/comark/SPEC/COMARK/component-block-props-backtick.md
+++ b/packages/comark/SPEC/COMARK/component-block-props-backtick.md
@@ -54,3 +54,13 @@ variant: soft
Content
::
```
+
+## Markdown HTML
+
+```md
+
+
+Content
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-block-props-tilde-with-code.md b/packages/comark/SPEC/COMARK/component-block-props-tilde-with-code.md
index bc5894ffc..73a31eb79 100644
--- a/packages/comark/SPEC/COMARK/component-block-props-tilde-with-code.md
+++ b/packages/comark/SPEC/COMARK/component-block-props-tilde-with-code.md
@@ -59,3 +59,13 @@ source: |-
Preview content here
::
```
+
+## Markdown HTML
+
+```md
+
+
+Preview content here
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-block-props-tilde.md b/packages/comark/SPEC/COMARK/component-block-props-tilde.md
index 9ebc1686d..3b18196f1 100644
--- a/packages/comark/SPEC/COMARK/component-block-props-tilde.md
+++ b/packages/comark/SPEC/COMARK/component-block-props-tilde.md
@@ -54,3 +54,13 @@ variant: soft
Content
::
```
+
+## Markdown HTML
+
+```md
+
+
+Content
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-block-props-types.md b/packages/comark/SPEC/COMARK/component-block-props-types.md
index 7345909ab..cdd858882 100644
--- a/packages/comark/SPEC/COMARK/component-block-props-types.md
+++ b/packages/comark/SPEC/COMARK/component-block-props-types.md
@@ -74,3 +74,13 @@ config:
Component content
::
```
+
+## Markdown HTML
+
+```md
+
+
+Component content
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-block-tailwind-class.md b/packages/comark/SPEC/COMARK/component-block-tailwind-class.md
index eea440e78..d69c6145b 100644
--- a/packages/comark/SPEC/COMARK/component-block-tailwind-class.md
+++ b/packages/comark/SPEC/COMARK/component-block-tailwind-class.md
@@ -39,3 +39,13 @@ Hello
Hello
::
```
+
+## Markdown HTML
+
+```md
+
+
+Hello
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-br-escaped.md b/packages/comark/SPEC/COMARK/component-br-escaped.md
new file mode 100644
index 000000000..0a5dbdab0
--- /dev/null
+++ b/packages/comark/SPEC/COMARK/component-br-escaped.md
@@ -0,0 +1,57 @@
+## Input
+
+```md
+::tip
+before
+\# literal
+::
+```
+
+## AST
+
+```json
+{
+ "frontmatter": {},
+ "meta": {},
+ "nodes": [
+ [
+ "tip",
+ {},
+ "before",
+ [
+ "br",
+ {}
+ ],
+ "# literal"
+ ]
+ ]
+}
+```
+
+## HTML
+
+```html
+
+ before
# literal
+
+```
+
+## Markdown
+
+```md
+::tip
+before
+\# literal
+::
+```
+
+## Markdown HTML
+
+```md
+
+
+before
+\# literal
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-empty.md b/packages/comark/SPEC/COMARK/component-empty.md
index 3de9c2b1f..ac8144333 100644
--- a/packages/comark/SPEC/COMARK/component-empty.md
+++ b/packages/comark/SPEC/COMARK/component-empty.md
@@ -32,3 +32,9 @@
::component
::
```
+
+## Markdown HTML
+
+```md
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-multiple-colons.md b/packages/comark/SPEC/COMARK/component-multiple-colons.md
index 3d95ec6a4..156972c13 100644
--- a/packages/comark/SPEC/COMARK/component-multiple-colons.md
+++ b/packages/comark/SPEC/COMARK/component-multiple-colons.md
@@ -32,3 +32,9 @@
::component
::
```
+
+## Markdown HTML
+
+```md
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-name-comment.md b/packages/comark/SPEC/COMARK/component-name-comment.md
index 43fd79e59..e21e062ca 100644
--- a/packages/comark/SPEC/COMARK/component-name-comment.md
+++ b/packages/comark/SPEC/COMARK/component-name-comment.md
@@ -57,3 +57,15 @@ Some :comment[a note]{author="maxi"} text.
body
::
```
+
+## Markdown HTML
+
+```md
+Some a note text.
+
+
+
+body
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-name-math.md b/packages/comark/SPEC/COMARK/component-name-math.md
index cebcc0677..a546ef85b 100644
--- a/packages/comark/SPEC/COMARK/component-name-math.md
+++ b/packages/comark/SPEC/COMARK/component-name-math.md
@@ -57,3 +57,15 @@ Some :math[x] text.
body
::
```
+
+## Markdown HTML
+
+```md
+Some text.
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-name-mermaid.md b/packages/comark/SPEC/COMARK/component-name-mermaid.md
index 69c852ca6..fa34ed9fe 100644
--- a/packages/comark/SPEC/COMARK/component-name-mermaid.md
+++ b/packages/comark/SPEC/COMARK/component-name-mermaid.md
@@ -55,3 +55,15 @@ Some :mermaid[x] text.
body
::
```
+
+## Markdown HTML
+
+```md
+Some x text.
+
+
+
+body
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-name-table.md b/packages/comark/SPEC/COMARK/component-name-table.md
index 5b392145c..2d8d17146 100644
--- a/packages/comark/SPEC/COMARK/component-name-table.md
+++ b/packages/comark/SPEC/COMARK/component-name-table.md
@@ -54,3 +54,11 @@ Some :table[x] text.
Some :table[x] text.
```
+
+## Markdown HTML
+
+```md
+
+
+Some text.
+```
diff --git a/packages/comark/SPEC/COMARK/component-name-template.md b/packages/comark/SPEC/COMARK/component-name-template.md
index e312e30aa..bf3b4fd2b 100644
--- a/packages/comark/SPEC/COMARK/component-name-template.md
+++ b/packages/comark/SPEC/COMARK/component-name-template.md
@@ -57,3 +57,15 @@ Some :template[x] text.
body
::
```
+
+## Markdown HTML
+
+```md
+Some x text.
+
+
+
+body
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-nested-after-list.md b/packages/comark/SPEC/COMARK/component-nested-after-list.md
index e1d70b47b..51a6dc1e3 100644
--- a/packages/comark/SPEC/COMARK/component-nested-after-list.md
+++ b/packages/comark/SPEC/COMARK/component-nested-after-list.md
@@ -99,3 +99,22 @@ Make sure to use an even numbered version.
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+### Prerequisites
+
+- **Node.js** - `22.x` or newer
+- **Terminal** - In order to run Nuxt commands
+
+
+
+Make sure to use an even numbered version.
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-nested-codeblock-indented.md b/packages/comark/SPEC/COMARK/component-nested-codeblock-indented.md
index e2089e859..b9d14eee7 100644
--- a/packages/comark/SPEC/COMARK/component-nested-codeblock-indented.md
+++ b/packages/comark/SPEC/COMARK/component-nested-codeblock-indented.md
@@ -68,3 +68,20 @@
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+```mdc
+ ::accordion
+ ::
+```
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-nested-codeblock-outdented.md b/packages/comark/SPEC/COMARK/component-nested-codeblock-outdented.md
index bbecf01e7..665bc52a7 100644
--- a/packages/comark/SPEC/COMARK/component-nested-codeblock-outdented.md
+++ b/packages/comark/SPEC/COMARK/component-nested-codeblock-outdented.md
@@ -68,3 +68,20 @@
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+```mdc
+ ::accordion
+ ::
+```
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-nested-codeblock.md b/packages/comark/SPEC/COMARK/component-nested-codeblock.md
index 79f073e4e..e4fff76bb 100644
--- a/packages/comark/SPEC/COMARK/component-nested-codeblock.md
+++ b/packages/comark/SPEC/COMARK/component-nested-codeblock.md
@@ -59,3 +59,17 @@ hello
```
::
```
+
+## Markdown HTML
+
+```md
+
+
+```mdc
+::alert
+hello
+::
+```
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-nested-deep-outdented.md b/packages/comark/SPEC/COMARK/component-nested-deep-outdented.md
index 3ac8de8ff..6e189267e 100644
--- a/packages/comark/SPEC/COMARK/component-nested-deep-outdented.md
+++ b/packages/comark/SPEC/COMARK/component-nested-deep-outdented.md
@@ -57,3 +57,21 @@ text
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+
+
+text
+
+
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-nested-in-list.md b/packages/comark/SPEC/COMARK/component-nested-in-list.md
index b3f3664f2..0313569c2 100644
--- a/packages/comark/SPEC/COMARK/component-nested-in-list.md
+++ b/packages/comark/SPEC/COMARK/component-nested-in-list.md
@@ -103,3 +103,22 @@
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+### Prerequisites
+
+- **Node.js** - `22.x` or newer
+- **Terminal** - In order to run Nuxt commands
+
+
+
+ Make sure to use an even numbered version.
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-nested-multiline-separated.md b/packages/comark/SPEC/COMARK/component-nested-multiline-separated.md
index f26d4c22c..ea56d986d 100644
--- a/packages/comark/SPEC/COMARK/component-nested-multiline-separated.md
+++ b/packages/comark/SPEC/COMARK/component-nested-multiline-separated.md
@@ -211,3 +211,45 @@ full-width: true
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-nested-paragraph-outdented.md b/packages/comark/SPEC/COMARK/component-nested-paragraph-outdented.md
index f5557da98..c74048a7a 100644
--- a/packages/comark/SPEC/COMARK/component-nested-paragraph-outdented.md
+++ b/packages/comark/SPEC/COMARK/component-nested-paragraph-outdented.md
@@ -49,3 +49,17 @@ hello world
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+hello world
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-nested-unindented.md b/packages/comark/SPEC/COMARK/component-nested-unindented.md
index 4f2a91a36..4634cb419 100644
--- a/packages/comark/SPEC/COMARK/component-nested-unindented.md
+++ b/packages/comark/SPEC/COMARK/component-nested-unindented.md
@@ -99,3 +99,35 @@ This is the parent
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+This is the parent
+
+
+
+Sibling content
+
+
+
+
+
+
+
+Slot content
+
+
+
+
+
+More slot content
+
+
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-nested-yaml-props-outdented.md b/packages/comark/SPEC/COMARK/component-nested-yaml-props-outdented.md
index 47aebecd4..4ef5980c1 100644
--- a/packages/comark/SPEC/COMARK/component-nested-yaml-props-outdented.md
+++ b/packages/comark/SPEC/COMARK/component-nested-yaml-props-outdented.md
@@ -54,3 +54,17 @@ content
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+content
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-nested.md b/packages/comark/SPEC/COMARK/component-nested.md
index b934f6b9c..a6771702e 100644
--- a/packages/comark/SPEC/COMARK/component-nested.md
+++ b/packages/comark/SPEC/COMARK/component-nested.md
@@ -57,3 +57,19 @@ First Paragraph
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+First Paragraph
+
+
+
+Second Paragraph
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-nested2.md b/packages/comark/SPEC/COMARK/component-nested2.md
index b07f37882..e980e4697 100644
--- a/packages/comark/SPEC/COMARK/component-nested2.md
+++ b/packages/comark/SPEC/COMARK/component-nested2.md
@@ -57,3 +57,19 @@ First Paragraph
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+First Paragraph
+
+
+
+Second Paragraph
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-nested3.md b/packages/comark/SPEC/COMARK/component-nested3.md
index 536abf369..a84bed749 100644
--- a/packages/comark/SPEC/COMARK/component-nested3.md
+++ b/packages/comark/SPEC/COMARK/component-nested3.md
@@ -77,3 +77,25 @@ First Paragraph
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+First Paragraph
+
+
+
+Second Paragraph
+
+
+
+Third Paragraph
+
+
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-nested4.md b/packages/comark/SPEC/COMARK/component-nested4.md
index 8097d8529..4d5c69499 100644
--- a/packages/comark/SPEC/COMARK/component-nested4.md
+++ b/packages/comark/SPEC/COMARK/component-nested4.md
@@ -171,3 +171,51 @@ timeout:
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+
+
+{{ $doc.snippet.tagline }}
+
+
+
+
+
+{{ $doc.snippet.title }}
+
+
+
+
+
+{{ $doc.snippet.description }}
+
+
+
+
+
+
+
+
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-props-boolean-false.md b/packages/comark/SPEC/COMARK/component-props-boolean-false.md
index 9b9b71eea..4d07c8f39 100644
--- a/packages/comark/SPEC/COMARK/component-props-boolean-false.md
+++ b/packages/comark/SPEC/COMARK/component-props-boolean-false.md
@@ -52,3 +52,13 @@ My button
My button
::
```
+
+## Markdown HTML
+
+```md
+
+
+My button
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-props-boolean-inline.md b/packages/comark/SPEC/COMARK/component-props-boolean-inline.md
index 7d50c421b..84cee9004 100644
--- a/packages/comark/SPEC/COMARK/component-props-boolean-inline.md
+++ b/packages/comark/SPEC/COMARK/component-props-boolean-inline.md
@@ -51,3 +51,13 @@ My button
My button
::
```
+
+## Markdown HTML
+
+```md
+
+
+My button
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-props-boolean-yaml.md b/packages/comark/SPEC/COMARK/component-props-boolean-yaml.md
index 602a406b0..dbbbd5364 100644
--- a/packages/comark/SPEC/COMARK/component-props-boolean-yaml.md
+++ b/packages/comark/SPEC/COMARK/component-props-boolean-yaml.md
@@ -57,3 +57,13 @@ disabled: true
My button
::
```
+
+## Markdown HTML
+
+```md
+
+
+My button
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-props-four-inline-to-yaml.md b/packages/comark/SPEC/COMARK/component-props-four-inline-to-yaml.md
index 58e094883..f3b13d91c 100644
--- a/packages/comark/SPEC/COMARK/component-props-four-inline-to-yaml.md
+++ b/packages/comark/SPEC/COMARK/component-props-four-inline-to-yaml.md
@@ -48,3 +48,13 @@ variant: soft
Content
::
```
+
+## Markdown HTML
+
+```md
+
+
+Content
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-props-max-inline-zero.md b/packages/comark/SPEC/COMARK/component-props-max-inline-zero.md
index 893c4a56e..888d11075 100644
--- a/packages/comark/SPEC/COMARK/component-props-max-inline-zero.md
+++ b/packages/comark/SPEC/COMARK/component-props-max-inline-zero.md
@@ -51,3 +51,13 @@ title: Hello
Content
::
```
+
+## Markdown HTML
+
+```md
+
+
+Content
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-props-single-yaml.md b/packages/comark/SPEC/COMARK/component-props-single-yaml.md
index 3118e4f9c..6eb603d34 100644
--- a/packages/comark/SPEC/COMARK/component-props-single-yaml.md
+++ b/packages/comark/SPEC/COMARK/component-props-single-yaml.md
@@ -42,3 +42,13 @@ Content
Content
::
```
+
+## Markdown HTML
+
+```md
+
+
+Content
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-props-three-inline.md b/packages/comark/SPEC/COMARK/component-props-three-inline.md
index 3aedeb50b..ebce8c371 100644
--- a/packages/comark/SPEC/COMARK/component-props-three-inline.md
+++ b/packages/comark/SPEC/COMARK/component-props-three-inline.md
@@ -41,3 +41,13 @@ Content
Content
::
```
+
+## Markdown HTML
+
+```md
+
+
+Content
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-short+block.md b/packages/comark/SPEC/COMARK/component-short+block.md
index 870a7809f..a22b68efb 100644
--- a/packages/comark/SPEC/COMARK/component-short+block.md
+++ b/packages/comark/SPEC/COMARK/component-short+block.md
@@ -73,3 +73,25 @@ First Paragraph
Second Paragraph
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+
+
+First Paragraph
+
+
+
+
+
+Second Paragraph
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-slot-default-escaped.md b/packages/comark/SPEC/COMARK/component-slot-default-escaped.md
new file mode 100644
index 000000000..a86d060b2
--- /dev/null
+++ b/packages/comark/SPEC/COMARK/component-slot-default-escaped.md
@@ -0,0 +1,58 @@
+## Input
+
+```md
+::box
+#default
+\# literal
+::
+```
+
+## AST
+
+```json
+{
+ "frontmatter": {},
+ "meta": {},
+ "nodes": [
+ [
+ "box",
+ {},
+ [
+ "template",
+ {
+ "name": "default"
+ },
+ "# literal"
+ ]
+ ]
+ ]
+}
+```
+
+## HTML
+
+```html
+
+
+ # literal
+
+
+```
+
+## Markdown
+
+```md
+::box
+\# literal
+::
+```
+
+## Markdown HTML
+
+```md
+
+
+\# literal
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-slot-default-named.md b/packages/comark/SPEC/COMARK/component-slot-default-named.md
index eec0d6f94..4a01193fa 100644
--- a/packages/comark/SPEC/COMARK/component-slot-default-named.md
+++ b/packages/comark/SPEC/COMARK/component-slot-default-named.md
@@ -46,3 +46,13 @@ Default slot content
Default slot content
::
```
+
+## Markdown HTML
+
+```md
+
+
+Default slot content
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-slot-default-unwrap-with-named.md b/packages/comark/SPEC/COMARK/component-slot-default-unwrap-with-named.md
index 47cd993e2..91d5232c3 100644
--- a/packages/comark/SPEC/COMARK/component-slot-default-unwrap-with-named.md
+++ b/packages/comark/SPEC/COMARK/component-slot-default-unwrap-with-named.md
@@ -73,3 +73,21 @@
~~~
::
```
+
+## Markdown HTML
+
+```md
+
+
+`inline code`
+
+
+
+~~~mdc
+`inline code`
+~~~
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-slot-default.md b/packages/comark/SPEC/COMARK/component-slot-default.md
index 03aa8b78e..5e373db91 100644
--- a/packages/comark/SPEC/COMARK/component-slot-default.md
+++ b/packages/comark/SPEC/COMARK/component-slot-default.md
@@ -37,3 +37,13 @@ Default slot content
Default slot content
::
```
+
+## Markdown HTML
+
+```md
+
+
+Default slot content
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-slot-nested-after-list.md b/packages/comark/SPEC/COMARK/component-slot-nested-after-list.md
index 0b9952e88..2d3baffb8 100644
--- a/packages/comark/SPEC/COMARK/component-slot-nested-after-list.md
+++ b/packages/comark/SPEC/COMARK/component-slot-nested-after-list.md
@@ -113,3 +113,30 @@ Make sure to use an even numbered version.
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+Getting started
+
+
+
+
+
+- **Node.js** - `22.x` or newer
+- **Terminal** - In order to run Nuxt commands
+
+
+
+Make sure to use an even numbered version.
+
+
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-slot-nested-codeblock.md b/packages/comark/SPEC/COMARK/component-slot-nested-codeblock.md
index d567db4b0..a11920a42 100644
--- a/packages/comark/SPEC/COMARK/component-slot-nested-codeblock.md
+++ b/packages/comark/SPEC/COMARK/component-slot-nested-codeblock.md
@@ -69,3 +69,21 @@ hello
```
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+```mdc
+::alert
+hello
+::
+```
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-slot-nested-components.md b/packages/comark/SPEC/COMARK/component-slot-nested-components.md
index a0f4b7947..25227e123 100644
--- a/packages/comark/SPEC/COMARK/component-slot-nested-components.md
+++ b/packages/comark/SPEC/COMARK/component-slot-nested-components.md
@@ -83,3 +83,29 @@ Some text
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+Some text
+
+
+
+Nested content
+
+
+
+
+
+More nested content
+
+
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-slot-with-multiple-attrs.md b/packages/comark/SPEC/COMARK/component-slot-with-multiple-attrs.md
index 4452155f0..e0b27a919 100644
--- a/packages/comark/SPEC/COMARK/component-slot-with-multiple-attrs.md
+++ b/packages/comark/SPEC/COMARK/component-slot-with-multiple-attrs.md
@@ -49,3 +49,17 @@ Title
Title
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+Title
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-slots-with-attrs.md b/packages/comark/SPEC/COMARK/component-slots-with-attrs.md
index d4f9a28f0..7047710bc 100644
--- a/packages/comark/SPEC/COMARK/component-slots-with-attrs.md
+++ b/packages/comark/SPEC/COMARK/component-slots-with-attrs.md
@@ -65,3 +65,23 @@ Visual Editor
Edit without code.
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+Visual Editor
+
+
+
+
+
+Edit without code.
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-slots-with-default-named.md b/packages/comark/SPEC/COMARK/component-slots-with-default-named.md
index 9fec44c81..8dca292e1 100644
--- a/packages/comark/SPEC/COMARK/component-slots-with-default-named.md
+++ b/packages/comark/SPEC/COMARK/component-slots-with-default-named.md
@@ -63,3 +63,23 @@ First Paragraph
Second Paragraph
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+First Paragraph
+
+
+
+
+
+Second Paragraph
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-slots.md b/packages/comark/SPEC/COMARK/component-slots.md
index 89d0845ed..3300c39f4 100644
--- a/packages/comark/SPEC/COMARK/component-slots.md
+++ b/packages/comark/SPEC/COMARK/component-slots.md
@@ -63,3 +63,23 @@ First Paragraph
Second Paragraph
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+First Paragraph
+
+
+
+
+
+Second Paragraph
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-with-codeblock.md b/packages/comark/SPEC/COMARK/component-with-codeblock.md
index 524986417..f7d5255a3 100644
--- a/packages/comark/SPEC/COMARK/component-with-codeblock.md
+++ b/packages/comark/SPEC/COMARK/component-with-codeblock.md
@@ -99,3 +99,27 @@ This is a paragraph with **bold** and _italic_ text.
```
::
```
+
+## Markdown HTML
+
+```md
+
+
+```mdc [content/index.md]
+---
+title: The Mountains Website
+description: A website about the most iconic mountains in the world.
+---
+
+::my-vue-hero-component{orientation="horizontal"}
+#title
+Welcome to the Mountains Website.
+#description
+This is a description of the Mountains Website.
+::
+
+This is a paragraph with **bold** and _italic_ text.
+```
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-with-heading.md b/packages/comark/SPEC/COMARK/component-with-heading.md
index 4bd6a5950..d0b111f3e 100644
--- a/packages/comark/SPEC/COMARK/component-with-heading.md
+++ b/packages/comark/SPEC/COMARK/component-with-heading.md
@@ -81,3 +81,19 @@ Text content
Text content
::
```
+
+## Markdown HTML
+
+```md
+
+
+### Step 1
+
+
+
+### Step 2
+
+Text content
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-yaml-props-thematic-break-named-slot.md b/packages/comark/SPEC/COMARK/component-yaml-props-thematic-break-named-slot.md
index d583dcf3d..a6e698276 100644
--- a/packages/comark/SPEC/COMARK/component-yaml-props-thematic-break-named-slot.md
+++ b/packages/comark/SPEC/COMARK/component-yaml-props-thematic-break-named-slot.md
@@ -89,3 +89,25 @@ Middle line
Line three
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+Line one
+
+---
+
+Middle line
+
+---
+
+Line three
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-yaml-props-thematic-break.md b/packages/comark/SPEC/COMARK/component-yaml-props-thematic-break.md
index e0dae7767..02b6d1db7 100644
--- a/packages/comark/SPEC/COMARK/component-yaml-props-thematic-break.md
+++ b/packages/comark/SPEC/COMARK/component-yaml-props-thematic-break.md
@@ -79,3 +79,21 @@ Middle text
Below
::
```
+
+## Markdown HTML
+
+```md
+
+
+Above
+
+---
+
+Middle text
+
+---
+
+Below
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component-yaml-props.md b/packages/comark/SPEC/COMARK/component-yaml-props.md
index 33515be72..a74681d20 100644
--- a/packages/comark/SPEC/COMARK/component-yaml-props.md
+++ b/packages/comark/SPEC/COMARK/component-yaml-props.md
@@ -79,3 +79,15 @@ First Paragraph
Second Paragraph
::
```
+
+## Markdown HTML
+
+```md
+
+
+First Paragraph
+
+Second Paragraph
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/component.md b/packages/comark/SPEC/COMARK/component.md
index b8a319c64..77096ff5c 100644
--- a/packages/comark/SPEC/COMARK/component.md
+++ b/packages/comark/SPEC/COMARK/component.md
@@ -51,3 +51,15 @@ First Paragraph
Second Paragraph
::
```
+
+## Markdown HTML
+
+```md
+
+
+First Paragraph
+
+Second Paragraph
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/data-binding-frontmatter.md b/packages/comark/SPEC/COMARK/data-binding-frontmatter.md
index 9cffa1df7..cd2b16839 100644
--- a/packages/comark/SPEC/COMARK/data-binding-frontmatter.md
+++ b/packages/comark/SPEC/COMARK/data-binding-frontmatter.md
@@ -54,3 +54,18 @@ site:
Hello
::
```
+
+## Markdown HTML
+
+```md
+---
+site:
+ name: My Blog
+---
+
+
+
+Hello
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/data-binding-inline.md b/packages/comark/SPEC/COMARK/data-binding-inline.md
index a86bb1a7c..5da658f54 100644
--- a/packages/comark/SPEC/COMARK/data-binding-inline.md
+++ b/packages/comark/SPEC/COMARK/data-binding-inline.md
@@ -54,3 +54,14 @@ user:
Hello :badge{:label="frontmatter.user.name"}!
```
+
+## Markdown HTML
+
+```md
+---
+user:
+ name: Ada
+---
+
+Hello !
+```
diff --git a/packages/comark/SPEC/COMARK/data-binding-props.md b/packages/comark/SPEC/COMARK/data-binding-props.md
index 675e34c3f..2824d25c1 100644
--- a/packages/comark/SPEC/COMARK/data-binding-props.md
+++ b/packages/comark/SPEC/COMARK/data-binding-props.md
@@ -48,3 +48,13 @@
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/data-binding-unresolved.md b/packages/comark/SPEC/COMARK/data-binding-unresolved.md
index 84816db28..ec30f242d 100644
--- a/packages/comark/SPEC/COMARK/data-binding-unresolved.md
+++ b/packages/comark/SPEC/COMARK/data-binding-unresolved.md
@@ -34,3 +34,9 @@
::card{:to="$doc.snippet.link"}
::
```
+
+## Markdown HTML
+
+```md
+
+```
diff --git a/packages/comark/SPEC/COMARK/emoji-inside-component-autounwrap.md b/packages/comark/SPEC/COMARK/emoji-inside-component-autounwrap.md
index f2311f943..b539a3203 100644
--- a/packages/comark/SPEC/COMARK/emoji-inside-component-autounwrap.md
+++ b/packages/comark/SPEC/COMARK/emoji-inside-component-autounwrap.md
@@ -67,3 +67,19 @@ options:
⚠️ Please backup your data before proceeding
::
```
+
+## Markdown HTML
+
+```md
+
+
+✅ Successfully deployed! 🚀
+
+
+
+
+
+⚠️ Please backup your data before proceeding
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/emoji-inside-component.md b/packages/comark/SPEC/COMARK/emoji-inside-component.md
index f2311f943..b539a3203 100644
--- a/packages/comark/SPEC/COMARK/emoji-inside-component.md
+++ b/packages/comark/SPEC/COMARK/emoji-inside-component.md
@@ -67,3 +67,19 @@ options:
⚠️ Please backup your data before proceeding
::
```
+
+## Markdown HTML
+
+```md
+
+
+✅ Successfully deployed! 🚀
+
+
+
+
+
+⚠️ Please backup your data before proceeding
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/inline-component-br.md b/packages/comark/SPEC/COMARK/inline-component-br.md
index e8a1e24a9..924117438 100644
--- a/packages/comark/SPEC/COMARK/inline-component-br.md
+++ b/packages/comark/SPEC/COMARK/inline-component-br.md
@@ -89,3 +89,18 @@ Published modules cannot leverage auto-imports.
:br :br
Auto-imports are not enabled for files within `node_modules`.
```
+
+## Markdown HTML
+
+```md
+
+
+Beware that using only `$fetch` will not provide network calls de-duplication.
+It is recommended to use `$fetch` for client-side interactions.
+
+
+
+Published modules cannot leverage auto-imports.
+
+Auto-imports are not enabled for files within `node_modules`.
+```
diff --git a/packages/comark/SPEC/COMARK/inline-component-in-blockquote.md b/packages/comark/SPEC/COMARK/inline-component-in-blockquote.md
new file mode 100644
index 000000000..eff845ed2
--- /dev/null
+++ b/packages/comark/SPEC/COMARK/inline-component-in-blockquote.md
@@ -0,0 +1,49 @@
+## Input
+
+```md
+> Quote :badge[x] end
+```
+
+## AST
+
+```json
+{
+ "frontmatter": {},
+ "meta": {},
+ "nodes": [
+ [
+ "blockquote",
+ {},
+ "Quote ",
+ [
+ "badge",
+ {},
+ "x"
+ ],
+ " end"
+ ]
+ ]
+}
+```
+
+## HTML
+
+```html
+
+ Quote
+ x
+ end
+
+```
+
+## Markdown
+
+```md
+> Quote :badge[x] end
+```
+
+## Markdown HTML
+
+```md
+> Quote x end
+```
diff --git a/packages/comark/SPEC/COMARK/inline-component-in-component.md b/packages/comark/SPEC/COMARK/inline-component-in-component.md
new file mode 100644
index 000000000..cc315025e
--- /dev/null
+++ b/packages/comark/SPEC/COMARK/inline-component-in-component.md
@@ -0,0 +1,57 @@
+## Input
+
+```md
+::alert
+Hello :badge[x] world
+::
+```
+
+## AST
+
+```json
+{
+ "frontmatter": {},
+ "meta": {},
+ "nodes": [
+ [
+ "alert",
+ {},
+ "Hello ",
+ [
+ "badge",
+ {},
+ "x"
+ ],
+ " world"
+ ]
+ ]
+}
+```
+
+## HTML
+
+```html
+
+ Hello
+ x
+ world
+
+```
+
+## Markdown
+
+```md
+::alert
+Hello :badge[x] world
+::
+```
+
+## Markdown HTML
+
+```md
+
+
+Hello x world
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/inline-component-in-list-item.md b/packages/comark/SPEC/COMARK/inline-component-in-list-item.md
new file mode 100644
index 000000000..df093ce59
--- /dev/null
+++ b/packages/comark/SPEC/COMARK/inline-component-in-list-item.md
@@ -0,0 +1,64 @@
+## Input
+
+```md
+- Press :kbd{value="meta"} then :badge[New]{color="green"} appears
+```
+
+## AST
+
+```json
+{
+ "frontmatter": {},
+ "meta": {},
+ "nodes": [
+ [
+ "ul",
+ {},
+ [
+ "li",
+ {},
+ "Press ",
+ [
+ "kbd",
+ {
+ "value": "meta"
+ }
+ ],
+ " then ",
+ [
+ "badge",
+ {
+ "color": "green"
+ },
+ "New"
+ ],
+ " appears"
+ ]
+ ]
+ ]
+}
+```
+
+## HTML
+
+```html
+
+ -
+ Press then
+ New
+ appears
+
+
+```
+
+## Markdown
+
+```md
+- Press :kbd{value="meta"} then :badge[New]{color="green"} appears
+```
+
+## Markdown HTML
+
+```md
+- Press then New appears
+```
diff --git a/packages/comark/SPEC/COMARK/inline-component-mixed.md b/packages/comark/SPEC/COMARK/inline-component-mixed.md
index 8dae97a96..9c2808308 100644
--- a/packages/comark/SPEC/COMARK/inline-component-mixed.md
+++ b/packages/comark/SPEC/COMARK/inline-component-mixed.md
@@ -103,3 +103,15 @@
[:component[text]{.class}]
```
+
+## Markdown HTML
+
+```md
+[text](/link)
+
+**text**
+
+*text*
+
+text
+```
diff --git a/packages/comark/SPEC/COMARK/inline-component-props-boolean.md b/packages/comark/SPEC/COMARK/inline-component-props-boolean.md
index caea54ba5..6b9447bdc 100644
--- a/packages/comark/SPEC/COMARK/inline-component-props-boolean.md
+++ b/packages/comark/SPEC/COMARK/inline-component-props-boolean.md
@@ -35,3 +35,9 @@
::component{reverse :square="false" disabled}
::
```
+
+## Markdown HTML
+
+```md
+
+```
diff --git a/packages/comark/SPEC/COMARK/inline-component-tailwind-class.md b/packages/comark/SPEC/COMARK/inline-component-tailwind-class.md
index da28a048c..f5facaacf 100644
--- a/packages/comark/SPEC/COMARK/inline-component-tailwind-class.md
+++ b/packages/comark/SPEC/COMARK/inline-component-tailwind-class.md
@@ -40,3 +40,9 @@ Hello :badge{.bg-[#fff].text-[12px]} world
```md
Hello :badge{.bg-[#fff].text-[12px]} world
```
+
+## Markdown HTML
+
+```md
+Hello world
+```
diff --git a/packages/comark/SPEC/COMARK/inline-component-text-sibling.md b/packages/comark/SPEC/COMARK/inline-component-text-sibling.md
index 92e91fdeb..7629e2a13 100644
--- a/packages/comark/SPEC/COMARK/inline-component-text-sibling.md
+++ b/packages/comark/SPEC/COMARK/inline-component-text-sibling.md
@@ -38,3 +38,9 @@ inline :component syntax
```md
inline :component syntax
```
+
+## Markdown HTML
+
+```md
+inline syntax
+```
diff --git a/packages/comark/SPEC/COMARK/inline-component-with-content-atrributes.md b/packages/comark/SPEC/COMARK/inline-component-with-content-atrributes.md
index be0d6c267..6ed44ed65 100644
--- a/packages/comark/SPEC/COMARK/inline-component-with-content-atrributes.md
+++ b/packages/comark/SPEC/COMARK/inline-component-with-content-atrributes.md
@@ -37,3 +37,13 @@
Syntax
::
```
+
+## Markdown HTML
+
+```md
+
+
+Syntax
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/inline-component-with-content.md b/packages/comark/SPEC/COMARK/inline-component-with-content.md
index bff414685..bb905de75 100644
--- a/packages/comark/SPEC/COMARK/inline-component-with-content.md
+++ b/packages/comark/SPEC/COMARK/inline-component-with-content.md
@@ -35,3 +35,13 @@
Syntax
::
```
+
+## Markdown HTML
+
+```md
+
+
+Syntax
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/inline-component.md b/packages/comark/SPEC/COMARK/inline-component.md
index a87826359..906cf1111 100644
--- a/packages/comark/SPEC/COMARK/inline-component.md
+++ b/packages/comark/SPEC/COMARK/inline-component.md
@@ -89,3 +89,15 @@ Paragraph with :inline-component in middle
## a :inline inside heading
```
+
+## Markdown HTML
+
+```md
+an
+
+Paragraph with
+
+Paragraph with in middle
+
+## a inside heading
+```
diff --git a/packages/comark/SPEC/COMARK/link-with-span.md b/packages/comark/SPEC/COMARK/link-with-span.md
index 92be8f436..55f0ba478 100644
--- a/packages/comark/SPEC/COMARK/link-with-span.md
+++ b/packages/comark/SPEC/COMARK/link-with-span.md
@@ -65,3 +65,11 @@
[[link-name]{.cls} more](https://example.com)
```
+
+## Markdown HTML
+
+```md
+[1 Document](#)
+
+[link-name more](https://example.com)
+```
diff --git a/packages/comark/SPEC/COMARK/span.md b/packages/comark/SPEC/COMARK/span.md
index a26ecca21..4f040b234 100644
--- a/packages/comark/SPEC/COMARK/span.md
+++ b/packages/comark/SPEC/COMARK/span.md
@@ -60,3 +60,9 @@ options:
```md
[**Bold** and *italic* text]{.highlight}
```
+
+## Markdown HTML
+
+```md
+**Bold** and *italic* text
+```
diff --git a/packages/comark/SPEC/COMARK/wrapped-component-nested.md b/packages/comark/SPEC/COMARK/wrapped-component-nested.md
index 5d4ceea54..b71161fde 100644
--- a/packages/comark/SPEC/COMARK/wrapped-component-nested.md
+++ b/packages/comark/SPEC/COMARK/wrapped-component-nested.md
@@ -70,3 +70,19 @@ First Paragraph
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+First Paragraph
+
+
+
+Second Paragraph
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/wrapped-component-nested2.md b/packages/comark/SPEC/COMARK/wrapped-component-nested2.md
index c64490d6f..2cfc19a41 100644
--- a/packages/comark/SPEC/COMARK/wrapped-component-nested2.md
+++ b/packages/comark/SPEC/COMARK/wrapped-component-nested2.md
@@ -70,3 +70,19 @@ First Paragraph
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+First Paragraph
+
+
+
+Second Paragraph
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/wrapped-component-nested3.md b/packages/comark/SPEC/COMARK/wrapped-component-nested3.md
index 845e833cb..e8f8eb7bc 100644
--- a/packages/comark/SPEC/COMARK/wrapped-component-nested3.md
+++ b/packages/comark/SPEC/COMARK/wrapped-component-nested3.md
@@ -90,3 +90,25 @@ First Paragraph
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+First Paragraph
+
+
+
+Second Paragraph
+
+
+
+Third Paragraph
+
+
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/wrapped-component-short+block.md b/packages/comark/SPEC/COMARK/wrapped-component-short+block.md
index 40766a113..10fc26ebc 100644
--- a/packages/comark/SPEC/COMARK/wrapped-component-short+block.md
+++ b/packages/comark/SPEC/COMARK/wrapped-component-short+block.md
@@ -90,3 +90,25 @@ First Paragraph
Second Paragraph
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+
+
+First Paragraph
+
+
+
+
+
+Second Paragraph
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/wrapped-component-slot-default-named.md b/packages/comark/SPEC/COMARK/wrapped-component-slot-default-named.md
index b5c69d6c6..8007c9633 100644
--- a/packages/comark/SPEC/COMARK/wrapped-component-slot-default-named.md
+++ b/packages/comark/SPEC/COMARK/wrapped-component-slot-default-named.md
@@ -59,3 +59,13 @@ Default slot content
Default slot content
::
```
+
+## Markdown HTML
+
+```md
+
+
+Default slot content
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/wrapped-component-slot-default.md b/packages/comark/SPEC/COMARK/wrapped-component-slot-default.md
index 4b9d7d7d8..a855f6bd5 100644
--- a/packages/comark/SPEC/COMARK/wrapped-component-slot-default.md
+++ b/packages/comark/SPEC/COMARK/wrapped-component-slot-default.md
@@ -50,3 +50,13 @@ Default slot content
Default slot content
::
```
+
+## Markdown HTML
+
+```md
+
+
+Default slot content
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/wrapped-component-slots-with-default-named.md b/packages/comark/SPEC/COMARK/wrapped-component-slots-with-default-named.md
index e38af3412..27b7cf444 100644
--- a/packages/comark/SPEC/COMARK/wrapped-component-slots-with-default-named.md
+++ b/packages/comark/SPEC/COMARK/wrapped-component-slots-with-default-named.md
@@ -80,3 +80,23 @@ First Paragraph
Second Paragraph
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+First Paragraph
+
+
+
+
+
+Second Paragraph
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/wrapped-component-slots.md b/packages/comark/SPEC/COMARK/wrapped-component-slots.md
index 7760e1a7d..d45a9784e 100644
--- a/packages/comark/SPEC/COMARK/wrapped-component-slots.md
+++ b/packages/comark/SPEC/COMARK/wrapped-component-slots.md
@@ -80,3 +80,23 @@ First Paragraph
Second Paragraph
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+
+First Paragraph
+
+
+
+
+
+Second Paragraph
+
+
+
+
+```
diff --git a/packages/comark/SPEC/COMARK/wrapped-emoji-inside-component.md b/packages/comark/SPEC/COMARK/wrapped-emoji-inside-component.md
index c7c6a80f1..92d787edc 100644
--- a/packages/comark/SPEC/COMARK/wrapped-emoji-inside-component.md
+++ b/packages/comark/SPEC/COMARK/wrapped-emoji-inside-component.md
@@ -76,3 +76,19 @@ options:
⚠️ Please backup your data before proceeding
::
```
+
+## Markdown HTML
+
+```md
+
+
+✅ Successfully deployed! 🚀
+
+
+
+
+
+⚠️ Please backup your data before proceeding
+
+
+```
diff --git a/packages/comark/SPEC/HTML/block+component.md b/packages/comark/SPEC/HTML/block+component.md
index eeb0c7dcf..5c5266ed4 100644
--- a/packages/comark/SPEC/HTML/block+component.md
+++ b/packages/comark/SPEC/HTML/block+component.md
@@ -54,3 +54,15 @@ Default Slot
::
```
+
+## Markdown HTML
+
+```md
+
+
+
+Default Slot
+
+
+
+```
diff --git a/packages/comark/SPEC/markdown-directive/container-block-directive.md b/packages/comark/SPEC/markdown-directive/container-block-directive.md
index 3c3ae6933..2041e2dd4 100644
--- a/packages/comark/SPEC/markdown-directive/container-block-directive.md
+++ b/packages/comark/SPEC/markdown-directive/container-block-directive.md
@@ -57,3 +57,15 @@ This is a **warning** message.
Do not ignore it.
::
```
+
+## Markdown HTML
+
+```md
+
+
+This is a **warning** message.
+
+Do not ignore it.
+
+
+```
diff --git a/packages/comark/SPEC/markdown-directive/container-directive-fence.md b/packages/comark/SPEC/markdown-directive/container-directive-fence.md
index d53ce37e3..3eec9fae1 100644
--- a/packages/comark/SPEC/markdown-directive/container-directive-fence.md
+++ b/packages/comark/SPEC/markdown-directive/container-directive-fence.md
@@ -79,3 +79,25 @@ Outer content.
:::
::
```
+
+## Markdown HTML
+
+```md
+
+
+Outer content.
+
+
+
+Inner content.
+
+
+
+Deeply nested.
+
+
+
+
+
+
+```
diff --git a/packages/comark/SPEC/markdown-directive/directive-attributes.md b/packages/comark/SPEC/markdown-directive/directive-attributes.md
index 5a9aa7a92..4acec829d 100644
--- a/packages/comark/SPEC/markdown-directive/directive-attributes.md
+++ b/packages/comark/SPEC/markdown-directive/directive-attributes.md
@@ -76,3 +76,21 @@ text
Content here.
::
```
+
+## Markdown HTML
+
+```md
+text world
+
+
+
+text
+
+
+
+
+
+Content here.
+
+
+```
diff --git a/packages/comark/SPEC/markdown-directive/directive-id-class.md b/packages/comark/SPEC/markdown-directive/directive-id-class.md
index 167f9ce1c..9bb70d815 100644
--- a/packages/comark/SPEC/markdown-directive/directive-id-class.md
+++ b/packages/comark/SPEC/markdown-directive/directive-id-class.md
@@ -77,3 +77,19 @@ Welcome to the site.
Welcome to the site.
::
```
+
+## Markdown HTML
+
+```md
+hello
+
+world
+
+styled
+
+
+
+Welcome to the site.
+
+
+```
diff --git a/packages/comark/SPEC/markdown-directive/directive-inline-content.md b/packages/comark/SPEC/markdown-directive/directive-inline-content.md
index 2749d357c..c14bb41b9 100644
--- a/packages/comark/SPEC/markdown-directive/directive-inline-content.md
+++ b/packages/comark/SPEC/markdown-directive/directive-inline-content.md
@@ -92,3 +92,27 @@ Important Notice
The label contains inline content but the body has block content.
::
```
+
+## Markdown HTML
+
+```md
+
+
+it's a *happy* ending
+
+
+
+[
+
+see **figure 1**
+
+](myFigure)
+
+
+
+Important Notice
+
+The label contains inline content but the body has block content.
+
+
+```
diff --git a/packages/comark/SPEC/markdown-directive/directive-nesting.md b/packages/comark/SPEC/markdown-directive/directive-nesting.md
index 0cea53238..664ca0d67 100644
--- a/packages/comark/SPEC/markdown-directive/directive-nesting.md
+++ b/packages/comark/SPEC/markdown-directive/directive-nesting.md
@@ -67,3 +67,21 @@ This is a spoiler.
More spoiler content.
::
```
+
+## Markdown HTML
+
+```md
+
+
+This is a spoiler.
+
+
+
+Nested warning inside spoiler.
+
+
+
+More spoiler content.
+
+
+```
diff --git a/packages/comark/SPEC/markdown-directive/directive-no-content.md b/packages/comark/SPEC/markdown-directive/directive-no-content.md
index 6f01f9b5c..54e1c46c4 100644
--- a/packages/comark/SPEC/markdown-directive/directive-no-content.md
+++ b/packages/comark/SPEC/markdown-directive/directive-no-content.md
@@ -79,3 +79,15 @@ a :br with no content or attributes
::separator
::
```
+
+## Markdown HTML
+
+```md
+a :hr directive with no content
+
+a
with no content or attributes
+
+
+
+
+```
diff --git a/packages/comark/SPEC/markdown-directive/inline-directive.md b/packages/comark/SPEC/markdown-directive/inline-directive.md
index 152916cfb..0a6da6c1c 100644
--- a/packages/comark/SPEC/markdown-directive/inline-directive.md
+++ b/packages/comark/SPEC/markdown-directive/inline-directive.md
@@ -77,3 +77,13 @@ a :cite[smith04] reference
paragraph with :abbr[HTML]{title="HyperText Markup Language"} inline
```
+
+## Markdown HTML
+
+```md
+a content directive
+
+a smith04 reference
+
+paragraph with HTML inline
+```
diff --git a/packages/comark/SPEC/plugins-binding/binding-span.md b/packages/comark/SPEC/plugins-binding/binding-span.md
index a23209e7d..54a80bba7 100644
--- a/packages/comark/SPEC/plugins-binding/binding-span.md
+++ b/packages/comark/SPEC/plugins-binding/binding-span.md
@@ -60,3 +60,13 @@ color: red
[highlighted {{ frontmatter.color }} text]{.glow}
```
+
+## Markdown HTML
+
+```md
+---
+color: red
+---
+
+highlighted {{ frontmatter.color }} text
+```
diff --git a/packages/comark/src/internal/stringify/handlers/blockquote.ts b/packages/comark/src/internal/stringify/handlers/blockquote.ts
index b8bf479f0..fa4c913a7 100644
--- a/packages/comark/src/internal/stringify/handlers/blockquote.ts
+++ b/packages/comark/src/internal/stringify/handlers/blockquote.ts
@@ -5,10 +5,7 @@ import { comarkAttributes, userBlockAttrs } from '../attributes.ts'
export async function blockquote(node: ElementNode, state: State) {
const children = node.slice(2) as Node[]
- let childResult = ''
- for (const child of children) {
- childResult += await state.one(child, state, node, childResult === '' || childResult.endsWith('\n'))
- }
+ let childResult = await state.flow(node, state, undefined, { atLineStart: true })
const userAttrs = userBlockAttrs('blockquote', node[1] as Record)
const attrs = comarkAttributes(userAttrs)
diff --git a/packages/comark/src/internal/stringify/handlers/html.ts b/packages/comark/src/internal/stringify/handlers/html.ts
index 59e1e9d30..c7850536e 100644
--- a/packages/comark/src/internal/stringify/handlers/html.ts
+++ b/packages/comark/src/internal/stringify/handlers/html.ts
@@ -1,5 +1,5 @@
import type { State } from 'comark/render'
-import type { ElementNode } from 'comark'
+import type { ElementNode, Node } from 'comark'
import { htmlAttributes } from '../html-attributes.ts'
import { indent, toNativeAttributes } from '../../../utils/index.ts'
@@ -55,7 +55,12 @@ export async function html(node: ElementNode, state: State, parent?: ElementNode
oneLiner = true
}
- if (parent?.[0] === 'p' || state.context.inline) {
+ if (parent?.[0] === 'p' || inlineTags.has(String(parent?.[0])) || state.context.inline) {
+ oneLiner = true
+ }
+
+ // Next to text, a component is inline even without a `p` around it (tight list item, blockquote, unwrapped component).
+ if (!state.context.html && $.html !== 1 && parent?.some((child, index) => index > 1 && typeof child === 'string')) {
oneLiner = true
}
@@ -67,27 +72,41 @@ export async function html(node: ElementNode, state: State, parent?: ElementNode
const revert = state.applyContext({ inline: oneLiner })
+ const isBlockChild = (child: Node) =>
+ typeof child !== 'string' &&
+ (blockTags.has(String(child?.[0])) || (!inlineTags.has(String(child?.[0])) && !hasTextSibling))
+
+ // A component written as a tag needs blank lines around its markdown, or CommonMark keeps it in the HTML block.
+ const markdownBody = !state.context.html && !oneLiner && $.html !== 1
+
const childrenContent: string[] = []
- for (const child of children) {
- childrenContent.push(await state.one(child, state, node))
+ for (let i = 0; i < children.length; i++) {
+ // A hard break (`br`) also ends a line, so check the rendered text, not only the previous node type.
+ const prev = childrenContent[i - 1]
+ const atLineStart = markdownBody && (i === 0 || isBlockChild(children[i - 1]) || prev.endsWith('\n'))
+ childrenContent.push(await state.one(children[i], state, node, atLineStart))
}
// A blank line inside a raw-HTML element would terminate it on reparse
- const childSeparator = state.context.html ? state.context.blockSeparator : oneLiner ? '' : '\n'
+ const childSeparator = state.context.html
+ ? state.context.blockSeparator
+ : markdownBody
+ ? '\n\n'
+ : oneLiner
+ ? ''
+ : '\n'
let content = ''
let isPrevBlock = true
for (let i = 0; i < children.length; i++) {
const childContent = childrenContent[i]
- const child = children[i]
- const isBlock =
- typeof child !== 'string' &&
- (blockTags.has(String(child?.[0])) || (!inlineTags.has(String(child?.[0])) && !hasTextSibling))
+ const isBlock = isBlockChild(children[i])
if (i > 0 && !isPrevBlock && isBlock) {
content += childSeparator
}
- content += childContent
+ // Block handlers end with their own separator, which `childSeparator` replaces.
+ content += markdownBody && isBlock ? trimTrailingNewlines(childContent) : childContent
isPrevBlock = isBlock
if (isBlock && i < children.length - 1) {
@@ -102,7 +121,10 @@ export async function html(node: ElementNode, state: State, parent?: ElementNode
const nativeAttributes = toNativeAttributes(String(tag), node, attributes)
const attrs =
Object.keys(nativeAttributes).length > 0
- ? ` ${htmlAttributes(nativeAttributes, { verbatim: !state.context.html && $.html === 1 })}`
+ ? ` ${htmlAttributes(nativeAttributes, {
+ verbatim: !state.context.html && $.html === 1,
+ encodeNewlines: !state.context.html,
+ })}`
: ''
if (isSelfClose) {
@@ -110,7 +132,8 @@ export async function html(node: ElementNode, state: State, parent?: ElementNode
}
if (!oneLiner && content) {
- content = '\n' + paddNoneHtmlContent(content, state, String(tag)).trimEnd() + '\n'
+ const padding = markdownBody ? '\n\n' : '\n'
+ content = padding + paddNoneHtmlContent(content, state, String(tag)).trimEnd() + padding
}
return `<${tag}${attrs}>${content}${tag}>` + (!parent && !isInline ? state.context.blockSeparator : '')
@@ -129,3 +152,10 @@ function paddNoneHtmlContent(content: string, state: State, tag: string) {
return (content.trim().startsWith('<') ? '' : '') + content + (content.trim().endsWith('>') ? '' : '')
}
+
+// A loop, since `/\n+$/` backtracks quadratically on long runs of newlines.
+function trimTrailingNewlines(content: string): string {
+ let end = content.length
+ while (end > 0 && content.charCodeAt(end - 1) === 10) end--
+ return content.slice(0, end)
+}
diff --git a/packages/comark/src/internal/stringify/handlers/li.ts b/packages/comark/src/internal/stringify/handlers/li.ts
index 53a7cc156..2ea5bf2fb 100644
--- a/packages/comark/src/internal/stringify/handlers/li.ts
+++ b/packages/comark/src/internal/stringify/handlers/li.ts
@@ -53,7 +53,9 @@ export async function li(node: ElementNode, state: State) {
// No parent -> mdc skips its own nesting indentation, so li owns it here.
if (!hasInlineContent && !(tag in state.handlers)) {
const indented = indent(await state.one(child, state), { width: prefixWidth, ignoreFirstLine: !result })
- result = result ? result.trimEnd() + '\n' + indented.trimEnd() + '\n' : indented.trimEnd() + '\n'
+ // A tag cannot interrupt a paragraph in CommonMark, so `markdown/html` needs a blank line before it.
+ const separator = state.context.format === 'markdown/comark' ? '\n' : '\n\n'
+ result = result ? result.trimEnd() + separator + indented.trimEnd() + '\n' : indented.trimEnd() + '\n'
continue
}
}
diff --git a/packages/comark/src/internal/stringify/handlers/mdc.ts b/packages/comark/src/internal/stringify/handlers/mdc.ts
index d2f3024e0..87db5af7b 100644
--- a/packages/comark/src/internal/stringify/handlers/mdc.ts
+++ b/packages/comark/src/internal/stringify/handlers/mdc.ts
@@ -38,7 +38,8 @@ export async function mdc(node: ElementNode, state: State, parent?: ElementNode)
if (content && !content.endsWith('\n') && isSlot(child)) {
content += state.context.blockSeparator
}
- content += await state.one(child, childState, node)
+ // Block bodies start on their own line, so `#` / `-` text there keeps its escape.
+ content += await state.one(child, childState, node, !inline && (content === '' || content.endsWith('\n')))
}
content = content.trimEnd()
diff --git a/packages/comark/src/internal/stringify/handlers/p.ts b/packages/comark/src/internal/stringify/handlers/p.ts
index 60229c6c1..b23be4061 100644
--- a/packages/comark/src/internal/stringify/handlers/p.ts
+++ b/packages/comark/src/internal/stringify/handlers/p.ts
@@ -1,14 +1,9 @@
import type { State } from 'comark/render'
-import type { ElementNode, Node } from 'comark'
+import type { ElementNode } from 'comark'
import { comarkAttributes } from '../attributes.ts'
export async function p(node: ElementNode, state: State, parent?: ElementNode) {
- const children = node.slice(2) as Node[]
-
- let result = ''
- for (const child of children) {
- result += await state.one(child, state, node, result === '' || result.endsWith('\n'))
- }
+ let result = await state.flow(node, state, undefined, { atLineStart: true })
const attrs = comarkAttributes(node[1])
if (attrs) result = `${result.replace(/[ \t]+$/, '')} ${attrs}`
diff --git a/packages/comark/src/internal/stringify/handlers/template.ts b/packages/comark/src/internal/stringify/handlers/template.ts
index a22a3ea3a..1a6f0a774 100644
--- a/packages/comark/src/internal/stringify/handlers/template.ts
+++ b/packages/comark/src/internal/stringify/handlers/template.ts
@@ -11,8 +11,6 @@ export async function template(node: ElementNode, state: State, parent?: Element
return component(node, state, parent)
}
- const content = (await state.flow(node, state)).trimEnd()
-
// Omit #default marker if this is the only slot
if (attrs.name === 'default') {
const siblings = parent ? (parent.slice(2) as Node[]) : []
@@ -20,11 +18,19 @@ export async function template(node: ElementNode, state: State, parent?: Element
(child) => Array.isArray(child) && (child as ElementNode)[0] === 'template'
).length
if (templateCount === 1) {
- return content + state.context.blockSeparator
+ return (await state.flow(node, state, undefined, { atLineStart: true })).trimEnd() + state.context.blockSeparator
}
}
const { name: _name, $: _$, ...rest } = attrs
+
+ // `#name` is Comark syntax and does not parse inside an HTML tag; `name` matches the `text/html` output.
+ if (state.context.format !== 'markdown/comark') {
+ return state.handlers.html(['template', { name: attrs.name, ...rest }, ...(node.slice(2) as Node[])], state, parent)
+ }
+
+ // Slot body is written at the start of a line, so `#` / `-` text must keep its escape.
+ const content = (await state.flow(node, state, undefined, { atLineStart: true })).trimEnd()
const extraAttrs = comarkAttributes(rest)
return `#${attrs.name}${extraAttrs}\n${content}` + state.context.blockSeparator
diff --git a/packages/comark/src/internal/stringify/html-attributes.ts b/packages/comark/src/internal/stringify/html-attributes.ts
index 8f2e810a7..c1f432ff9 100644
--- a/packages/comark/src/internal/stringify/html-attributes.ts
+++ b/packages/comark/src/internal/stringify/html-attributes.ts
@@ -122,10 +122,21 @@ const SAFE_ATTR_NAME = /^[a-zA-Z_:][a-zA-Z0-9_:.-]*$/
interface HtmlAttributesOptions {
/** Keep `:` prefixes and string `"true"` values as written */
verbatim?: boolean
+ /** Write line breaks as `
` / `
`, since a CommonMark HTML block needs its open tag on one line */
+ encodeNewlines?: boolean
}
+const NEWLINE_RE = /[\n\r]/g
+
/** Serialize an attribute bag into an HTML attribute string. */
-export function htmlAttributes(attributes: Record, { verbatim = false }: HtmlAttributesOptions = {}) {
+export function htmlAttributes(
+ attributes: Record,
+ { verbatim = false, encodeNewlines = false }: HtmlAttributesOptions = {}
+) {
+ const escapeValue = (value: string) => {
+ const escaped = escapeHtml(value)
+ return encodeNewlines ? escaped.replace(NEWLINE_RE, (char) => (char === '\n' ? '
' : '
')) : escaped
+ }
const parts: string[] = []
for (const [rawKey, value] of Object.entries(attributes)) {
const isBinding = rawKey.startsWith(':')
@@ -138,10 +149,10 @@ export function htmlAttributes(attributes: Record, { verbatim =
continue
}
if (typeof value === 'object' && value !== null) {
- parts.push(`${key}="${escapeHtml(JSON.stringify(value))}"`)
+ parts.push(`${key}="${escapeValue(JSON.stringify(value))}"`)
continue
}
- parts.push(`${key}="${escapeHtml(String(value))}"`)
+ parts.push(`${key}="${escapeValue(String(value))}"`)
continue
}
@@ -152,11 +163,11 @@ export function htmlAttributes(attributes: Record, { verbatim =
if (value === false || value === null || value === undefined) continue
if (typeof value === 'object') {
- parts.push(`${key}="${escapeHtml(JSON.stringify(value))}"`)
+ parts.push(`${key}="${escapeValue(JSON.stringify(value))}"`)
continue
}
- parts.push(`${key}="${escapeHtml(String(value))}"`)
+ parts.push(`${key}="${escapeValue(String(value))}"`)
}
return parts.join(' ')
}
diff --git a/packages/comark/src/internal/stringify/state.ts b/packages/comark/src/internal/stringify/state.ts
index 986bbe285..0f03af60b 100644
--- a/packages/comark/src/internal/stringify/state.ts
+++ b/packages/comark/src/internal/stringify/state.ts
@@ -1,4 +1,4 @@
-import type { NodeRenderData, State, Context, RendererOptions } from 'comark/render'
+import type { NodeRenderData, State, Context, RendererOptions, FlowOptions } from 'comark/render'
import type { ElementNode, Node, MarkdownDocument, ConditionalNodeHandler, CreateContext, NodeHandler } from 'comark'
import { escapeHtml, pascalCase } from '../../utils/index.ts'
import { resolveAttributes } from './html-attributes.ts'
@@ -118,11 +118,17 @@ export async function one(node: Node, state: State, parent?: ElementNode, atLine
}
}
-export async function flow(node: ElementNode, state: State, parent?: ElementNode): Promise {
- const children = node.slice(2) as ElementNode[]
+export async function flow(
+ node: ElementNode,
+ state: State,
+ parent?: ElementNode,
+ options?: FlowOptions
+): Promise {
+ const children = node.slice(2) as Node[]
+ const atLineStart = options?.atLineStart === true
let result = ''
for (const child of children) {
- result += await one(child, state, parent || node)
+ result += await one(child, state, parent || node, atLineStart && (result === '' || result.endsWith('\n')))
}
return result
}
diff --git a/packages/comark/src/render/index.ts b/packages/comark/src/render/index.ts
index bd5d949b0..0ab015db1 100644
--- a/packages/comark/src/render/index.ts
+++ b/packages/comark/src/render/index.ts
@@ -7,6 +7,7 @@ import { handlers } from '../internal/stringify/handlers/index.ts'
export type {
NodeHandler,
State,
+ FlowOptions,
Context,
RendererOptions,
RenderMarkdownOptions,
diff --git a/packages/comark/src/types.ts b/packages/comark/src/types.ts
index 6af6b35b7..6ce03f5e6 100644
--- a/packages/comark/src/types.ts
+++ b/packages/comark/src/types.ts
@@ -151,6 +151,20 @@ export interface Context extends ContextBase {
/** Renders a single element node to a string. */
export type NodeHandler = (node: ElementNode, state: State, parent?: ElementNode) => string | Promise
+/**
+ * Options for {@link State.flow}.
+ */
+export interface FlowOptions {
+ /**
+ * Escape leading block markers in text that begins a line.
+ *
+ * Off by default: most callers render an inline run, where a leading `#` or
+ * `-` is not a block marker. Turn it on when the children are written at the
+ * start of a line (a paragraph, a blockquote, a slot).
+ */
+ atLineStart?: boolean
+}
+
/**
* A node handler rule that pairs a match predicate with a handler function.
* When `match` returns true for a node, the associated `handler` is used to render it.
@@ -175,7 +189,7 @@ export type State = {
handlers: Record
- flow: (node: ElementNode, state: State, parent?: ElementNode) => Promise
+ flow: (node: ElementNode, state: State, parent?: ElementNode, options?: FlowOptions) => Promise
one: (node: Node, state: State, parent?: ElementNode, atLineStart?: boolean) => Promise
diff --git a/packages/comark/test/index.test.ts b/packages/comark/test/index.test.ts
index a36983e8e..531e8bdb4 100644
--- a/packages/comark/test/index.test.ts
+++ b/packages/comark/test/index.test.ts
@@ -51,6 +51,7 @@ interface TestCase {
ast: string
html: string
markdown: string
+ markdownHtml: string
timeouts?: {
parse?: number
html?: number
@@ -118,7 +119,7 @@ function extractTestCase(content: string): TestCase {
const { timeouts, body, options, ...frontmatter } = extractFrontmatter(content)
const sections: Record = {}
- const sectionHeaders = [...body.matchAll(/^## (Input|AST|HTML|Markdown)\s*\n\n```(\w+)\n/gm)]
+ const sectionHeaders = [...body.matchAll(/^## (Input|AST|HTML|Markdown HTML|Markdown)\s*\n\n```(\w+)\n/gm)]
for (let i = 0; i < sectionHeaders.length; i++) {
const match = sectionHeaders[i]
@@ -163,6 +164,9 @@ function extractTestCase(content: string): TestCase {
ast: sections.ast || '',
html: sections.html || '',
markdown: sections.markdown || '',
+ // `## Markdown HTML` is optional and falls back to `## Markdown`.
+ // Add it only when `markdown/html` output differs (components, spans, slots, `:br`).
+ markdownHtml: sections['markdown html'] ?? sections.markdown ?? '',
timeouts,
options,
}
@@ -186,9 +190,9 @@ function findMarkdownFiles(dir: string, baseDir: string = dir): string[] {
return files
}
-// Run a single spec: SPEC=SPEC/MDC/inline-component.md pnpm vitest run test/index.test.ts
+// Run a single spec: SPEC=SPEC/COMARK/component.md pnpm vitest run test/index.test.ts
const specDir = join(process.cwd(), 'SPEC')
-const specArg = String(process.env.npm_lifecycle_script || '').split('-- -spec ')[1] || ''
+const specArg = process.env.SPEC || ''
function loadTestCases(): Array<{ file: string; testCase: TestCase }> {
if (specArg) {
@@ -292,6 +296,17 @@ describe('Comark Tests', () => {
expect(result).toBe(expectedMarkdown)
}
)
+
+ it('should render AST to Markdown HTML', async () => {
+ const result = await renderMarkdown(document, {
+ ...(testCase.options || {}),
+ format: 'markdown/html',
+ components: {
+ binding: MarkdownBinding,
+ },
+ })
+ expect(result).toBe(testCase.markdownHtml.trim())
+ })
})
})
})
diff --git a/packages/comark/test/render-markdown-html.test.ts b/packages/comark/test/render-markdown-html.test.ts
new file mode 100644
index 000000000..3718ac2e6
--- /dev/null
+++ b/packages/comark/test/render-markdown-html.test.ts
@@ -0,0 +1,43 @@
+import { describe, expect, it } from 'vitest'
+import { createMarkdownExit } from 'markdown-exit/core'
+import { parseMarkdown } from '../src/index'
+import { render } from '../src/render'
+
+// `markdown/html` output is read by plain CommonMark parsers; SPEC fixtures pin the exact output.
+async function reparse(markdown: string) {
+ const output = await render(await parseMarkdown(markdown), { format: 'markdown/html' })
+ return createMarkdownExit({ html: true }).parse(output, {})
+}
+
+describe('render: markdown/html', () => {
+ it('keeps the markdown inside a component tag parseable', async () => {
+ const tokens = await reparse(
+ ['::steps', '### Create', '', 'Run:', '', '```bash', 'npx create', '```', '', '- a', '- b', '::'].join('\n')
+ )
+
+ const types = tokens.map((token) => token.type)
+ expect(types).toContain('heading_open')
+ expect(types).toContain('fence')
+ expect(types).toContain('bullet_list_open')
+ })
+
+ it('keeps a code block holding indented fences whole', async () => {
+ const code = '::tabs\n :::tabs-item\n ```mdc\n ::callout\n ::\n ```\n :::\n\n::'
+ const tokens = await reparse(`::code-preview\n#code\n\`\`\`\`mdc\n${code}\n\`\`\`\`\n::\n\nAfter`)
+
+ expect(tokens.filter((token) => token.type === 'fence').map((token) => token.content)).toEqual([`${code}\n`])
+ expect(tokens.at(-2)?.content).toBe('After')
+ })
+
+ it('keeps a component in a list item out of the paragraph before it', async () => {
+ const tokens = await reparse('- para\n ::alert\n hi\n ::')
+
+ // A custom tag cannot interrupt a paragraph, so `` must follow its own blank line.
+ const paragraphs = tokens.filter((token) => token.type === 'inline').map((token) => token.content)
+ expect(paragraphs).toEqual(['para', 'hi'])
+ expect(tokens.filter((token) => token.type === 'html_block').map((token) => token.content.trim())).toEqual([
+ '',
+ '',
+ ])
+ })
+})
diff --git a/test/bundle.test.ts b/test/bundle.test.ts
index 8f1c90112..557655dc4 100644
--- a/test/bundle.test.ts
+++ b/test/bundle.test.ts
@@ -77,7 +77,7 @@ describe('package bundle size', { timeout: 60_000 }, () => {
"@comark/react": "43.3k (87 files)",
"@comark/svelte": "51.0k (95 files)",
"@comark/vue": "62.7k (93 files)",
- "comark": "449k (175 files)",
+ "comark": "451k (175 files)",
}
`)
})