jodit 4.19.10 → 4.19.11

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.
Files changed (76) hide show
  1. package/CHANGELOG.md +139 -131
  2. package/es2015/jodit.css +1 -1
  3. package/es2015/jodit.fat.min.js +7 -7
  4. package/es2015/jodit.js +703 -166
  5. package/es2015/jodit.min.js +7 -7
  6. package/es2015/plugins/debug/debug.css +1 -1
  7. package/es2015/plugins/debug/debug.js +1 -1
  8. package/es2015/plugins/debug/debug.min.js +1 -1
  9. package/es2015/plugins/speech-recognize/speech-recognize.css +1 -1
  10. package/es2015/plugins/speech-recognize/speech-recognize.js +1 -1
  11. package/es2015/plugins/speech-recognize/speech-recognize.min.js +1 -1
  12. package/es2018/jodit.fat.min.js +7 -7
  13. package/es2018/jodit.min.js +7 -7
  14. package/es2018/plugins/debug/debug.min.js +1 -1
  15. package/es2018/plugins/speech-recognize/speech-recognize.min.js +1 -1
  16. package/es2021/jodit.css +1 -1
  17. package/es2021/jodit.fat.min.js +13 -13
  18. package/es2021/jodit.js +703 -166
  19. package/es2021/jodit.min.js +13 -13
  20. package/es2021/plugins/debug/debug.css +1 -1
  21. package/es2021/plugins/debug/debug.js +1 -1
  22. package/es2021/plugins/debug/debug.min.js +1 -1
  23. package/es2021/plugins/speech-recognize/speech-recognize.css +1 -1
  24. package/es2021/plugins/speech-recognize/speech-recognize.js +1 -1
  25. package/es2021/plugins/speech-recognize/speech-recognize.min.js +1 -1
  26. package/es2021.en/jodit.css +1 -1
  27. package/es2021.en/jodit.fat.min.js +19 -19
  28. package/es2021.en/jodit.js +703 -166
  29. package/es2021.en/jodit.min.js +19 -19
  30. package/es2021.en/plugins/debug/debug.css +1 -1
  31. package/es2021.en/plugins/debug/debug.js +1 -1
  32. package/es2021.en/plugins/debug/debug.min.js +1 -1
  33. package/es2021.en/plugins/speech-recognize/speech-recognize.css +1 -1
  34. package/es2021.en/plugins/speech-recognize/speech-recognize.js +1 -1
  35. package/es2021.en/plugins/speech-recognize/speech-recognize.min.js +1 -1
  36. package/es5/jodit.css +2 -2
  37. package/es5/jodit.fat.min.js +2 -2
  38. package/es5/jodit.js +731 -171
  39. package/es5/jodit.min.css +2 -2
  40. package/es5/jodit.min.js +2 -2
  41. package/es5/plugins/debug/debug.css +1 -1
  42. package/es5/plugins/debug/debug.js +1 -1
  43. package/es5/plugins/debug/debug.min.js +1 -1
  44. package/es5/plugins/speech-recognize/speech-recognize.css +1 -1
  45. package/es5/plugins/speech-recognize/speech-recognize.js +1 -1
  46. package/es5/plugins/speech-recognize/speech-recognize.min.js +1 -1
  47. package/es5/polyfills.fat.min.js +1 -1
  48. package/es5/polyfills.js +1 -1
  49. package/es5/polyfills.min.js +1 -1
  50. package/esm/core/constants.js +1 -1
  51. package/esm/core/dom/dom.js +2 -2
  52. package/esm/core/helpers/checker/is-html-from-word.d.ts +4 -3
  53. package/esm/core/helpers/checker/is-html-from-word.js +94 -14
  54. package/esm/core/helpers/checker/is-html.d.ts +4 -0
  55. package/esm/core/helpers/checker/is-html.js +54 -2
  56. package/esm/core/helpers/html/apply-styles.js +20 -11
  57. package/esm/core/helpers/html/clean-from-word.js +2 -3
  58. package/esm/core/helpers/html/index.d.ts +1 -0
  59. package/esm/core/helpers/html/index.js +1 -0
  60. package/esm/core/helpers/html/tag-scan.d.ts +36 -0
  61. package/esm/core/helpers/html/tag-scan.js +257 -0
  62. package/esm/core/helpers/string/trim.d.ts +4 -0
  63. package/esm/core/helpers/string/trim.js +29 -10
  64. package/esm/core/selection/helpers/index.js +3 -2
  65. package/esm/jodit.js +2 -1
  66. package/esm/plugins/delete/delete.js +16 -2
  67. package/esm/plugins/iframe/iframe.js +59 -12
  68. package/esm/plugins/media/media.js +2 -4
  69. package/esm/plugins/paste/helpers.js +4 -2
  70. package/esm/plugins/resizer/resizer.js +2 -4
  71. package/package.json +1 -1
  72. package/types/core/helpers/checker/is-html-from-word.d.ts +4 -3
  73. package/types/core/helpers/checker/is-html.d.ts +4 -0
  74. package/types/core/helpers/html/index.d.ts +1 -0
  75. package/types/core/helpers/html/tag-scan.d.ts +36 -0
  76. package/types/core/helpers/string/trim.d.ts +4 -0
