]> BookStack Code Mirror - bookstack/blob - resources/js/editor/schema.js
Added strike, sup and sub marks
[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 markStrike = {
36     parseDOM: [{tag: "s"}, {tag: "strike"}, {style: "text-decoration=line-through"}],
37     toDOM() {
38         return ["span", {style: "text-decoration: line-through;"}, 0];
39     }
40 };
41
42 const markSuperscript = {
43     parseDOM: [{tag: "sup"}],
44     toDOM() {
45         return ["sup", 0];
46     }
47 };
48
49 const markSubscript = {
50     parseDOM: [{tag: "sub"}],
51     toDOM() {
52         return ["sub", 0];
53     }
54 };
55
56 const customNodes = baseNodes.append({
57     callout: nodeCallout,
58 });
59
60 const customMarks = baseMarks.append({
61     underline: markUnderline,
62     strike: markStrike,
63     superscript: markSuperscript,
64     subscript: markSubscript,
65 });
66
67 const schema = new Schema({
68     nodes: customNodes,
69     marks: customMarks,
70 })
71
72 export default schema;