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