diff --git a/packages/comark/SPEC/HTML/block+component-ordered-blocks.md b/packages/comark/SPEC/HTML/block+component-ordered-blocks.md
new file mode 100644
index 000000000..078c5df48
--- /dev/null
+++ b/packages/comark/SPEC/HTML/block+component-ordered-blocks.md
@@ -0,0 +1,84 @@
+## Input
+
+```md
+::foo
+
+
+default
+
+#one
+named
+::
+```
+
+## AST
+
+```json
+{
+ "frontmatter": {},
+ "meta": {},
+ "nodes": [
+ [
+ "foo",
+ {},
+ [
+ "div",
+ {
+ "$": {
+ "html": 1,
+ "block": 1
+ }
+ },
+ "default"
+ ],
+ [
+ "template",
+ {
+ "name": "one"
+ },
+ "named"
+ ]
+ ]
+ ]
+}
+```
+
+## HTML
+
+```html
+
+
+ default
+
+
+ named
+
+
+```
+
+## Markdown
+
+```md
+::foo
+
+default
+
+
+#one
+named
+::
+```
diff --git a/packages/comark/src/internal/parse/tree.ts b/packages/comark/src/internal/parse/tree.ts
index 06c813fd7..dd8859970 100644
--- a/packages/comark/src/internal/parse/tree.ts
+++ b/packages/comark/src/internal/parse/tree.ts
@@ -310,7 +310,11 @@ function processBlockChildrenWithSlots(
const result = processToken(tokens, i, state)
if (result) {
- pushChild(result.node)
+ for (const frame of state.htmlStack) frame.block = true
+ if (result.node !== undefined) {
+ const free = result.siblingOfHtmlStack ? result.node : deliverBlock(state, result.node)
+ pushChild(free)
+ }
i = result.nextIndex
} else {
i += 1
diff --git a/packages/comark/src/internal/stringify/handlers/html.ts b/packages/comark/src/internal/stringify/handlers/html.ts
index 0a7dc61ae..43bb9b48b 100644
--- a/packages/comark/src/internal/stringify/handlers/html.ts
+++ b/packages/comark/src/internal/stringify/handlers/html.ts
@@ -113,7 +113,10 @@ export async function html(node: ElementNode, state: State, parent?: ElementNode
content = '\n' + paddNoneHtmlContent(content, state, String(tag)).trimEnd() + '\n'
}
- return `<${tag}${attrs}>${content}${tag}>` + (!parent && !isInline ? state.context.blockSeparator : '')
+ // Components and slots need a separator between block HTML and the next block.
+ const endsBlock = !parent || (!oneLiner && !state.context.html && parent[1].$?.html !== 1)
+
+ return `<${tag}${attrs}>${content}${tag}>` + (endsBlock && !isInline ? state.context.blockSeparator : '')
}
// Literal-content tags whose body must be rendered verbatim (no indentation