1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
import { DOMOutputSpec, MarkSpec } from 'prosemirror-model';
import { ClientUtils } from '../../../../ClientUtils';
import { Utils } from '../../../../Utils';
const emDOM: DOMOutputSpec = ['em', 0];
const strongDOM: DOMOutputSpec = ['strong', 0];
const codeDOM: DOMOutputSpec = ['code', 0];
// :: Object [Specs](#model.MarkSpec) for the marks in the schema.
export const marks: { [index: string]: MarkSpec } = {
splitter: {
attrs: {
id: { default: '' },
},
toDOM() {
return ['div', { className: 'dummy' }, 0];
},
},
// :: MarkSpec an autoLinkAnchor. These are automatically generated anchors to "published" documents based on the anchor text matching the
// published document's title.
// NOTE: unlike linkAnchors, the autoLinkAnchor's href's indicate the target anchor of the hyperlink and NOT the source. This is because
// automatic links do not create a text selection Marker document for the source anchor, but use the text document itself. Since
// multiple automatic links can be created each having the same source anchor (the whole document), the target href of the link is needed to
// disambiguate links from one another.
// Rendered and parsed as an `<a>`
// element.
autoLinkAnchor: {
attrs: {
allAnchors: { default: [] as { href: string; title: string; anchorId: string }[] },
title: { default: null },
},
inclusive: false,
parseDOM: [
{
tag: 'a[href]',
getAttrs: dom => {
return {
title: dom.getAttribute('title'),
};
},
},
],
toDOM: node => {
const targethrefs = node.attrs.allAnchors.reduce((p: string, item: { href: string; title: string; anchorId: string }) => (p ? p + ' ' + item.href : item.href), '');
const anchorids = node.attrs.allAnchors.reduce((p: string, item: { href: string; title: string; anchorId: string }) => (p ? p + ' ' + item.anchorId : item.anchorId), '');
return ['a', { id: Utils.GenerateGuid(), class: anchorids, 'data-targethrefs': targethrefs, /* 'data-noPreview': 'true', */ 'data-linkdoc': node.attrs.linkDoc, title: node.attrs.title, style: `background: lightBlue` }, 0];
},
},
noAutoLinkAnchor: {
attrs: {},
inclusive: false,
parseDOM: [
{
tag: 'div',
getAttrs: dom => {
return {
noAutoLink: dom.getAttribute('data-noAutoLink'),
};
},
},
],
toDOM() {
return ['span', { 'data-noAutoLink': 'true' }, 0];
},
},
// :: MarkSpec A linkAnchor. The anchor can have multiple links, where each linkAnchor specifies an href to the URL of the source selection Marker text,
// and a title for use in menus and hover. `title`
// defaults to the empty string. Rendered and parsed as an `<a>`
// element.
linkAnchor: {
attrs: {
allAnchors: { default: [] as { href: string; title: string; anchorId: string }[] },
title: { default: null },
noPreview: { default: false },
fontSize: { default: null },
docref: { default: false }, // flags whether the linked text comes from a document within Dash. If so, an attribution label is appended after the text
},
inclusive: false,
parseDOM: [
{
tag: 'a[href]',
getAttrs: dom => {
return {
title: dom.getAttribute('title'),
noPreview: dom.getAttribute('noPreview'),
};
},
},
],
toDOM: node => {
const targethrefs = node.attrs.allAnchors.reduce((p: string, item: { href: string; title: string; anchorId: string }) => (p ? p + ' ' + item.href : item.href), '');
const anchorids = node.attrs.allAnchors.reduce((p: string, item: { href: string; title: string; anchorId: string }) => (p ? p + ' ' + item.anchorId : item.anchorId), '');
return node.attrs.docref && node.attrs.title
? [
'a',
['span', 0],
[
'span',
{
...node.attrs,
class: 'prosemirror-attribution',
'data-targethrefs': targethrefs,
href: node.attrs.allAnchors[0].href,
style: `font-size: ${node.attrs.fontSize}`,
},
node.attrs.title,
],
]
: ['a', { id: '' + Utils.GenerateGuid(), class: anchorids, 'data-targethrefs': targethrefs, title: node.attrs.title, 'data-noPreview': node.attrs.noPreview, style: `text-decoration: underline; cursor: default` }, 0];
},
},
/** FONT SIZES */
pFontSize: {
attrs: { fontSize: { default: '10px' } },
parseDOM: [
{
tag: 'span',
getAttrs: dom => {
if (!dom.style.fontSize) return false;
return { fontSize: dom.style.fontSize ? dom.style.fontSize.toString() : '' };
},
},
],
toDOM: node => (node.attrs.fontSize ? ['span', { style: `font-size: ${node.attrs.fontSize};` }] : ['span', 0]),
},
/* FONTS */
pFontFamily: {
attrs: { fontFamily: { default: '' } },
parseDOM: [
{
tag: 'span',
getAttrs: dom => {
const cstyle = dom.style.fontFamily;
if (!cstyle) return false;
return { fontFamily: cstyle };
},
},
],
toDOM: node => (node.attrs.fontFamily ? ['span', { style: `font-family: "${node.attrs.fontFamily}";` }] : ['span', 0]),
},
// :: MarkSpec Coloring on text. Has `color` attribute that defined the color of the marked text.
pFontColor: {
attrs: { fontColor: { default: '' } },
inclusive: true,
parseDOM: [
{
tag: 'span',
getAttrs: dom => {
if (!dom.style.color) return false;
return { color: dom.getAttribute('color') };
},
},
],
toDOM: node => (node.attrs.fontColor ? ['span', { style: 'color:' + node.attrs.fontColor }] : ['span', 0]),
},
pFontHighlight: {
attrs: {
fontHighlight: { default: 'transparent' },
},
inclusive: true,
parseDOM: [
{
tag: 'span',
getAttrs: dom => {
if (!dom.getAttribute('background-color')) return false;
return { fontHighlight: dom.getAttribute('background-color') };
},
},
],
toDOM: node => {
return node.attrs.fontHighlight ? ['span', { style: 'background-color:' + node.attrs.fontHighlight }] : ['span', { style: 'background-color: transparent' }];
},
},
// :: MarkSpec An emphasis mark. Rendered as an `<em>` element.
// Has parse rules that also match `<i>` and `font-style: italic`.
em: {
parseDOM: [{ tag: 'i' }, { tag: 'em' }, { style: 'font-style: italic' }],
toDOM() {
return emDOM;
},
},
// :: MarkSpec A strong mark. Rendered as `<strong>`, parse rules
// also match `<b>` and `font-weight: bold`.
strong: {
parseDOM: [{ tag: 'strong' }, { tag: 'b' }, { style: 'font-weight' }],
toDOM() {
return strongDOM;
},
},
strikethrough: {
parseDOM: [{ tag: 'strike' }, { style: 'text-decoration=line-through' }, { style: 'text-decoration-line=line-through' }],
toDOM: () => [
'span',
{
style: 'text-decoration-line:line-through',
},
],
},
subscript: {
excludes: 'superscript',
parseDOM: [{ tag: 'sub' }, { style: 'vertical-align=sub' }],
toDOM: () => ['sub'],
},
superscript: {
excludes: 'subscript',
parseDOM: [{ tag: 'sup' }, { style: 'vertical-align=super' }],
toDOM: () => ['sup'],
},
mbulletType: {
attrs: {
bulletType: { default: 'decimal' },
},
toDOM: node => {
return [
'span',
{
style: `background: ${node.attrs.bulletType === 'decimal' ? 'yellow' : node.attrs.bulletType === 'upper-alpha' ? 'blue' : 'green'}`,
},
];
},
},
summarizeInclusive: {
parseDOM: [
{
tag: 'span',
getAttrs: p => {
if (p.getAttribute('data-summarizeInclusive')) return [[{ style: 'data-summarizeInclusive: true' }]];
return false;
},
},
],
inclusive: true,
toDOM() {
return [
'span',
{
'data-summarizeInclusive': 'true',
style: 'text-decoration: underline; text-decoration-style: dotted; text-decoration-color: rgba(204, 206, 210)',
},
];
},
},
summarize: {
inclusive: false,
parseDOM: [
{
tag: 'span',
getAttrs: p => {
if (typeof p !== 'string') {
const style = getComputedStyle(p);
if (style.textDecoration === 'underline') return null;
if (p.parentElement?.outerHTML.indexOf('text-decoration: underline') !== -1 && p.parentElement?.outerHTML.indexOf('text-decoration-style: dotted') !== -1) {
return null;
}
}
return false;
},
},
],
toDOM() {
return [
'span',
{
style: 'text-decoration: underline; text-decoration-style: dotted; text-decoration-color: rgba(204, 206, 210, 0.92)',
},
];
},
},
underline: {
parseDOM: [
{
tag: 'span',
getAttrs: p => {
if (typeof p !== 'string') {
const style = getComputedStyle(p);
if (style.textDecoration === 'underline' || p.parentElement?.outerHTML.indexOf('text-decoration-style:line') !== -1) {
return null;
}
}
return false;
},
},
// { style: "text-decoration=underline" }
],
toDOM: () => [
'span',
{
style: 'text-decoration:underline;text-decoration-style:line',
},
],
},
search_highlight: {
attrs: {
selected: { default: false },
},
parseDOM: [{ style: 'background: lightGray' }],
toDOM: node => {
return ['span', { style: `background: ${node.attrs.selected ? 'orange' : 'lightGray'}` }];
},
},
// the id of the user who entered the text
user_mark: {
attrs: {
userid: { default: '' },
modified: { default: 'when?' }, // 1 second intervals since 1970
},
excludes: 'user_mark',
group: 'inline',
toDOM: node => {
const uid = node.attrs.userid.replace(/\./g, '').replace(/@/g, '');
const min = Math.round(node.attrs.modified / 60);
const hr = Math.round(min / 60);
const day = Math.round(hr / 60 / 24);
const remote = node.attrs.userid !== ClientUtils.CurrentUserEmail() ? ' UM-remote' : '';
return ['span', { class: 'UM-' + uid + remote + ' UM-min-' + min + ' UM-hr-' + hr + ' UM-day-' + day }, 0];
},
},
// :: MarkSpec Code font mark. Represented as a `<code>` element.
code: {
parseDOM: [{ tag: 'code' }],
toDOM() {
return codeDOM;
},
},
};
|