@@ -0,0 +1,257 @@
1
+ /*!
2
+ * Jodit Editor (https://xdsoft.net/jodit/)
3
+ * Released under MIT see LICENSE.txt in the project root for license information.
4
+ * Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net
5
+ */
6
+ /**
7
+ * @module helpers/html
8
+ */
9
+ // Single passes over HTML that comes from the clipboard or the editor value.
10
+ // A regex with `[^>]*` or `.*?` before a required literal backtracks
11
+ // quadratically on a long run of tag openers, so these walk with `indexOf`.
12
+ const TAG_NAME = /[a-z0-9:-]/i;
13
+ // The tags the Word clean-up strips: `<html>`, `<colgroup>`, `<col>`, `<o:p>` and their closers
14
+ const WORD_WRAPPER_TAGS = ['<html', '</html', '<col', '</col', '<o:p', '</o:p'];
15
+ function startsWithIgnoreCase(html, index, prefix) {
16
+ return html.substr(index, prefix.length).toLowerCase() === prefix;
17
+ }
18
+ // The first `<` at or after `from` that opens one of the prefixes (`<meta`, `</html`, `<!--`)
19
+ function indexOfPrefix(html, prefixes, from) {
20
+ let index = html.indexOf('<', from);
21
+ while (index !== -1) {
22
+ for (const prefix of prefixes) {
23
+ if (startsWithIgnoreCase(html, index, prefix)) {
24
+ return [index, prefix];
25
+ }
26
+ }
27
+ index = html.indexOf('<', index + 1);
28
+ }
29
+ return [-1, ''];
30
+ }
31
+ /**
32
+ * The first `</name>` at or after `from`, case-insensitive, or -1
33
+ */
34
+ export function indexOfClosingTag(html, name, from) {
35
+ const closing = '</' + name + '>';
36
+ let index = html.indexOf('</', from);
37
+ while (index !== -1) {
38
+ if (startsWithIgnoreCase(html, index, closing)) {
39
+ return index;
40
+ }
41
+ index = html.indexOf('</', index + 2);
42
+ }
43
+ return -1;
44
+ }
45
+ /**
46
+ * Remove every tag that starts with one of the prefixes, up to its `>`:
47
+ * `removeTagsByPrefix(html, ['<meta', '<!--'])`
48
+ */
49
+ export function removeTagsByPrefix(html, prefixes) {
50
+ const lower = prefixes.map(prefix => prefix.toLowerCase());
51
+ let result = '';
52
+ let cursor = 0;
53
+ for (;;) {
54
+ const [start] = indexOfPrefix(html, lower, cursor);
55
+ if (start === -1) {
56
+ break;
57
+ }
58
+ const end = html.indexOf('>', start);
59
+ if (end === -1) {
60
+ break;
61
+ }
62
+ result += html.slice(cursor, start);
63
+ cursor = end + 1;
64
+ }
65
+ return cursor === 0 ? html : result + html.slice(cursor);
66
+ }
67
+ /**
68
+ * Strip the Word wrapper tags and then the comments, as the clean-up always did
69
+ */
70
+ export function removeWordWrappers(html) {
71
+ return removeTagsByPrefix(removeTagsByPrefix(html, WORD_WRAPPER_TAGS), [
72
+ '<!--'
73
+ ]);
74
+ }
75
+ // Every `</name>` position by name, so the closer of an element is found by a binary search
76
+ function closingTagPositions(html) {
77
+ const positions = new Map();
78
+ let index = html.indexOf('</');
79
+ while (index !== -1) {
80
+ const name = readTagName(html, index + 2).toLowerCase();
81
+ if (name !== '' && html.charAt(index + 2 + name.length) === '>') {
82
+ const list = positions.get(name);
83
+ if (list) {
84
+ list.push(index);
85
+ }
86
+ else {
87
+ positions.set(name, [index]);
88
+ }
89
+ }
90
+ index = html.indexOf('</', index + 2);
91
+ }
92
+ return positions;
93
+ }
94
+ // The first position in the sorted list that is >= from, or -1
95
+ function firstAfter(list, from) {
96
+ if (!list) {
97
+ return -1;
98
+ }
99
+ let low = 0;
100
+ let high = list.length;
101
+ while (low < high) {
102
+ const middle = (low + high) >> 1;
103
+ if (list[middle] < from) {
104
+ low = middle + 1;
105
+ }
106
+ else {
107
+ high = middle;
108
+ }
109
+ }
110
+ return low < list.length ? list[low] : -1;
111
+ }
112
+ /**
113
+ * The index of the first `<name>` or `<name …>` tag, or -1
114
+ */
115
+ export function indexOfOpenTag(html, name) {
116
+ const prefix = '<' + name.toLowerCase();
117
+ let cursor = 0;
118
+ for (;;) {
119
+ const [start] = indexOfPrefix(html, [prefix], cursor);
120
+ if (start === -1) {
121
+ return -1;
122
+ }
123
+ const next = html.charAt(start + prefix.length);
124
+ if (next === '>') {
125
+ return start;
126
+ }
127
+ if (/\s/.test(next)) {
128
+ if (html.indexOf('>', start) === -1) {
129
+ return -1;
130
+ }
131
+ return start;
132
+ }
133
+ cursor = start + 1;
134
+ }
135
+ }
136
+ function readTagName(html, from) {
137
+ let end = from;
138
+ while (TAG_NAME.test(html.charAt(end))) {
139
+ end += 1;
140
+ }
141
+ return html.slice(from, end);
142
+ }
143
+ /**
144
+ * Replace every `<name … marker …>inner</name>` with `inner`.
145
+ * `name` null takes any tag; `keep` can refuse an element by its inner HTML.
146
+ */
147
+ export function unwrapMarkedTags(html, name, marker, keep) {
148
+ const lowerMarker = marker.toLowerCase();
149
+ const prefixes = [name == null ? '<' : '<' + name.toLowerCase()];
150
+ const closings = closingTagPositions(html);
151
+ let result = '';
152
+ let cursor = 0;
153
+ for (;;) {
154
+ const [start] = indexOfPrefix(html, prefixes, cursor);
155
+ if (start === -1) {
156
+ break;
157
+ }
158
+ const tagName = (name !== null && name !== void 0 ? name : readTagName(html, start + 1)).toLowerCase();
159
+ const gt = html.indexOf('>', start);
160
+ if (gt === -1) {
161
+ break;
162
+ }
163
+ const close = tagName !== '' &&
164
+ html.slice(start, gt).toLowerCase().includes(lowerMarker)
165
+ ? firstAfter(closings.get(tagName), gt + 1)
166
+ : -1;
167
+ // Not a marked element: the `<` is text, the next one may still open an element
168
+ if (close === -1) {
169
+ result += html.slice(cursor, start + 1);
170
+ cursor = start + 1;
171
+ continue;
172
+ }
173
+ const inner = html.slice(gt + 1, close);
174
+ const after = close + tagName.length + 3;
175
+ result += html.slice(cursor, start);
176
+ result +=
177
+ inner !== '' && (!keep || keep(inner))
178
+ ? inner
179
+ : html.slice(start, after);
180
+ cursor = after;
181
+ }
182
+ return cursor === 0 ? html : result + html.slice(cursor);
183
+ }
184
+ // The first `literal` at or after `from`, case-insensitive, or -1
185
+ function indexOfLiteral(html, literal, from) {
186
+ const head = literal.charAt(0);
187
+ let index = html.indexOf(head, from);
188
+ while (index !== -1) {
189
+ if (startsWithIgnoreCase(html, index, literal)) {
190
+ return index;
191
+ }
192
+ index = html.indexOf(head, index + 1);
193
+ }
194
+ return -1;
195
+ }
196
+ /**
197
+ * Remove every `open … openEnd … close` block whose opener holds `marker` (any opener when it is ''):
198
+ * `removeBetween(html, '<style', '>', '</style>', 'jodit-box')`
199
+ */
200
+ export function removeBetween(html, open, openEnd, close, marker = '') {
201
+ const lowerOpen = open.toLowerCase();
202
+ const lowerMarker = marker.toLowerCase();
203
+ let result = '';
204
+ let cursor = 0;
205
+ for (;;) {
206
+ const start = indexOfLiteral(html, lowerOpen, cursor);
207
+ if (start === -1) {
208
+ break;
209
+ }
210
+ const end = indexOfLiteral(html, openEnd, start + open.length);
211
+ if (end === -1) {
212
+ break;
213
+ }
214
+ if (lowerMarker !== '' &&
215
+ !html.slice(start, end).toLowerCase().includes(lowerMarker)) {
216
+ result += html.slice(cursor, end + openEnd.length);
217
+ cursor = end + openEnd.length;
218
+ continue;
219
+ }
220
+ const closeIndex = indexOfLiteral(html, close, end + openEnd.length);
221
+ if (closeIndex === -1) {
222
+ break;
223
+ }
224
+ result += html.slice(cursor, start);
225
+ cursor = closeIndex + close.length;
226
+ }
227
+ return cursor === 0 ? html : result + html.slice(cursor);
228
+ }
229
+ /**
230
+ * Remove every empty `<name … marker …></name>` element
231
+ */
232
+ export function removeEmptyMarkedTags(html, name, marker) {
233
+ const lowerName = name.toLowerCase();
234
+ const lowerMarker = marker.toLowerCase();
235
+ const closing = '</' + lowerName + '>';
236
+ let result = '';
237
+ let cursor = 0;
238
+ for (;;) {
239
+ const [start] = indexOfPrefix(html, ['<' + lowerName], cursor);
240
+ if (start === -1) {
241
+ break;
242
+ }
243
+ const gt = html.indexOf('>', start);
244
+ if (gt === -1) {
245
+ break;
246
+ }
247
+ if (html.slice(start, gt).toLowerCase().includes(lowerMarker) &&
248
+ startsWithIgnoreCase(html, gt + 1, closing)) {
249
+ result += html.slice(cursor, start);
250
+ cursor = gt + 1 + closing.length;
251
+ continue;
252
+ }
253
+ result += html.slice(cursor, gt + 1);
254
+ cursor = gt + 1;
255
+ }
256
+ return cursor === 0 ? html : result + html.slice(cursor);
257
+ }
@@ -13,3 +13,7 @@ export declare function trimChars(value: string, chars: string): string;
13
13
  * Trim only invisible chars
