]> BookStack Code Mirror - bookstack/blob - resources/js/editor/schema.js
7c6a11cb9db1959b9a60612b282f3df1dab4cf54
[bookstack] / resources / js / editor / schema.js
1 import {Schema} from "prosemirror-model";
2 import {schema as basicSchema} from "prosemirror-schema-basic";
3 import {addListNodes} from "prosemirror-schema-list";
4
5 const baseNodes = addListNodes(basicSchema.spec.nodes, "paragraph block*", "block");
6
7 const nodeCallout = {
8     attrs: {
9         type: {default: 'info'},
10     },
11     content: "inline*",
12     group: "block",
13     defining: true,
14     parseDOM: [
15         {tag: 'p.callout.info', attrs: {type: 'info'}},
16         {tag: 'p.callout.success', attrs: {type: 'success'}},
17         {tag: 'p.callout.danger', attrs: {type: 'danger'}},
18         {tag: 'p.callout.warning', attrs: {type: 'warning'}},
19         {tag: 'p.callout', attrs: {type: 'info'}},
20     ],
21     toDOM: function(node) {
22         const type = node.attrs.type || 'info';
23         return ['p', {class: 'callout ' + type}, 0];
24     }
25 };
26
27 const customNodes = baseNodes.prepend({
28     callout: nodeCallout,
29 });
30
31 const schema = new Schema({
32     nodes: customNodes,
33     marks: basicSchema.spec.marks
34 })
35
36 export default schema;