]> BookStack Code Mirror - bookstack/blob - resources/js/editor/schema.js
Got underline working in editor
[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 const baseMarks = basicSchema.spec.marks;
7
8 const nodeCallout = {
9     attrs: {
10         type: {default: 'info'},
11     },
12     content: "inline*",
13     group: "block",
14     defining: true,
15     parseDOM: [
16         {tag: 'p.callout.info', attrs: {type: 'info'}, priority: 75,},
17         {tag: 'p.callout.success', attrs: {type: 'success'}, priority: 75,},
18         {tag: 'p.callout.danger', attrs: {type: 'danger'}, priority: 75,},
19         {tag: 'p.callout.warning', attrs: {type: 'warning'}, priority: 75,},
20         {tag: 'p.callout', attrs: {type: 'info'}, priority: 75},
21     ],
22     toDOM(node) {
23         const type = node.attrs.type || 'info';
24         return ['p', {class: 'callout ' + type}, 0];
25     }
26 };
27
28 const markUnderline = {
29     parseDOM: [{tag: "u"}, {style: "text-decoration=underline"}],
30     toDOM() {
31         return ["span", {style: "text-decoration: underline;"}, 0];
32     }
33 }
34
35 const customNodes = baseNodes.append({
36     callout: nodeCallout,
37 });
38
39 const customMarks = baseMarks.append({
40     underline: markUnderline,
41 });
42
43 const schema = new Schema({
44     nodes: customNodes,
45     marks: customMarks,
46 })
47
48 export default schema;