14
14
  */
15
15
  export declare function trimInv(value: string): string;
16
+ /**
17
+ * Without the invisible chars at the end
18
+ */
19
+ export declare function trimInvEnd(value: string): string;
@@ -6,26 +6,45 @@
6
6
  /**
7
7
  * @module helpers/string
8
8
  */
9
- import { INVISIBLE_SPACE_REG_EXP_END, INVISIBLE_SPACE_REG_EXP_START, SPACE_REG_EXP_END, SPACE_REG_EXP_START } from "../../constants.js";
9
+ const SPACE = /[\s\u200b]/;
10
+ const INVISIBLE = /\uFEFF/;
11
+ // Cut the chars matching `char` from both ends; `[…]+$` backtracks on a long run that is not at the end
12
+ function trimBy(value, char) {
13
+ let start = 0;
14
+ let end = value.length;
15
+ while (start < end && char.test(value.charAt(start))) {
16
+ start += 1;
17
+ }
18
+ while (end > start && char.test(value.charAt(end - 1))) {
19
+ end -= 1;
20
+ }
21
+ return start === 0 && end === value.length
22
+ ? value
23
+ : value.slice(start, end);
24
+ }
10
25
  /**
11
26
  * It clears the line of all auxiliary invisible characters , from the spaces and line breaks , tabs
12
27
  * from the beginning and end of the line
13
28
  */
