From 8890c81a9f67949aa8aeafc73e6bb3efdafeb847 Mon Sep 17 00:00:00 2001 From: Yuriy Demidov Date: Fri, 26 Jan 2024 12:17:25 +0300 Subject: [PATCH] feat(core): allow to parse blocks with noCloseToken=true with content from children tokens (#180) --- src/core/markdown/MarkdownParser.ts | 15 ++++++++++----- src/core/types/parser.ts | 5 +++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/core/markdown/MarkdownParser.ts b/src/core/markdown/MarkdownParser.ts index 2654f2a1..34924925 100644 --- a/src/core/markdown/MarkdownParser.ts +++ b/src/core/markdown/MarkdownParser.ts @@ -186,13 +186,18 @@ export class MarkdownParser implements Parser { if (tokenSpec.noCloseToken) { this.openNode(schemaSpec, attrs); - let {content} = yfmToken; - if (tokenSpec.prepareContent) { - content = tokenSpec.prepareContent(content); + + if (tokenSpec.contentField === 'children' && yfmToken.children?.length) { + this.parseTokens(yfmToken.children); + } else { + let {content} = yfmToken; + if (tokenSpec.prepareContent) { + content = tokenSpec.prepareContent(content); + } + this.addText(content); } - this.addText(content); - this.closeNode(); + this.closeNode(); return; } diff --git a/src/core/types/parser.ts b/src/core/types/parser.ts index b2b24cff..3292d8c4 100644 --- a/src/core/types/parser.ts +++ b/src/core/types/parser.ts @@ -23,4 +23,9 @@ export interface ParserToken { code?: boolean; /** only for tokens with type=block */ prepareContent?: (content: string) => string; + /** + * only for tokens with type=block and noCloseToken=true + * @default 'content' + */ + contentField?: 'content' | 'children'; }