@atlaskit/editor-jira-transformer 8.2.4 → 8.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/collapse-whitespace.js +0 -3
- package/dist/cjs/emojiHelper.js +0 -1
- package/dist/cjs/fix-doc.js +8 -25
- package/dist/cjs/index.js +63 -126
- package/dist/cjs/parse-html.js +0 -5
- package/dist/cjs/schema.js +0 -1
- package/dist/cjs/utils.js +25 -99
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/fix-doc.js +8 -24
- package/dist/es2019/index.js +29 -92
- package/dist/es2019/parse-html.js +0 -2
- package/dist/es2019/utils.js +22 -80
- package/dist/es2019/version.json +1 -1
- package/dist/esm/fix-doc.js +8 -24
- package/dist/esm/index.js +63 -118
- package/dist/esm/parse-html.js +0 -2
- package/dist/esm/utils.js +26 -90
- package/dist/esm/version.json +1 -1
- package/package.json +10 -8
- package/report.api.md +13 -0
package/dist/cjs/parse-html.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = _default;
|
|
9
|
-
|
|
10
8
|
var _collapseWhitespace = _interopRequireDefault(require("./collapse-whitespace"));
|
|
11
|
-
|
|
12
9
|
function _default(fragment) {
|
|
13
10
|
var html = "<!doctype html><html><body>".concat(fragment, "</body></html>");
|
|
14
11
|
var parser = new window.DOMParser();
|
|
@@ -16,7 +13,6 @@ function _default(fragment) {
|
|
|
16
13
|
(0, _collapseWhitespace.default)(tree.documentElement, isBlock);
|
|
17
14
|
return tree;
|
|
18
15
|
}
|
|
19
|
-
|
|
20
16
|
function isBlock(node) {
|
|
21
17
|
// these blocks are mainly used to collapse whitespace between the blocks
|
|
22
18
|
// (preventing spurious text nodes of ' ')
|
|
@@ -72,6 +68,5 @@ function isBlock(node) {
|
|
|
72
68
|
case 'UL':
|
|
73
69
|
return true;
|
|
74
70
|
}
|
|
75
|
-
|
|
76
71
|
return false;
|
|
77
72
|
}
|
package/dist/cjs/schema.js
CHANGED
package/dist/cjs/utils.js
CHANGED
|
@@ -7,21 +7,13 @@ exports.bfsOrder = bfsOrder;
|
|
|
7
7
|
exports.convert = convert;
|
|
8
8
|
exports.ensureBlocks = ensureBlocks;
|
|
9
9
|
exports.ensureInline = void 0;
|
|
10
|
-
|
|
11
10
|
var _adfSchema = require("@atlaskit/adf-schema");
|
|
12
|
-
|
|
13
11
|
var _schemaJira = require("@atlaskit/adf-schema/schema-jira");
|
|
14
|
-
|
|
15
12
|
var _prosemirrorModel = require("prosemirror-model");
|
|
16
|
-
|
|
17
13
|
var _emojiHelper = require("./emojiHelper");
|
|
18
|
-
|
|
19
14
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
20
|
-
|
|
21
15
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
22
|
-
|
|
23
16
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
24
|
-
|
|
25
17
|
/**
|
|
26
18
|
* Ensure that each node in the fragment is a block, wrapping
|
|
27
19
|
* in a block node if necessary.
|
|
@@ -30,18 +22,18 @@ function ensureBlocks(fragment, schema, nodeType) {
|
|
|
30
22
|
// If all the nodes are inline, we want to wrap in a single paragraph.
|
|
31
23
|
if (schema.nodes.paragraph.validContent(fragment)) {
|
|
32
24
|
return _prosemirrorModel.Fragment.fromArray([schema.nodes.paragraph.createChecked({}, fragment)]);
|
|
33
|
-
}
|
|
34
|
-
// We convert each (if any) inline nodes to blocks.
|
|
25
|
+
}
|
|
35
26
|
|
|
27
|
+
// Either all the nodes are blocks, or a mix of inline and blocks.
|
|
28
|
+
// We convert each (if any) inline nodes to blocks.
|
|
29
|
+
var blockNodes = [];
|
|
36
30
|
|
|
37
|
-
|
|
31
|
+
// Following if condition has been added as fix for #ED-3431.
|
|
38
32
|
// First child of list-item should be paragraph,
|
|
39
33
|
// if that is not the case paragraph requires to be added.
|
|
40
|
-
|
|
41
34
|
if (nodeType && nodeType === schema.nodes.listItem && fragment.firstChild && (fragment.firstChild.type === schema.nodes.bulletList || fragment.firstChild.type === schema.nodes.orderedList)) {
|
|
42
35
|
blockNodes.push(schema.nodes.paragraph.createAndFill());
|
|
43
36
|
}
|
|
44
|
-
|
|
45
37
|
fragment.forEach(function (child) {
|
|
46
38
|
if (child.isBlock) {
|
|
47
39
|
blockNodes.push(child);
|
|
@@ -51,11 +43,10 @@ function ensureBlocks(fragment, schema, nodeType) {
|
|
|
51
43
|
});
|
|
52
44
|
return _prosemirrorModel.Fragment.fromArray(blockNodes);
|
|
53
45
|
}
|
|
46
|
+
|
|
54
47
|
/**
|
|
55
48
|
* This function will convert all content to inline nodes
|
|
56
49
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
50
|
var ensureInline = function ensureInline(schema, content, supportedMarks) {
|
|
60
51
|
var result = [];
|
|
61
52
|
content.forEach(function (node) {
|
|
@@ -65,74 +56,59 @@ var ensureInline = function ensureInline(schema, content, supportedMarks) {
|
|
|
65
56
|
});
|
|
66
57
|
result.push(node.mark(filteredMarks));
|
|
67
58
|
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
59
|
+
}
|
|
60
|
+
// We replace an non-inline node with UnsupportedInline node
|
|
71
61
|
result.push(schema.text(node.textContent));
|
|
72
62
|
});
|
|
73
63
|
return _prosemirrorModel.Fragment.fromArray(result);
|
|
74
64
|
};
|
|
75
|
-
|
|
76
65
|
exports.ensureInline = ensureInline;
|
|
77
|
-
|
|
78
66
|
function convert(content, node, schema) {
|
|
79
67
|
// text
|
|
80
68
|
if (node.nodeType === Node.TEXT_NODE) {
|
|
81
69
|
var text = node.textContent;
|
|
82
70
|
return text ? schema.text(text) : null;
|
|
83
|
-
}
|
|
84
|
-
|
|
71
|
+
}
|
|
85
72
|
|
|
73
|
+
// marks and nodes
|
|
86
74
|
if (node instanceof HTMLElement) {
|
|
87
75
|
var tag = node.tagName.toUpperCase();
|
|
88
|
-
|
|
89
76
|
switch (tag) {
|
|
90
77
|
// Marks
|
|
91
78
|
case 'DEL':
|
|
92
79
|
if (!(0, _schemaJira.isSchemaWithAdvancedTextFormattingMarks)(schema)) {
|
|
93
80
|
return null;
|
|
94
81
|
}
|
|
95
|
-
|
|
96
82
|
return addMarks(content, [schema.marks.strike.create()]);
|
|
97
|
-
|
|
98
83
|
case 'B':
|
|
99
84
|
return addMarks(content, [schema.marks.strong.create()]);
|
|
100
|
-
|
|
101
85
|
case 'EM':
|
|
102
86
|
return addMarks(content, [schema.marks.em.create()]);
|
|
103
|
-
|
|
104
87
|
case 'TT':
|
|
105
88
|
if (!(0, _schemaJira.isSchemaWithAdvancedTextFormattingMarks)(schema)) {
|
|
106
89
|
return null;
|
|
107
90
|
}
|
|
108
|
-
|
|
109
91
|
return addMarks(content, [schema.marks.code.create()]);
|
|
110
|
-
|
|
111
92
|
case 'SUB':
|
|
112
93
|
case 'SUP':
|
|
113
94
|
if (!(0, _schemaJira.isSchemaWithSubSupMark)(schema)) {
|
|
114
95
|
return null;
|
|
115
96
|
}
|
|
116
|
-
|
|
117
97
|
var type = tag === 'SUB' ? 'sub' : 'sup';
|
|
118
98
|
return addMarks(content, [schema.marks.subsup.create({
|
|
119
99
|
type: type
|
|
120
100
|
})]);
|
|
121
|
-
|
|
122
101
|
case 'INS':
|
|
123
102
|
return addMarks(content, [schema.marks.underline.create()]);
|
|
124
|
-
|
|
125
103
|
case 'FONT':
|
|
126
104
|
if (!(0, _schemaJira.isSchemaWithTextColor)(schema)) {
|
|
127
105
|
return null;
|
|
128
106
|
}
|
|
129
|
-
|
|
130
107
|
var color = (0, _adfSchema.normalizeHexColor)(node.getAttribute('color'), '#333333');
|
|
131
108
|
return color ? addMarks(content, [schema.marks.textColor.create({
|
|
132
109
|
color: color
|
|
133
110
|
})]) : content;
|
|
134
111
|
// Nodes
|
|
135
|
-
|
|
136
112
|
case 'A':
|
|
137
113
|
if (node.className === 'user-hover' && (0, _schemaJira.isSchemaWithMentions)(schema)) {
|
|
138
114
|
return schema.nodes.mention.createChecked({
|
|
@@ -140,18 +116,15 @@ function convert(content, node, schema) {
|
|
|
140
116
|
text: node.textContent
|
|
141
117
|
});
|
|
142
118
|
}
|
|
143
|
-
|
|
144
119
|
if (node.className.match('jira-issue-macro-key') || !content || !(0, _schemaJira.isSchemaWithLinks)(schema)) {
|
|
145
120
|
return null;
|
|
146
121
|
}
|
|
147
|
-
|
|
148
122
|
var href = node.getAttribute('href');
|
|
149
123
|
var title = node.getAttribute('title');
|
|
150
124
|
return href ? addMarks(content, [schema.marks.link.create({
|
|
151
125
|
href: href,
|
|
152
126
|
title: title
|
|
153
127
|
})]) : content;
|
|
154
|
-
|
|
155
128
|
case 'SPAN':
|
|
156
129
|
/**
|
|
157
130
|
* JIRA ISSUE MACROS
|
|
@@ -169,14 +142,12 @@ function convert(content, node, schema) {
|
|
|
169
142
|
if (node.className.split(' ').indexOf('jira-issue-macro') > -1) {
|
|
170
143
|
var jiraKey = node.getAttribute('data-jira-key');
|
|
171
144
|
var link = node.getElementsByTagName('a')[0];
|
|
172
|
-
|
|
173
145
|
if (jiraKey && link) {
|
|
174
146
|
return addMarks(_prosemirrorModel.Fragment.from(schema.text(jiraKey)), [schema.marks.link.create({
|
|
175
147
|
href: link.getAttribute('href'),
|
|
176
148
|
title: link.getAttribute('title')
|
|
177
149
|
})]);
|
|
178
150
|
}
|
|
179
|
-
|
|
180
151
|
return null;
|
|
181
152
|
} else if (node.className.match('jira-macro-single-issue-export-pdf')) {
|
|
182
153
|
return null;
|
|
@@ -185,12 +156,9 @@ function convert(content, node, schema) {
|
|
|
185
156
|
return null;
|
|
186
157
|
} else if (isMedia(node) && (0, _schemaJira.isSchemaWithMedia)(schema)) {
|
|
187
158
|
var dataNode = node.querySelector('[data-media-services-id]');
|
|
188
|
-
|
|
189
159
|
if (dataNode && dataNode instanceof HTMLElement) {
|
|
190
160
|
var id = dataNode.getAttribute('data-media-services-id');
|
|
191
|
-
|
|
192
161
|
var _type = dataNode.getAttribute('data-media-services-type');
|
|
193
|
-
|
|
194
162
|
var collection = dataNode.getAttribute('data-media-services-collection') || '';
|
|
195
163
|
var attachmentName = dataNode.getAttribute('data-attachment-name');
|
|
196
164
|
var attachmentType = dataNode.getAttribute('data-attachment-type');
|
|
@@ -209,22 +177,17 @@ function convert(content, node, schema) {
|
|
|
209
177
|
});
|
|
210
178
|
}
|
|
211
179
|
}
|
|
212
|
-
|
|
213
180
|
break;
|
|
214
|
-
|
|
215
181
|
case 'IMG':
|
|
216
182
|
if (node.parentElement && node.parentElement.className.match('jira-issue-macro-key')) {
|
|
217
183
|
return null;
|
|
218
184
|
} else if (node.className === 'emoticon') {
|
|
219
185
|
var emojiResult = (0, _emojiHelper.mapImageToEmoji)(node);
|
|
220
|
-
|
|
221
186
|
if (emojiResult) {
|
|
222
187
|
return schema.text(emojiResult);
|
|
223
188
|
}
|
|
224
189
|
}
|
|
225
|
-
|
|
226
190
|
break;
|
|
227
|
-
|
|
228
191
|
case 'H1':
|
|
229
192
|
case 'H2':
|
|
230
193
|
case 'H3':
|
|
@@ -235,24 +198,23 @@ function convert(content, node, schema) {
|
|
|
235
198
|
var supportedMarks = [schema.marks.link].filter(function (mark) {
|
|
236
199
|
return !!mark;
|
|
237
200
|
});
|
|
238
|
-
return schema.nodes.heading.createChecked(
|
|
201
|
+
return schema.nodes.heading.createChecked(
|
|
202
|
+
// @see ED-4708
|
|
239
203
|
{
|
|
240
204
|
level: level === 6 ? 5 : level
|
|
241
205
|
}, schema.nodes.heading.validContent(content) ? content : ensureInline(schema, content, supportedMarks));
|
|
242
|
-
|
|
243
206
|
case 'BR':
|
|
244
207
|
return schema.nodes.hardBreak.createChecked();
|
|
245
|
-
|
|
246
208
|
case 'HR':
|
|
247
209
|
return schema.nodes.rule.createChecked();
|
|
248
|
-
|
|
249
210
|
case 'P':
|
|
250
211
|
if (node.firstElementChild && isMedia(node.firstElementChild)) {
|
|
251
212
|
// Filter out whitespace text nodes
|
|
213
|
+
|
|
252
214
|
var _schema$nodes = schema.nodes,
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
215
|
+
mediaSingle = _schema$nodes.mediaSingle,
|
|
216
|
+
mediaGroup = _schema$nodes.mediaGroup,
|
|
217
|
+
paragraph = _schema$nodes.paragraph;
|
|
256
218
|
var mediaArray = [];
|
|
257
219
|
var contentArray = [];
|
|
258
220
|
var fragmentArray = [];
|
|
@@ -264,45 +226,37 @@ function convert(content, node, schema) {
|
|
|
264
226
|
} else if (!(child.isText && /^\s*$/.test(child.text || ''))) {
|
|
265
227
|
hasNonMediaChildren = true;
|
|
266
228
|
}
|
|
267
|
-
|
|
268
229
|
contentArray.push(child);
|
|
269
230
|
});
|
|
270
|
-
|
|
271
231
|
if (hasNonMediaChildren && contentArray.length) {
|
|
272
232
|
fragmentArray.push(paragraph.createChecked({}, contentArray));
|
|
273
233
|
}
|
|
274
|
-
|
|
275
234
|
if ((0, _schemaJira.isSchemaWithMedia)(schema) && mediaArray.length) {
|
|
276
235
|
var mediaNodeType = isMediaSingle(node.firstElementChild) ? mediaSingle : mediaGroup;
|
|
277
236
|
fragmentArray.push(mediaNodeType.createChecked({}, mediaArray));
|
|
278
237
|
}
|
|
279
|
-
|
|
280
238
|
if (fragmentArray.length) {
|
|
281
239
|
return _prosemirrorModel.Fragment.fromArray(fragmentArray);
|
|
282
240
|
}
|
|
283
|
-
|
|
284
241
|
return null;
|
|
285
242
|
}
|
|
286
|
-
|
|
287
243
|
return schema.nodes.paragraph.createChecked({}, content);
|
|
288
|
-
}
|
|
289
|
-
|
|
244
|
+
}
|
|
290
245
|
|
|
246
|
+
// lists
|
|
291
247
|
if ((0, _schemaJira.isSchemaWithLists)(schema)) {
|
|
292
248
|
switch (tag) {
|
|
293
249
|
case 'UL':
|
|
294
250
|
return schema.nodes.bulletList.createChecked({}, content);
|
|
295
|
-
|
|
296
251
|
case 'OL':
|
|
297
252
|
return schema.nodes.orderedList.createChecked({}, content);
|
|
298
|
-
|
|
299
253
|
case 'LI':
|
|
300
254
|
var compatibleContent = schema.nodes.listItem.validContent(content) ? content : ensureBlocks(content, schema, schema.nodes.listItem);
|
|
301
255
|
return schema.nodes.listItem.createChecked({}, compatibleContent);
|
|
302
256
|
}
|
|
303
|
-
}
|
|
304
|
-
|
|
257
|
+
}
|
|
305
258
|
|
|
259
|
+
// code block
|
|
306
260
|
if ((0, _schemaJira.isSchemaWithCodeBlock)(schema)) {
|
|
307
261
|
switch (tag) {
|
|
308
262
|
case 'DIV':
|
|
@@ -310,100 +264,81 @@ function convert(content, node, schema) {
|
|
|
310
264
|
return null;
|
|
311
265
|
} else if (node.className === 'code panel' || node.className === 'preformatted panel') {
|
|
312
266
|
var pre = node.querySelector('pre');
|
|
313
|
-
|
|
314
267
|
if (!pre) {
|
|
315
268
|
return null;
|
|
316
269
|
}
|
|
317
|
-
|
|
318
270
|
var language = node.className === 'preformatted panel' ? 'plain' : pre.className.split('-')[1];
|
|
319
271
|
var textContent = (pre.textContent || '').replace(/\r\n/g, '\n');
|
|
320
272
|
return schema.nodes.codeBlock.createChecked({
|
|
321
273
|
language: language
|
|
322
274
|
}, textContent ? schema.text(textContent) : undefined);
|
|
323
275
|
}
|
|
324
|
-
|
|
325
276
|
break;
|
|
326
|
-
|
|
327
277
|
case 'PRE':
|
|
328
278
|
return null;
|
|
329
279
|
}
|
|
330
280
|
}
|
|
331
|
-
|
|
332
281
|
if ((0, _schemaJira.isSchemaWithBlockQuotes)(schema) && tag === 'BLOCKQUOTE') {
|
|
333
282
|
var blockquoteContent = content && content.content.length ? content : schema.nodes.paragraph.createChecked();
|
|
334
283
|
return schema.nodes.blockquote.createChecked({}, blockquoteContent);
|
|
335
|
-
}
|
|
336
|
-
|
|
284
|
+
}
|
|
337
285
|
|
|
286
|
+
// table
|
|
338
287
|
if ((0, _schemaJira.isSchemaWithTables)(schema)) {
|
|
339
288
|
switch (tag) {
|
|
340
289
|
case 'TABLE':
|
|
341
290
|
return schema.nodes.table.createChecked({}, content);
|
|
342
|
-
|
|
343
291
|
case 'TR':
|
|
344
292
|
return schema.nodes.tableRow.createChecked({}, content);
|
|
345
|
-
|
|
346
293
|
case 'TD':
|
|
347
294
|
var tdContent = schema.nodes.tableCell.validContent(content) ? content : ensureBlocks(content, schema);
|
|
348
295
|
return schema.nodes.tableCell.createChecked({}, tdContent);
|
|
349
|
-
|
|
350
296
|
case 'TH':
|
|
351
297
|
var thContent = schema.nodes.tableHeader.validContent(content) ? content : ensureBlocks(content, schema);
|
|
352
298
|
return schema.nodes.tableHeader.createChecked({}, thContent);
|
|
353
299
|
}
|
|
354
300
|
}
|
|
355
301
|
}
|
|
356
|
-
|
|
357
302
|
return;
|
|
358
303
|
}
|
|
304
|
+
|
|
359
305
|
/*
|
|
360
306
|
* Flattens DOM tree into single array
|
|
361
307
|
*/
|
|
362
|
-
|
|
363
|
-
|
|
364
308
|
function bfsOrder(root) {
|
|
365
309
|
var inqueue = [root];
|
|
366
310
|
var outqueue = [];
|
|
367
311
|
var elem;
|
|
368
|
-
|
|
369
312
|
while (elem = inqueue.shift()) {
|
|
370
313
|
outqueue.push(elem);
|
|
371
314
|
var childIndex = void 0;
|
|
372
|
-
|
|
373
315
|
for (childIndex = 0; childIndex < elem.childNodes.length; childIndex++) {
|
|
374
316
|
var child = elem.childNodes[childIndex];
|
|
375
|
-
|
|
376
317
|
switch (child.nodeType) {
|
|
377
318
|
case Node.ELEMENT_NODE:
|
|
378
319
|
case Node.TEXT_NODE:
|
|
379
320
|
inqueue.push(child);
|
|
380
321
|
break;
|
|
381
|
-
|
|
382
322
|
default:
|
|
383
323
|
// eslint-disable-next-line no-console
|
|
384
324
|
console.error("Not pushing: ".concat(child.nodeType, " ").concat(child.nodeName));
|
|
385
325
|
}
|
|
386
326
|
}
|
|
387
327
|
}
|
|
388
|
-
|
|
389
328
|
outqueue.shift();
|
|
390
329
|
return outqueue;
|
|
391
330
|
}
|
|
331
|
+
|
|
392
332
|
/**
|
|
393
333
|
* Create a fragment by adding a set of marks to each node.
|
|
394
334
|
*/
|
|
395
|
-
|
|
396
|
-
|
|
397
335
|
function addMarks(fragment, marks) {
|
|
398
336
|
var result = fragment;
|
|
399
|
-
|
|
400
337
|
for (var i = 0; i < fragment.childCount; i++) {
|
|
401
338
|
var child = result.child(i);
|
|
402
339
|
var newChild = child;
|
|
403
|
-
|
|
404
340
|
var _iterator = _createForOfIteratorHelper(marks),
|
|
405
|
-
|
|
406
|
-
|
|
341
|
+
_step;
|
|
407
342
|
try {
|
|
408
343
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
409
344
|
var mark = _step.value;
|
|
@@ -414,17 +349,13 @@ function addMarks(fragment, marks) {
|
|
|
414
349
|
} finally {
|
|
415
350
|
_iterator.f();
|
|
416
351
|
}
|
|
417
|
-
|
|
418
352
|
result = result.replaceChild(i, newChild);
|
|
419
353
|
}
|
|
420
|
-
|
|
421
354
|
return result;
|
|
422
355
|
}
|
|
423
|
-
|
|
424
356
|
function getNodeName(node) {
|
|
425
357
|
return node.nodeName.toUpperCase();
|
|
426
358
|
}
|
|
427
|
-
|
|
428
359
|
function isMedia(node) {
|
|
429
360
|
if (node && node instanceof HTMLElement) {
|
|
430
361
|
if (node.parentNode && getNodeName(node.parentNode) === 'P') {
|
|
@@ -433,23 +364,18 @@ function isMedia(node) {
|
|
|
433
364
|
}
|
|
434
365
|
}
|
|
435
366
|
}
|
|
436
|
-
|
|
437
367
|
return false;
|
|
438
368
|
}
|
|
439
|
-
|
|
440
369
|
function isMediaSingle(node) {
|
|
441
370
|
if (isMedia(node)) {
|
|
442
371
|
var dataNode = node.querySelector('[data-media-services-id]');
|
|
443
|
-
|
|
444
372
|
if (dataNode instanceof HTMLElement) {
|
|
445
373
|
var width = parseInt(dataNode.getAttribute('data-width') || '', 10);
|
|
446
374
|
var height = parseInt(dataNode.getAttribute('data-height') || '', 10);
|
|
447
|
-
|
|
448
375
|
if (node.parentNode.classList.contains('mediaSingle') && width && height) {
|
|
449
376
|
return true;
|
|
450
377
|
}
|
|
451
378
|
}
|
|
452
379
|
}
|
|
453
|
-
|
|
454
380
|
return false;
|
|
455
381
|
}
|
package/dist/cjs/version.json
CHANGED
package/dist/es2019/fix-doc.js
CHANGED
|
@@ -1,54 +1,44 @@
|
|
|
1
1
|
function getNodeName(node) {
|
|
2
2
|
return node && node.nodeName.toUpperCase();
|
|
3
3
|
}
|
|
4
|
-
|
|
5
4
|
function isMedia(node) {
|
|
6
5
|
if (!node) {
|
|
7
6
|
return false;
|
|
8
7
|
}
|
|
9
|
-
|
|
10
8
|
if (getNodeName(node) === 'SPAN' && node instanceof HTMLElement) {
|
|
11
9
|
return !!node.querySelector('a > jira-attachment-thumbnail > img[data-attachment-type="thumbnail"], ' + 'a[data-attachment-type="file"]');
|
|
12
10
|
}
|
|
13
|
-
|
|
14
11
|
return false;
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
function repairParagraph(p) {
|
|
18
14
|
const paragraphs = [];
|
|
19
15
|
let buffer = [];
|
|
20
16
|
let mediaGroupFound = false;
|
|
21
17
|
let skipBuffer = false;
|
|
22
|
-
|
|
23
18
|
const processMedia = () => {
|
|
24
19
|
if (buffer.length) {
|
|
25
20
|
const head = buffer[0];
|
|
26
|
-
|
|
27
21
|
if (getNodeName(head) === 'BR') {
|
|
28
22
|
buffer.shift();
|
|
29
23
|
}
|
|
30
|
-
|
|
31
24
|
paragraphs.push(buffer);
|
|
32
25
|
buffer = [];
|
|
33
26
|
}
|
|
34
27
|
};
|
|
35
|
-
|
|
36
28
|
for (let i = 0, length = p.childNodes.length; i < length; i++) {
|
|
37
29
|
const node = p.childNodes[i];
|
|
38
|
-
skipBuffer = false;
|
|
39
|
-
|
|
30
|
+
skipBuffer = false;
|
|
31
|
+
// [..., M, BR, ...]
|
|
40
32
|
if (getNodeName(node) === 'BR') {
|
|
41
33
|
// [mmm, M, BR, ...]
|
|
42
34
|
if (mediaGroupFound) {
|
|
43
35
|
processMedia();
|
|
44
36
|
mediaGroupFound = false;
|
|
45
37
|
skipBuffer = true;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
}
|
|
39
|
+
// [..., BR, M, ...]
|
|
49
40
|
if (isMedia(node.nextSibling)) {
|
|
50
41
|
mediaGroupFound = true;
|
|
51
|
-
|
|
52
42
|
if (buffer.length) {
|
|
53
43
|
paragraphs.push(buffer);
|
|
54
44
|
buffer = [];
|
|
@@ -65,44 +55,38 @@ function repairParagraph(p) {
|
|
|
65
55
|
if (getNodeName(node) === '#TEXT' && (node.textContent || '').trim() === '') {
|
|
66
56
|
continue;
|
|
67
57
|
}
|
|
68
|
-
|
|
69
58
|
buffer = (paragraphs.pop() || []).concat(buffer);
|
|
70
59
|
mediaGroupFound = false;
|
|
71
60
|
}
|
|
72
61
|
}
|
|
73
|
-
|
|
74
62
|
if (!skipBuffer) {
|
|
75
63
|
buffer.push(node);
|
|
76
64
|
}
|
|
77
65
|
}
|
|
78
|
-
|
|
79
66
|
if (mediaGroupFound) {
|
|
80
67
|
processMedia();
|
|
81
68
|
} else {
|
|
82
69
|
paragraphs.push(buffer);
|
|
83
70
|
}
|
|
84
|
-
|
|
85
71
|
if (paragraphs.length > 1) {
|
|
86
72
|
const fragment = document.createDocumentFragment();
|
|
87
73
|
paragraphs.forEach(childP => {
|
|
88
74
|
const innerP = document.createElement('p');
|
|
89
75
|
childP.forEach(child => innerP.appendChild(child));
|
|
90
76
|
fragment.appendChild(innerP);
|
|
91
|
-
});
|
|
77
|
+
});
|
|
92
78
|
|
|
79
|
+
// Replace old P
|
|
93
80
|
const parent = p.parentNode;
|
|
94
|
-
parent.insertBefore(fragment, p.nextSibling);
|
|
95
|
-
|
|
81
|
+
parent.insertBefore(fragment, p.nextSibling);
|
|
82
|
+
// IE11 doesn't support remove
|
|
96
83
|
parent.removeChild(p);
|
|
97
84
|
}
|
|
98
85
|
}
|
|
99
|
-
|
|
100
86
|
export default function (doc) {
|
|
101
87
|
const paragraphs = doc.querySelectorAll('p');
|
|
102
|
-
|
|
103
88
|
for (let i = 0, length = paragraphs.length; i < length; i++) {
|
|
104
89
|
repairParagraph(paragraphs[i]);
|
|
105
90
|
}
|
|
106
|
-
|
|
107
91
|
return doc;
|
|
108
92
|
}
|