Skip to content

Commit d362717

Browse files
authored
feat(core): allow to parse blocks with noCloseToken=true with content from children tokens (#180)
1 parent d96b5a6 commit d362717

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/core/markdown/MarkdownParser.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,18 @@ export class MarkdownParser implements Parser {
186186

187187
if (tokenSpec.noCloseToken) {
188188
this.openNode(schemaSpec, attrs);
189-
let {content} = yfmToken;
190-
if (tokenSpec.prepareContent) {
191-
content = tokenSpec.prepareContent(content);
189+
190+
if (tokenSpec.contentField === 'children' && yfmToken.children?.length) {
191+
this.parseTokens(yfmToken.children);
192+
} else {
193+
let {content} = yfmToken;
194+
if (tokenSpec.prepareContent) {
195+
content = tokenSpec.prepareContent(content);
196+
}
197+
this.addText(content);
192198
}
193-
this.addText(content);
194-
this.closeNode();
195199

200+
this.closeNode();
196201
return;
197202
}
198203

src/core/types/parser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ export interface ParserToken {
2323
code?: boolean;
2424
/** only for tokens with type=block */
2525
prepareContent?: (content: string) => string;
26+
/**
27+
* only for tokens with type=block and noCloseToken=true
28+
* @default 'content'
29+
*/
30+
contentField?: 'content' | 'children';
2631
}

0 commit comments

Comments
 (0)