Skip to content

Commit

Permalink
feat(core): allow to parse blocks with noCloseToken=true with content…
Browse files Browse the repository at this point in the history
… from children tokens
  • Loading branch information
d3m1d0v committed Jan 25, 2024
1 parent d96b5a6 commit 8d5ae69
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/core/markdown/MarkdownParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions src/core/types/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

0 comments on commit 8d5ae69

Please sign in to comment.