Skip to content

Commit 045c49d

Browse files
committed
fix: treat heading children as inline elements
1 parent 1107223 commit 045c49d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/runtime/stringify/mdc-remark.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ const mdcRemarkNodeHandlers = {
153153
}
154154

155155
const isInlineElement = (parent?.children || [])
156-
.some(child => child.type === 'text') || ['p', 'li', 'strong', 'em', 'span'].includes(parent?.tagName)
156+
.some(child => child.type === 'text') || ['p', 'li', 'strong', 'em', 'span', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'].includes(parent?.tagName)
157157
if (isInlineElement) {
158158
return {
159159
type: mdastTextComponentType,

test/markdown/markdown.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { expect, it } from 'vitest'
2+
import { parseMarkdown } from '../utils/parser'
3+
import { stringifyMarkdown } from '../../src/runtime/stringify'
4+
5+
6+
it('Element in heading', async () => {
7+
const { body } = await parseMarkdown('### :hello')
8+
expect(body).toHaveProperty('type', 'root')
9+
10+
expect(body.children).toHaveLength(1)
11+
expect(body.children[0]).toMatchObject({
12+
type: 'element',
13+
tag: 'h3',
14+
props: { id: '' },
15+
children: [{ type: 'element', tag: 'hello', props: {}, children: [] }],
16+
})
17+
18+
const result = await stringifyMarkdown(body)
19+
expect(result).toMatchInlineSnapshot(`
20+
"### :hello\n"
21+
`)
22+
})

0 commit comments

Comments
 (0)