]> BookStack Code Mirror - bookstack/blob - resources/js/editor/schema-marks.js
c8b8da3464a20052dd73b79c771774b756f342f2
[bookstack] / resources / js / editor / schema-marks.js
1 const link = {
2     attrs: {
3         href: {},
4         title: {default: null}
5     },
6     inclusive: false,
7     parseDOM: [{
8         tag: "a[href]", getAttrs: function getAttrs(dom) {
9             return {href: dom.getAttribute("href"), title: dom.getAttribute("title")}
10         }
11     }],
12     toDOM: function toDOM(node) {
13         const ref = node.attrs;
14         const href = ref.href;
15         const title = ref.title;
16         return ["a", {href: href, title: title}, 0]
17     }
18 };
19
20 const em = {
21     parseDOM: [{tag: "i"}, {tag: "em"}, {style: "font-style=italic"}],
22     toDOM() {
23         return ["em", 0]
24     }
25 };
26
27 const strong = {
28     parseDOM: [{tag: "strong"},
29         // This works around a Google Docs misbehavior where
30         // pasted content will be inexplicably wrapped in `<b>`
31         // tags with a font-weight normal.
32         {
33             tag: "b", getAttrs: function (node) {
34                 return node.style.fontWeight != "normal" && null;
35             }
36         },
37         {
38             style: "font-weight", getAttrs: function (value) {
39                 return /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null;
40             }
41         }],
42     toDOM() {
43         return ["strong", 0]
44     }
45 };
46
47 const code = {
48     parseDOM: [{tag: "code"}],
49     toDOM() {
50         return ["code", 0]
51     }
52 };
53
54 const underline = {
55     parseDOM: [{tag: "u"}, {style: "text-decoration=underline"}],
56     toDOM() {
57         return ["span", {style: "text-decoration: underline;"}, 0];
58     }
59 };
60
61 const strike = {
62     parseDOM: [{tag: "s"}, {tag: "strike"}, {style: "text-decoration=line-through"}],
63     toDOM() {
64         return ["span", {style: "text-decoration: line-through;"}, 0];
65     }
66 };
67
68 const superscript = {
69     parseDOM: [{tag: "sup"}],
70     toDOM() {
71         return ["sup", 0];
72     }
73 };
74
75 const subscript = {
76     parseDOM: [{tag: "sub"}],
77     toDOM() {
78         return ["sub", 0];
79     }
80 };
81
82 const text_color = {
83     attrs: {
84         color: {},
85     },
86     parseDOM: [{
87         style: 'color',
88         getAttrs(color) {
89             return {color}
90         }
91     }],
92     toDOM(node) {
93         return ['span', {style: `color: ${node.attrs.color};`}, 0];
94     }
95 };
96
97 const background_color = {
98     attrs: {
99         color: {},
100     },
101     parseDOM: [{
102         style: 'background-color',
103         getAttrs(color) {
104             return {color}
105         }
106     }],
107     toDOM(node) {
108         return ['span', {style: `background-color: ${node.attrs.color};`}, 0];
109     }
110 };
111
112 const marks = {
113     link,
114     em,
115     strong,
116     code,
117     underline,
118     strike,
119     superscript,
120     subscript,
121     text_color,
122     background_color,
123 };
124
125 export default marks;