|
1 | 1 | import type { ComarkElementAttributes, ComarkNode } from 'comark' |
2 | | -import { htmlToComarkNodes, parseInlineHtmlTag } from './html/index.ts' |
| 2 | +import { htmlToComarkNodes, parseInlineHtmlTag, VOID_ELEMENTS } from './html/index.ts' |
3 | 3 |
|
4 | 4 | // Mapping from token types to tag names |
5 | 5 | const BLOCK_TAG_MAP: Record<string, string> = { |
@@ -289,11 +289,18 @@ function processBlockToken( |
289 | 289 | return { node: [null, {}, inner] as unknown as ComarkNode, nextIndex: startIndex + 1 } |
290 | 290 | } |
291 | 291 |
|
292 | | - const children = processBlockChildren(tokens, startIndex + 1, 'html_block_close', false, false, false, state) |
293 | | - const [node1] = htmlToComarkNodes(content) |
| 292 | + const htmlNodes = htmlToComarkNodes(content) |
| 293 | + const [node1] = htmlNodes |
294 | 294 | if (!node1) { |
295 | 295 | return { node: null, nextIndex: startIndex + 1 } |
296 | 296 | } |
| 297 | + |
| 298 | + const isVoid = Array.isArray(node1) && VOID_ELEMENTS.has(node1[0] as string) |
| 299 | + if (isVoid) { |
| 300 | + return { node: node1, nextIndex: startIndex + 1 } |
| 301 | + } |
| 302 | + |
| 303 | + const children = processBlockChildren(tokens, startIndex + 1, 'html_block_close', false, false, false, state) |
297 | 304 | const node = [node1[0]!, node1[1]! as ComarkElementAttributes, ...children.nodes] as ComarkNode |
298 | 305 |
|
299 | 306 | return { node, nextIndex: children.nextIndex + 1 } |
|
0 commit comments