14
29
  export function trim(value) {
15
- return value
16
- .replace(SPACE_REG_EXP_END(), '')
17
- .replace(SPACE_REG_EXP_START(), '');
30
+ return trimBy(value, SPACE);
18
31
  }
19
32
  export function trimChars(value, chars) {
20
- return value
21
- .replace(RegExp(`[${chars}]+$`), '')
22
- .replace(RegExp(`^[${chars}]+`), '');
33
+ return trimBy(value, RegExp(`[${chars}]`));
23
34
  }
24
35
  /**
25
36
  * Trim only invisible chars
26
37
  */
27
38
  export function trimInv(value) {
28
- return value
29
- .replace(INVISIBLE_SPACE_REG_EXP_END(), '')
30
- .replace(INVISIBLE_SPACE_REG_EXP_START(), '');
39
+ return trimBy(value, INVISIBLE);
40
+ }
41
+ /**
42
+ * Without the invisible chars at the end
43
+ */
44
+ export function trimInvEnd(value) {
45
+ let end = value.length;
46
+ while (end > 0 && INVISIBLE.test(value.charAt(end - 1))) {
47
+ end -= 1;
48
+ }
49
+ return end === value.length ? value : value.slice(0, end);
31
50
  }
@@ -6,8 +6,9 @@
6
6
  /**
7
7
  * @module selection
8
8
  */
