1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Got callouts about working, simplified markdown setup

This commit is contained in:
Dan Brown
2022-01-07 21:22:07 +00:00
parent 0fb8ba00a5
commit 81dfe9c345
4 changed files with 60 additions and 156 deletions

View File

@ -0,0 +1,22 @@
import schema from "./schema";
import markdownit from "markdown-it";
import {MarkdownParser, defaultMarkdownParser} from "prosemirror-markdown";
import {htmlToDoc} from "./util";
const tokens = defaultMarkdownParser.tokens;
// This is really a placeholder on the object to allow the below
// parser.tokenHandlers.html_block hack to work as desired.
tokens.html_block = {block: "callout", noCloseToken: true};
const tokenizer = markdownit("commonmark", {html: true});
const parser = new MarkdownParser(schema, tokenizer, tokens);
parser.tokenHandlers.html_block = function(state, tok, tokens, i) {
const contentDoc = htmlToDoc(tok.content || '');
for (const node of contentDoc.content.content) {
state.addNode(node.type, node.attrs, node.content);
}
};
export default parser;