1
0
mirror of https://github.com/writeas/writefreely synced 2024-12-12 08:36:14 +01:00
writefreely/prose/markdownParser.js

58 lines
1.6 KiB
JavaScript
Raw Normal View History

import { MarkdownParser } from "prosemirror-markdown";
import markdownit from "markdown-it";
import { writeFreelySchema } from "./schema";
export const writeFreelyMarkdownParser = new MarkdownParser(
2021-01-08 00:33:35 +01:00
writeFreelySchema,
markdownit("commonmark", { html: true }),
{
blockquote: { block: "blockquote" },
2021-01-08 00:33:35 +01:00
paragraph: { block: "paragraph" },
list_item: { block: "list_item" },
bullet_list: { block: "bullet_list" },
ordered_list: {
block: "ordered_list",
getAttrs: (tok) => ({ order: +tok.attrGet("start") || 1 }),
},
heading: {
block: "heading",
getAttrs: (tok) => ({ level: +tok.tag.slice(1) }),
},
code_block: { block: "code_block", noCloseToken: true },
fence: {
block: "code_block",
getAttrs: (tok) => ({ params: tok.info || "" }),
noCloseToken: true,
},
hr: { node: "horizontal_rule" },
2021-01-08 00:33:35 +01:00
image: {
node: "image",
getAttrs: (tok) => ({
src: tok.attrGet("src"),
title: tok.attrGet("title") || null,
alt: (tok.children !== null && typeof tok.children[0] !== 'undefined' ? tok.children[0].content : null),
2021-01-08 00:33:35 +01:00
}),
},
hardbreak: { node: "hard_break" },
2021-01-08 00:33:35 +01:00
em: { mark: "em" },
strong: { mark: "strong" },
link: {
mark: "link",
getAttrs: (tok) => ({
href: tok.attrGet("href"),
title: tok.attrGet("title") || null,
}),
},
code_inline: { mark: "code", noCloseToken: true },
html_block: {
node: "readmore",
getAttrs(token) {
// TODO: Give different attributes depending on the token content
return {};
},
},
2021-01-08 00:33:35 +01:00
}
);