jodit 4.19.9 → 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.
- package/CHANGELOG.md +145 -131
- package/es2015/jodit.css +1 -1
- package/es2015/jodit.fat.min.js +19 -19
- package/es2015/jodit.js +1222 -1033
- package/es2015/jodit.min.js +19 -19
- package/es2015/plugins/debug/debug.css +1 -1
- package/es2015/plugins/debug/debug.js +1 -1
- package/es2015/plugins/debug/debug.min.js +1 -1
- package/es2015/plugins/speech-recognize/speech-recognize.css +1 -1
- package/es2015/plugins/speech-recognize/speech-recognize.js +8 -8
- package/es2015/plugins/speech-recognize/speech-recognize.min.js +2 -2
- package/es2018/jodit.fat.min.js +19 -19
- package/es2018/jodit.min.js +19 -19
- package/es2018/plugins/debug/debug.min.js +1 -1
- package/es2018/plugins/speech-recognize/speech-recognize.min.js +2 -2
- package/es2021/jodit.css +1 -1
- package/es2021/jodit.fat.min.js +26 -26
- package/es2021/jodit.js +1216 -1027
- package/es2021/jodit.min.js +26 -26
- package/es2021/plugins/debug/debug.css +1 -1
- package/es2021/plugins/debug/debug.js +1 -1
- package/es2021/plugins/debug/debug.min.js +1 -1
- package/es2021/plugins/speech-recognize/speech-recognize.css +1 -1
- package/es2021/plugins/speech-recognize/speech-recognize.js +8 -8
- package/es2021/plugins/speech-recognize/speech-recognize.min.js +2 -2
- package/es2021.en/jodit.css +1 -1
- package/es2021.en/jodit.fat.min.js +28 -28
- package/es2021.en/jodit.js +1216 -1027
- package/es2021.en/jodit.min.js +28 -28
- package/es2021.en/plugins/debug/debug.css +1 -1
- package/es2021.en/plugins/debug/debug.js +1 -1
- package/es2021.en/plugins/debug/debug.min.js +1 -1
- package/es2021.en/plugins/speech-recognize/speech-recognize.css +1 -1
- package/es2021.en/plugins/speech-recognize/speech-recognize.js +8 -8
- package/es2021.en/plugins/speech-recognize/speech-recognize.min.js +2 -2
- package/es5/jodit.css +2 -2
- package/es5/jodit.fat.min.js +2 -2
- package/es5/jodit.js +1299 -1046
- package/es5/jodit.min.css +2 -2
- package/es5/jodit.min.js +2 -2
- package/es5/plugins/debug/debug.css +1 -1
- package/es5/plugins/debug/debug.js +1 -1
- package/es5/plugins/debug/debug.min.js +1 -1
- package/es5/plugins/speech-recognize/speech-recognize.css +1 -1
- package/es5/plugins/speech-recognize/speech-recognize.js +8 -8
- package/es5/plugins/speech-recognize/speech-recognize.min.js +2 -2
- package/es5/polyfills.fat.min.js +1 -1
- package/es5/polyfills.js +1 -1
- package/es5/polyfills.min.js +1 -1
- package/esm/core/constants.js +1 -1
- package/esm/core/dom/dom.js +2 -2
- package/esm/core/helpers/checker/is-html-from-word.d.ts +4 -3
- package/esm/core/helpers/checker/is-html-from-word.js +94 -14
- package/esm/core/helpers/checker/is-html.d.ts +4 -0
- package/esm/core/helpers/checker/is-html.js +54 -2
- package/esm/core/helpers/html/apply-styles.js +20 -11
- package/esm/core/helpers/html/clean-from-word.js +2 -3
- package/esm/core/helpers/html/index.d.ts +1 -0
- package/esm/core/helpers/html/index.js +1 -0
- package/esm/core/helpers/html/tag-scan.d.ts +36 -0
- package/esm/core/helpers/html/tag-scan.js +257 -0
- package/esm/core/helpers/string/trim.d.ts +4 -0
- package/esm/core/helpers/string/trim.js +29 -10
- package/esm/core/selection/helpers/index.js +3 -2
- package/esm/jodit.js +2 -1
- package/esm/plugins/delete/delete.d.ts +6 -0
- package/esm/plugins/delete/delete.js +61 -2
- package/esm/plugins/iframe/iframe.js +59 -12
- package/esm/plugins/media/media.js +2 -4
- package/esm/plugins/paste/helpers.js +4 -2
- package/esm/plugins/resizer/resizer.js +2 -4
- package/package.json +1 -1
- package/types/core/helpers/checker/is-html-from-word.d.ts +4 -3
- package/types/core/helpers/checker/is-html.d.ts +4 -0
- package/types/core/helpers/html/index.d.ts +1 -0
- package/types/core/helpers/html/tag-scan.d.ts +36 -0
- package/types/core/helpers/string/trim.d.ts +4 -0
- package/types/plugins/delete/delete.d.ts +6 -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
|
-
|
|
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
|
-
|
|
30
|
-
|
|
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 {
|
|
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
|
|
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
|
|
413
|
+
value = removeEmptyMarkedTags(value, 'span', 'id="jodit-selection_marker_');
|
|
413
414
|
}
|
|
414
415
|
if (value === '<br>') {
|
|
415
416
|
value = '';
|
|
@@ -38,6 +38,12 @@ export declare class deleteCommand extends Plugin {
|
|
|
38
38
|
* delete and in Backspace without a selection (#1522)
|
|
39
39
|
*/
|
|
40
40
|
private __keepSpacesVisible;
|
|
41
|
+
/**
|
|
42
|
+
* A deletion that starts or ends in a table leaves the fake between the
|
|
43
|
+
* table and the block it reached into, and a space at that block's edge
|
|
44
|
+
* would be hidden as well (#1783)
|
|
45
|
+
*/
|
|
46
|
+
private __keepSpacesVisibleBesideTable;
|
|
41
47
|
/**
|
|
42
48
|
* The text, line break or other element next to the caret in its block,
|
|
43
49
|
* looking inside inline elements
|
|
@@ -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 ||
|
|
@@ -81,6 +95,7 @@ export class deleteCommand extends Plugin {
|
|
|
81
95
|
const rightSibling = Dom.findSibling(fake, false);
|
|
82
96
|
this.__moveContentInLeftSibling(fake, leftSibling, rightSibling);
|
|
83
97
|
this.__keepSpacesVisible(fake);
|
|
98
|
+
this.__keepSpacesVisibleBesideTable(fake);
|
|
84
99
|
range.setStartBefore(fake);
|
|
85
100
|
range.collapse(true);
|
|
86
101
|
this.__moveCursorInEditableSibling(jodit, leftSibling, fake, range);
|
|
@@ -109,6 +124,9 @@ export class deleteCommand extends Plugin {
|
|
|
109
124
|
const endTable = Dom.closest(endCell, 'table', editor);
|
|
110
125
|
const caret = range.cloneRange();
|
|
111
126
|
caret.collapse(true);
|
|
127
|
+
// Where the selection ends, which follows the deletion in its cell
|
|
128
|
+
const end = range.cloneRange();
|
|
129
|
+
end.collapse(false);
|
|
112
130
|
const parts = [];
|
|
113
131
|
const addParts = (table) => {
|
|
114
132
|
toArray(table.rows)
|
|
@@ -143,7 +161,22 @@ export class deleteCommand extends Plugin {
|
|
|
143
161
|
if (Dom.isEmpty(cell)) {
|
|
144
162
|
Dom.detach(cell);
|
|
145
163
|
Dom.append(cell, createInside.element('br'));
|
|
164
|
+
return;
|
|
146
165
|
}
|
|
166
|
+
// A space left at the cell's edge, where the selection started or
|
|
167
|
+
// ended in it, would be hidden, as at a block's (#1783). Each edge
|
|
168
|
+
// moves beside its fake, as making the space non-breaking would
|
|
169
|
+
// move it to the start of its text
|
|
170
|
+
[caret, end]
|
|
171
|
+
.filter(edge => Dom.isOrContains(cell, edge.startContainer))
|
|
172
|
+
.forEach(edge => {
|
|
173
|
+
const fake = createInside.fake();
|
|
174
|
+
edge.insertNode(fake);
|
|
175
|
+
this.__keepSpacesVisible(fake);
|
|
176
|
+
edge.setStartBefore(fake);
|
|
177
|
+
edge.collapse(true);
|
|
178
|
+
Dom.safeRemove(fake);
|
|
179
|
+
});
|
|
147
180
|
});
|
|
148
181
|
return startTable ? caret : null;
|
|
149
182
|
}
|
|
@@ -200,11 +233,37 @@ export class deleteCommand extends Plugin {
|
|
|
200
233
|
const before = this.__findNeighbor(fake, true, block);
|
|
201
234
|
const after = this.__findNeighbor(fake, false, block);
|
|
202
235
|
if (Dom.isText(before) && hidesSpace(after, /^ /)) {
|
|
203
|
-
before.nodeValue = before.nodeValue
|
|
236
|
+
before.nodeValue = replaceEdgeSpaces(before.nodeValue, true);
|
|
204
237
|
}
|
|
205
238
|
if (Dom.isText(after) && hidesSpace(before, / $/)) {
|
|
206
|
-
after.nodeValue = after.nodeValue
|
|
239
|
+
after.nodeValue = replaceEdgeSpaces(after.nodeValue, false);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* A deletion that starts or ends in a table leaves the fake between the
|
|
244
|
+
* table and the block it reached into, and a space at that block's edge
|
|
245
|
+
* would be hidden as well (#1783)
|
|
246
|
+
*/
|
|
247
|
+
__keepSpacesVisibleBesideTable(fake) {
|
|
248
|
+
const before = Dom.findNotEmptySibling(fake, true);
|
|
249
|
+
const after = Dom.findNotEmptySibling(fake, false);
|
|
250
|
+
const block = Dom.isTag(after, 'table')
|
|
251
|
+
? before
|
|
252
|
+
: Dom.isTag(before, 'table')
|
|
253
|
+
? after
|
|
254
|
+
: null;
|
|
255
|
+
if (!Dom.isBlock(block) || Dom.isTag(block, 'table')) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const edge = this.jodit.createInside.fake();
|
|
259
|
+
if (block === before) {
|
|
260
|
+
Dom.append(block, edge);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
block.insertBefore(edge, block.firstChild);
|
|
207
264
|
}
|
|
265
|
+
this.__keepSpacesVisible(edge);
|
|
266
|
+
Dom.safeRemove(edge);
|
|
208
267
|
}
|
|
209
268
|
/**
|
|
210
269
|
* The text, line break or other element next to the caret in its block,
|
|
@@ -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
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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>'), '<span', '>', '</span>');
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
@@ -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;
|