9
- import { INVISIBLE_SPACE_REG_EXP_END as INV_END, INVISIBLE_SPACE_REG_EXP_START as INV_START } from "../../constants.js";
9
+ import { INVISIBLE_SPACE_REG_EXP_START as INV_START } from "../../constants.js";
10
10
  import { Dom } from "../../dom/dom.js";
11
+ import { trimInvEnd } from "../../helpers/string/trim.js";
11
12
  export * from "./composed-ranges.js";
12
13
  export * from "./is-moved.js";
13
14
  export * from "./move-node-inside-start.js";
@@ -21,7 +22,7 @@ export * from "./move-the-node-along-the-edge-outward.js";
21
22
  export function cursorInTheEdgeOfString(container, offset, start, end) {
22
23
  var _a;
23
24
  const text = ((_a = container.nodeValue) === null || _a === void 0 ? void 0 : _a.length) ? container.nodeValue : '';
24
- if (end && text.replace(INV_END(), '').length > offset) {
25
+ if (end && trimInvEnd(text).length > offset) {
25
26
  return true;
26
27
  }
27
28
  const inv = INV_START().exec(text);
package/esm/jodit.js CHANGED
@@ -19,6 +19,7 @@ import { FAT_MODE, IS_PROD, KEY_BACKSPACE, KEY_DELETE, KEY_ENTER, lang } from ".
19
19
  import { autobind, cache, cached, derive, throttle, watch } from "./core/decorators/index.js";
20
20
  import { eventEmitter, instances, modules, pluginSystem } from "./core/global.js";
21
21
  import { asArray, attr, callPromise, ConfigMerge, ConfigProto, css, error, isFunction, isJoditObject, isNumber, isPromise, isString, isVoid, kebabCase, markAsAtomic, normalizeKeyAliases, resolveElement, toArray, ucfirst } from "./core/helpers/index.js";
22
+ import { removeEmptyMarkedTags } from "./core/helpers/html/tag-scan.js";
22
23
  import { cssInline } from "./core/helpers/utils/css.js";
23
24
  import { Ajax } from "./core/request/index.js";
24
25
  import { Dlgs } from "./core/traits/dlgs.js";
@@ -409,7 +410,7 @@ let Jodit = Jodit_1 = class Jodit extends ViewWithToolbar {
409
410
  }
410
411
  value = this.getNativeEditorValue().replace(constants.INVISIBLE_SPACE_REG_EXP(), '');
411
412
  if (removeSelectionMarkers) {
412
- value = value.replace(/<span[^>]+id="jodit-selection_marker_[^>]+><\/span>/g, '');
413
+ value = removeEmptyMarkedTags(value, 'span', 'id="jodit-selection_marker_');
413
414
  }
414
415
  if (value === '<br>') {
415
416
  value = '';
@@ -22,6 +22,20 @@ const KEEPS_SPACES = new Set(['pre', 'pre-wrap', 'break-spaces']);
22
22
  * A plain space beside this neighbor isn't shown: there is none, or it's a
23
23
  * line break, a block or text starting (or ending) with a plain space
24
24
  */
25
+ // The run of spaces at the end (or the start) of the text becomes nbsp; counted, as `/ +$/` backtracks on a long run
26
+ function replaceEdgeSpaces(text, atEnd) {
27
+ let count = 0;
28
+ while (count < text.length &&
29
+ text.charAt(atEnd ? text.length - 1 - count : count) === ' ') {
30
+ count += 1;
31
+ }
32
+ if (count === 0) {
33
+ return text;
34
+ }
35
+ return atEnd
36
+ ? text.slice(0, text.length - count) + NBSP_SPACE.repeat(count)
37
+ : NBSP_SPACE.repeat(count) + text.slice(count);
38
+ }
25
39
  function hidesSpace(neighbor, edge) {
26
40
  var _a;
27
41
  return (!neighbor ||
@@ -219,10 +233,10 @@ export class deleteCommand extends Plugin {
219
233
  const before = this.__findNeighbor(fake, true, block);
220
234
  const after = this.__findNeighbor(fake, false, block);
221
235
  if (Dom.isText(before) && hidesSpace(after, /^ /)) {
222
- before.nodeValue = before.nodeValue.replace(/ +$/, spaces => NBSP_SPACE.repeat(spaces.length));
236
+ before.nodeValue = replaceEdgeSpaces(before.nodeValue, true);
223
237
  }
224
238
  if (Dom.isText(after) && hidesSpace(before, / $/)) {
225
- after.nodeValue = after.nodeValue.replace(/^ +/, spaces => NBSP_SPACE.repeat(spaces.length));
239
+ after.nodeValue = replaceEdgeSpaces(after.nodeValue, false);
226
240
  }
227
241
  }
228
242
  /**
@@ -8,6 +8,7 @@ import { Dom } from "../../core/dom/dom.js";
8
8
  import { pluginSystem } from "../../core/global.js";
9
9
  import { error } from "../../core/helpers/index.js";
10
10
  import { $$, attr, callPromise, css, defaultLanguage } from "../../core/helpers/index.js";
11
+ import { indexOfClosingTag, indexOfOpenTag, removeBetween } from "../../core/helpers/html/tag-scan.js";
11
12
  import "./config.js";
12
13
  /**
13
14
  * Iframe plugin - use `iframe` instead of DIV in editor. It can be need when you want to attach custom styles in editor
@@ -84,20 +85,66 @@ export function iframe(editor) {
84
85
  !editor.getReadOnly()) ||
85
86
  null);
86
87
  };
88
+ // The start of the whitespace run that ends at `to`
89
+ const skipBack = (text, to) => {
90
+ while (to > 0 && /\s/.test(text.charAt(to - 1))) {
91
+ to -= 1;
92
+ }
93
+ return to;
94
+ };
95
+ // The editor's own attributes on `<body>`: `min-height` and `contenteditable=true`
96
+ const cleanBodyTag = (tag) => {
97
+ tag = tag.replace(/min-height["'\s]*:[\s"']*[0-9]+(px|%)/i, '');
98
+ const skip = (from, chars) => {
99
+ while (chars.test(tag.charAt(from))) {
100
+ from += 1;
101
+ }
102
+ return from;
103
+ };
104
+ let index = tag.indexOf('contenteditable');
105
+ while (index !== -1) {
106
+ let to = skip(index + 'contenteditable'.length, /["'\s]/);
107
+ if (tag.charAt(to) === '=') {
108
+ to = skip(to + 1, /[\s"']/);
109
+ if (tag.startsWith('true', to)) {
110
+ to = skip(to + 4, /["']/);
111
+ let from = index;
112
+ if (/["']/.test(tag.charAt(from - 1))) {
113
+ from -= 1;
114
+ }
115
+ from = skipBack(tag, from);
116
+ return tag.slice(0, from) + tag.slice(to);
117
+ }
118
+ }
119
+ index = tag.indexOf('contenteditable', index + 1);
120
+ }
121
+ return tag;
122
+ };
87
123
  const clearMarkers = (html) => {
88
124
  // The plugins' own styles, from `getContainer`, aren't part of the value
89
- html = html.replace(/<style[^>]+jodit-box[^>]*>[\s\S]*?<\/style>/gi, '');
90
- const bodyReg = /<body.*<\/body>/im, bodyMarker = '{%%BODY%%}', body = bodyReg.exec(html);
91
- if (body) {
92
- // remove markers
93
- html = html
94
- .replace(bodyReg, bodyMarker)
95
- .replace(/<span([^>]*?)>(.*?)<\/span>/gim, '')
96
- .replace(/&lt;span([^&]*?)&gt;(.*?)&lt;\/span&gt;/gim, '')
97
- .replace(bodyMarker, body[0]
98
- .replace(/(<body[^>]+?)min-height["'\s]*:[\s"']*[0-9]+(px|%)/im, '$1')
99
- .replace(/(<body[^>]+?)([\s]*["'])?contenteditable["'\s]*=[\s"']*true["']?/im, '$1')
100
- .replace(/<(style|script|span)[^>]+jodit[^>]+>.*?<\/\1>/g, ''))
125
+ html = removeBetween(html, '<style', '>', '</style>', 'jodit-box');
126
+ const bodyStart = indexOfOpenTag(html, 'body');
127
+ let bodyEnd = -1;
128
+ for (let index = indexOfClosingTag(html, 'body', bodyStart + 1); index !== -1; index = indexOfClosingTag(html, 'body', index + 1)) {
129
+ bodyEnd = index;
130
+ }
131
+ if (bodyStart !== -1 && bodyEnd !== -1) {
132
+ const afterBody = bodyEnd + '</body>'.length;
133
+ const gt = html.indexOf('>', bodyStart);
134
+ let body = html.slice(bodyStart, afterBody);
135
+ if (gt !== -1 && gt < bodyEnd) {
136
+ body =
137
+ cleanBodyTag(html.slice(bodyStart, gt)) +
138
+ html.slice(gt, afterBody);
139
+ }
140
+ for (const tag of ['style', 'script', 'span']) {
141
+ body = removeBetween(body, '<' + tag, '>', '</' + tag + '>', 'jodit');
142
+ }
143
+ // remove markers: the spans outside the body are the editor's own
144
+ const stripSpans = (part) => removeBetween(removeBetween(part, '<span', '>', '</span>'), '&lt;span', '&gt;', '&lt;/span&gt;');
145
+ html = (stripSpans(html.slice(0, bodyStart)) +
146
+ body +
147
+ stripSpans(html.slice(afterBody)))
101
148
  .replace(/(class\s*=\s*)(['"])([^"']*)(jodit-wysiwyg|jodit)([^"']*\2)/g, '$1$2$3$5')
102
149
  .replace(/(<[^<]+?)\sclass="[\s]*"/gim, '$1')
103
150
  .replace(/(<[^<]+?)\sstyle="[\s;]*"/gim, '$1')
@@ -6,6 +6,7 @@
6
6
  import * as consts from "../../core/constants.js";
7
7
  import { Dom } from "../../core/dom/dom.js";
8
8
  import { getContainer, pluginSystem } from "../../core/global.js";
9
+ import { unwrapMarkedTags } from "../../core/helpers/html/tag-scan.js";
9
10
  import { $$, attr, dataBind, getMediaWrapper, wrapMedia } from "../../core/helpers/utils/index.js";
10
11
  import { css, cssInline } from "../../core/helpers/utils/css.js";
11
12
  import "./config.js";
@@ -86,10 +87,7 @@ export function media(editor) {
86
87
  if (mediaInFakeBlock || Object.keys(mediaWrappers).length) {
87
88
  editor.e
88
89
  .on('afterGetValueFromEditor', (data) => {
89
- const rxp = new RegExp(`<${mediaFakeTag}[^>]+data-${keyFake}[^>]+>([^]+?)</${mediaFakeTag}>`, 'ig');
90
- if (rxp.test(data.value)) {
91
- data.value = data.value.replace(rxp, '$1');
92
- }
90
+ data.value = unwrapMarkedTags(data.value, mediaFakeTag, `data-${keyFake}`);
93
91
  })
94
92
  .on('change afterInit afterSetMode changePlace', editor.async.debounce(() => {
95
93
  if (!editor.isDestructed &&
@@ -7,13 +7,14 @@ import { TEXT_PLAIN } from "../../core/constants.js";
7
7
  import { Dom } from "../../core/dom/dom.js";
8
8
  import { toArray } from "../../core/helpers/array/to-array.js";
9
9
  import { isArray, isNumber, isString, isVoid } from "../../core/helpers/checker/index.js";
10
+ import { removeTagsByPrefix } from "../../core/helpers/html/tag-scan.js";
10
11
  import { Button } from "../../core/ui/button/button/button.js";
11
12
  /**
12
13
  * Remove special HTML comments
13
14
  * @private
14
15
  */
15
16
  function removeExtraFragments(html) {
16
- html = html.replace(/<meta[^>]+?>/g, '');
17
+ html = removeTagsByPrefix(html, ['<meta']);
17
18
  const start = html.search(/<!--StartFragment-->/i);
18
19
  if (start !== -1) {
19
20
  html = html.substring(start + 20);
@@ -32,7 +33,8 @@ function removeExtraFragments(html) {
32
33
  * @private
33
34
  */
34
35
  export function removeGoogleDocsWrapper(html) {
35
- if (!/<b\s[^>]*docs-internal-guid-/i.test(html)) {
36
+ // A plain search: the wrapper check is left to the parsed document below
37
+ if (!/docs-internal-guid-/i.test(html)) {
36
38
  return html;
37
39
  }
38
40
  // An inert document: images don't load and handlers don't run
@@ -19,6 +19,7 @@ import { autobind, watch } from "../../core/decorators/index.js";
19
19
  import { Dom } from "../../core/dom/dom.js";
20
20
  import { eventEmitter, getContainer, pluginSystem } from "../../core/global.js";
21
21
  import { $$, attr, css, dataBind, getCaptionWrapper, getWrappedMedia, innerWidth, markOwner, offset } from "../../core/helpers/index.js";
22
+ import { unwrapMarkedTags } from "../../core/helpers/html/tag-scan.js";
22
23
  import { cssInline } from "../../core/helpers/utils/css.js";
23
24
  import { Plugin } from "../../core/plugin/plugin.js";
24
25
  import { isMoved } from "../../core/selection/helpers/index.js";
@@ -157,10 +158,7 @@ export class resizer extends Plugin {
157
158
  // move the caret, as table-keyboard-navigation's do
158
159
  .on('keydown', this.onEditorKeyDown, { top: true })
159
160
  .on('afterGetValueFromEditor.resizer', (data) => {
160
- const rgx = /<jodit[^>]+data-jodit_iframe_wrapper[^>]+>(.*?<iframe[^>]*>.*?<\/iframe>.*?)<\/jodit>/gi;
161
- if (rgx.test(data.value)) {
162
- data.value = data.value.replace(rgx, '$1');
163
- }
161
+ data.value = unwrapMarkedTags(data.value, 'jodit', 'data-jodit_iframe_wrapper', inner => /<iframe/i.test(inner));
164
162
  });
165
163
  this.addEventListeners();
166
164
  this.__onChangeEditor();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jodit",
3
- "version": "4.19.10",
3
+ "version": "4.19.11",
4
4
  "description": "Jodit is an awesome and useful wysiwyg editor with filebrowser",
5
5
  "main": "esm/index.js",
6
6
  "types": "types/index.d.ts",
@@ -3,10 +3,11 @@
3
3
  * Released under MIT see LICENSE.txt in the project root for license information.
4
4
  * Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net
5
5
  */
6
- /**
7
- * @module helpers/checker
8
- */
9
6
  /**
10
7
  * Detect if string is HTML from MS Word, Excel or LibreOffice/OpenOffice
8
+ *
9
+ * The clipboard text is attacker controlled, so every check walks the string
10
+ * once with `indexOf`: a regex with an unbounded group before a required
11
+ * literal was quadratic on a long run of `<meta` and froze the tab.
11
12
  */
12
13
  export declare function isHtmlFromWord(data: string): boolean;
@@ -5,5 +5,9 @@
5
5
  */
6
6
  /**
7
7
  * Check if a string is html or not
8
+ *
9
+ * The pasted text is attacker controlled, so the check walks the string with
10
+ * `indexOf`: the former regex `<(\w+)[^>]*>(.*?)<\/\1>` was quadratic on a
11
+ * long run of `<a>` and froze the tab.
8
12
  */
9
13
  export declare const isHTML: (str: unknown) => str is string;
@@ -12,3 +12,4 @@ export * from "./htmlspecialchars";
12
12
  export * from "./nl2br";
13
13
  export * from "./safe-html";
14
14
  export * from "./strip-tags";
15
+ export * from "./tag-scan";
@@ -0,0 +1,36 @@
1
+ /*!
2
+ * Jodit Editor (https://xdsoft.net/jodit/)
3
+ * Released under MIT see LICENSE.txt in the project root for license information.
4
+ * Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net
5
+ */
6
+ /**
7
+ * The first `</name>` at or after `from`, case-insensitive, or -1
8
+ */
9
+ export declare function indexOfClosingTag(html: string, name: string, from: number): number;
10
+ /**
11
+ * Remove every tag that starts with one of the prefixes, up to its `>`:
12
+ * `removeTagsByPrefix(html, ['<meta', '<!--'])`
13
+ */
14
+ export declare function removeTagsByPrefix(html: string, prefixes: string[]): string;
15
+ /**
16
+ * Strip the Word wrapper tags and then the comments, as the clean-up always did
17
+ */
18
+ export declare function removeWordWrappers(html: string): string;
19
+ /**
20
+ * The index of the first `<name>` or `<name …>` tag, or -1
21
+ */
22
+ export declare function indexOfOpenTag(html: string, name: string): number;
23
+ /**
24
+ * Replace every `<name … marker …>inner</name>` with `inner`.
25
+ * `name` null takes any tag; `keep` can refuse an element by its inner HTML.
26
+ */
27
+ export declare function unwrapMarkedTags(html: string, name: string | null, marker: string, keep?: (inner: string) => boolean): string;
28
+ /**
29
+ * Remove every `open … openEnd … close` block whose opener holds `marker` (any opener when it is ''):
30
+ * `removeBetween(html, '<style', '>', '</style>', 'jodit-box')`
31
+ */
32
+ export declare function removeBetween(html: string, open: string, openEnd: string, close: string, marker?: string): string;
33
+ /**
34
+ * Remove every empty `<name … marker …></name>` element
35
+ */
36
+ export declare function removeEmptyMarkedTags(html: string, name: string, marker: string): string;
@@ -13,3 +13,7 @@ export declare function trimChars(value: string, chars: string): string;
13
13
  * Trim only invisible chars
14
14
  */
15
15
  export declare function trimInv(value: string): string;
16
+ /**
17
+ * Without the invisible chars at the end
18
+ */
19
+ export declare function trimInvEnd(value: string): string;