]> BookStack Code Mirror - bookstack/blob - resources/js/editor/schema.js
Fixed issue with new nodes being callouts
[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'}, priority: 75,},
16         {tag: 'p.callout.success', attrs: {type: 'success'}, priority: 75,},
17         {tag: 'p.callout.danger', attrs: {type: 'danger'}, priority: 75,},
18         {tag: 'p.callout.warning', attrs: {type: 'warning'}, priority: 75,},
19         {tag: 'p.callout', attrs: {type: 'info'}, priority: 75},
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.append({
28     callout: nodeCallout,
29 });
30
31 const schema = new Schema({
32     nodes: customNodes,
33     marks: basicSchema.spec.marks
34 })
35
36 export default schema;