@atlaskit/editor-plugin-paste 13.3.0 → 13.3.1
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
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-paste
|
|
2
2
|
|
|
3
|
+
## 13.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`73743eb8b36e6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/73743eb8b36e6) -
|
|
8
|
+
CLeanup prefer static regex violations
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
3
11
|
## 13.3.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
|
@@ -29,6 +29,23 @@ var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
|
29
29
|
var _utils3 = require("@atlaskit/editor-tables/utils");
|
|
30
30
|
var _mediaClient = require("@atlaskit/media-client");
|
|
31
31
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
32
|
+
// Ignored via go/ees005
|
|
33
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
34
|
+
var HTML_CONTAINS_SINGLE_FILE_REGEX = /<img .*>/;
|
|
35
|
+
// Ignored via go/ees005
|
|
36
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
37
|
+
var ESCAPE_LINKS_INNER_REGEX = /^(https?|ftp|jamfselfservice):\/\/[^\s>"]+$/;
|
|
38
|
+
// Allows up to 3 leading spaces before ``` and optional trailing characters
|
|
39
|
+
// Ignored via go/ees005
|
|
40
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
41
|
+
var OPENING_CODE_FENCE_REGEX = /^( {0,3})```.*$/;
|
|
42
|
+
// Allows up to 3 leading spaces before ``` and optional trailing spaces or tabs
|
|
43
|
+
// Ignored via go/ees005
|
|
44
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
45
|
+
var CLOSING_CODE_FENCE_REGEX = /^( {0,3})```[ ]*$/;
|
|
46
|
+
// Ignored via go/ees005
|
|
47
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
48
|
+
var SPLIT_ON_ANCHOR_REGEX = /(?=<a)/;
|
|
32
49
|
function isPastedFromWord(html) {
|
|
33
50
|
return !!html && html.indexOf('urn:schemas-microsoft-com:office:word') >= 0;
|
|
34
51
|
}
|
|
@@ -63,9 +80,7 @@ var isSingleLine = exports.isSingleLine = function isSingleLine(text) {
|
|
|
63
80
|
return !!text && text.trim().split('\n').length === 1;
|
|
64
81
|
};
|
|
65
82
|
function htmlContainsSingleFile(html) {
|
|
66
|
-
|
|
67
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
68
|
-
return !!html.match(/<img .*>/) && !(0, _mediaClient.isMediaBlobUrl)(html);
|
|
83
|
+
return !!html.match(HTML_CONTAINS_SINGLE_FILE_REGEX) && !(0, _mediaClient.isMediaBlobUrl)(html);
|
|
69
84
|
}
|
|
70
85
|
function getPasteSource(event) {
|
|
71
86
|
// Ignored via go/ees005
|
|
@@ -110,9 +125,7 @@ function escapeLinks(text) {
|
|
|
110
125
|
// Ignored via go/ees005
|
|
111
126
|
// eslint-disable-next-line require-unicode-regexp
|
|
112
127
|
return text.replace(/(\[([^\]]+)\]\()?((https?|ftp|jamfselfservice):\/\/[^\s>"]+)/g, function (str) {
|
|
113
|
-
|
|
114
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
115
|
-
return str.match(/^(https?|ftp|jamfselfservice):\/\/[^\s>"]+$/) ? "<".concat(str, ">") : str;
|
|
128
|
+
return str.match(ESCAPE_LINKS_INNER_REGEX) ? "<".concat(str, ">") : str;
|
|
116
129
|
});
|
|
117
130
|
}
|
|
118
131
|
|
|
@@ -127,23 +140,15 @@ function escapeLinks(text) {
|
|
|
127
140
|
*/
|
|
128
141
|
function escapeBackslashAndLinksExceptCodeBlock(textInput) {
|
|
129
142
|
// ref: https://spec.commonmark.org/0.31.2/#fenced-code-blocks
|
|
130
|
-
// Allows up to 3 leading spaces before ``` and optional trailing characters
|
|
131
|
-
// Ignored via go/ees005
|
|
132
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
133
|
-
var openingCodeFenceRegex = /^( {0,3})```.*$/;
|
|
134
|
-
// Allows up to 3 leading spaces before ``` and optional trailing spaces or tabs
|
|
135
|
-
// Ignored via go/ees005
|
|
136
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
137
|
-
var closingCodeFenceRegex = /^( {0,3})```[ \t]*$/;
|
|
138
143
|
var isInsideCodeBlock = false;
|
|
139
144
|
var lines = textInput.split('\n');
|
|
140
145
|
// In the splitted array, we traverse through every line and check if it will be parsed as a codeblock.
|
|
141
146
|
return lines.map(function (line) {
|
|
142
|
-
if (!isInsideCodeBlock &&
|
|
147
|
+
if (!isInsideCodeBlock && OPENING_CODE_FENCE_REGEX.test(line)) {
|
|
143
148
|
isInsideCodeBlock = true;
|
|
144
149
|
return line;
|
|
145
150
|
}
|
|
146
|
-
if (isInsideCodeBlock &&
|
|
151
|
+
if (isInsideCodeBlock && CLOSING_CODE_FENCE_REGEX.test(line)) {
|
|
147
152
|
isInsideCodeBlock = false;
|
|
148
153
|
return line;
|
|
149
154
|
}
|
|
@@ -244,9 +249,7 @@ var htmlHasInvalidLinkTags = exports.htmlHasInvalidLinkTags = function htmlHasIn
|
|
|
244
249
|
// <li><a href="http://www.atlassian.com\"<a> href="http://www.atlassian.com\"http://www.atlassian.com</a></a></li>">
|
|
245
250
|
var removeDuplicateInvalidLinks = exports.removeDuplicateInvalidLinks = function removeDuplicateInvalidLinks(html) {
|
|
246
251
|
if (htmlHasInvalidLinkTags(html)) {
|
|
247
|
-
|
|
248
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
249
|
-
var htmlArray = html.split(/(?=<a)/);
|
|
252
|
+
var htmlArray = html.split(SPLIT_ON_ANCHOR_REGEX);
|
|
250
253
|
var htmlArrayWithoutInvalidLinks = htmlArray.filter(function (item) {
|
|
251
254
|
return !(item.includes('<a') && item.includes('"></a>')) && !(item.includes('<a') && !item.includes('</a>'));
|
|
252
255
|
});
|
|
@@ -7,6 +7,24 @@ import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
|
7
7
|
import { getSelectedTableInfo, isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
8
8
|
import { isMediaBlobUrl } from '@atlaskit/media-client';
|
|
9
9
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
|
+
|
|
11
|
+
// Ignored via go/ees005
|
|
12
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
13
|
+
const HTML_CONTAINS_SINGLE_FILE_REGEX = /<img .*>/;
|
|
14
|
+
// Ignored via go/ees005
|
|
15
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
16
|
+
const ESCAPE_LINKS_INNER_REGEX = /^(https?|ftp|jamfselfservice):\/\/[^\s>"]+$/;
|
|
17
|
+
// Allows up to 3 leading spaces before ``` and optional trailing characters
|
|
18
|
+
// Ignored via go/ees005
|
|
19
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
20
|
+
const OPENING_CODE_FENCE_REGEX = /^( {0,3})```.*$/;
|
|
21
|
+
// Allows up to 3 leading spaces before ``` and optional trailing spaces or tabs
|
|
22
|
+
// Ignored via go/ees005
|
|
23
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
24
|
+
const CLOSING_CODE_FENCE_REGEX = /^( {0,3})```[ ]*$/;
|
|
25
|
+
// Ignored via go/ees005
|
|
26
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
27
|
+
const SPLIT_ON_ANCHOR_REGEX = /(?=<a)/;
|
|
10
28
|
export function isPastedFromWord(html) {
|
|
11
29
|
return !!html && html.indexOf('urn:schemas-microsoft-com:office:word') >= 0;
|
|
12
30
|
}
|
|
@@ -41,9 +59,7 @@ export const isSingleLine = text => {
|
|
|
41
59
|
return !!text && text.trim().split('\n').length === 1;
|
|
42
60
|
};
|
|
43
61
|
export function htmlContainsSingleFile(html) {
|
|
44
|
-
|
|
45
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
46
|
-
return !!html.match(/<img .*>/) && !isMediaBlobUrl(html);
|
|
62
|
+
return !!html.match(HTML_CONTAINS_SINGLE_FILE_REGEX) && !isMediaBlobUrl(html);
|
|
47
63
|
}
|
|
48
64
|
export function getPasteSource(event) {
|
|
49
65
|
// Ignored via go/ees005
|
|
@@ -88,9 +104,7 @@ export function escapeLinks(text) {
|
|
|
88
104
|
// Ignored via go/ees005
|
|
89
105
|
// eslint-disable-next-line require-unicode-regexp
|
|
90
106
|
return text.replace(/(\[([^\]]+)\]\()?((https?|ftp|jamfselfservice):\/\/[^\s>"]+)/g, str => {
|
|
91
|
-
|
|
92
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
93
|
-
return str.match(/^(https?|ftp|jamfselfservice):\/\/[^\s>"]+$/) ? `<${str}>` : str;
|
|
107
|
+
return str.match(ESCAPE_LINKS_INNER_REGEX) ? `<${str}>` : str;
|
|
94
108
|
});
|
|
95
109
|
}
|
|
96
110
|
|
|
@@ -105,23 +119,15 @@ export function escapeLinks(text) {
|
|
|
105
119
|
*/
|
|
106
120
|
export function escapeBackslashAndLinksExceptCodeBlock(textInput) {
|
|
107
121
|
// ref: https://spec.commonmark.org/0.31.2/#fenced-code-blocks
|
|
108
|
-
// Allows up to 3 leading spaces before ``` and optional trailing characters
|
|
109
|
-
// Ignored via go/ees005
|
|
110
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
111
|
-
const openingCodeFenceRegex = /^( {0,3})```.*$/;
|
|
112
|
-
// Allows up to 3 leading spaces before ``` and optional trailing spaces or tabs
|
|
113
|
-
// Ignored via go/ees005
|
|
114
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
115
|
-
const closingCodeFenceRegex = /^( {0,3})```[ \t]*$/;
|
|
116
122
|
let isInsideCodeBlock = false;
|
|
117
123
|
const lines = textInput.split('\n');
|
|
118
124
|
// In the splitted array, we traverse through every line and check if it will be parsed as a codeblock.
|
|
119
125
|
return lines.map(line => {
|
|
120
|
-
if (!isInsideCodeBlock &&
|
|
126
|
+
if (!isInsideCodeBlock && OPENING_CODE_FENCE_REGEX.test(line)) {
|
|
121
127
|
isInsideCodeBlock = true;
|
|
122
128
|
return line;
|
|
123
129
|
}
|
|
124
|
-
if (isInsideCodeBlock &&
|
|
130
|
+
if (isInsideCodeBlock && CLOSING_CODE_FENCE_REGEX.test(line)) {
|
|
125
131
|
isInsideCodeBlock = false;
|
|
126
132
|
return line;
|
|
127
133
|
}
|
|
@@ -234,9 +240,7 @@ export const htmlHasInvalidLinkTags = html => {
|
|
|
234
240
|
// <li><a href="http://www.atlassian.com\"<a> href="http://www.atlassian.com\"http://www.atlassian.com</a></a></li>">
|
|
235
241
|
export const removeDuplicateInvalidLinks = html => {
|
|
236
242
|
if (htmlHasInvalidLinkTags(html)) {
|
|
237
|
-
|
|
238
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
239
|
-
const htmlArray = html.split(/(?=<a)/);
|
|
243
|
+
const htmlArray = html.split(SPLIT_ON_ANCHOR_REGEX);
|
|
240
244
|
const htmlArrayWithoutInvalidLinks = htmlArray.filter(item => {
|
|
241
245
|
return !(item.includes('<a') && item.includes('"></a>')) && !(item.includes('<a') && !item.includes('</a>'));
|
|
242
246
|
});
|
|
@@ -8,6 +8,24 @@ import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
|
8
8
|
import { getSelectedTableInfo, isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
9
9
|
import { isMediaBlobUrl } from '@atlaskit/media-client';
|
|
10
10
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
11
|
+
|
|
12
|
+
// Ignored via go/ees005
|
|
13
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
14
|
+
var HTML_CONTAINS_SINGLE_FILE_REGEX = /<img .*>/;
|
|
15
|
+
// Ignored via go/ees005
|
|
16
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
17
|
+
var ESCAPE_LINKS_INNER_REGEX = /^(https?|ftp|jamfselfservice):\/\/[^\s>"]+$/;
|
|
18
|
+
// Allows up to 3 leading spaces before ``` and optional trailing characters
|
|
19
|
+
// Ignored via go/ees005
|
|
20
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
21
|
+
var OPENING_CODE_FENCE_REGEX = /^( {0,3})```.*$/;
|
|
22
|
+
// Allows up to 3 leading spaces before ``` and optional trailing spaces or tabs
|
|
23
|
+
// Ignored via go/ees005
|
|
24
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
25
|
+
var CLOSING_CODE_FENCE_REGEX = /^( {0,3})```[ ]*$/;
|
|
26
|
+
// Ignored via go/ees005
|
|
27
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
28
|
+
var SPLIT_ON_ANCHOR_REGEX = /(?=<a)/;
|
|
11
29
|
export function isPastedFromWord(html) {
|
|
12
30
|
return !!html && html.indexOf('urn:schemas-microsoft-com:office:word') >= 0;
|
|
13
31
|
}
|
|
@@ -42,9 +60,7 @@ export var isSingleLine = function isSingleLine(text) {
|
|
|
42
60
|
return !!text && text.trim().split('\n').length === 1;
|
|
43
61
|
};
|
|
44
62
|
export function htmlContainsSingleFile(html) {
|
|
45
|
-
|
|
46
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
47
|
-
return !!html.match(/<img .*>/) && !isMediaBlobUrl(html);
|
|
63
|
+
return !!html.match(HTML_CONTAINS_SINGLE_FILE_REGEX) && !isMediaBlobUrl(html);
|
|
48
64
|
}
|
|
49
65
|
export function getPasteSource(event) {
|
|
50
66
|
// Ignored via go/ees005
|
|
@@ -89,9 +105,7 @@ export function escapeLinks(text) {
|
|
|
89
105
|
// Ignored via go/ees005
|
|
90
106
|
// eslint-disable-next-line require-unicode-regexp
|
|
91
107
|
return text.replace(/(\[([^\]]+)\]\()?((https?|ftp|jamfselfservice):\/\/[^\s>"]+)/g, function (str) {
|
|
92
|
-
|
|
93
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
94
|
-
return str.match(/^(https?|ftp|jamfselfservice):\/\/[^\s>"]+$/) ? "<".concat(str, ">") : str;
|
|
108
|
+
return str.match(ESCAPE_LINKS_INNER_REGEX) ? "<".concat(str, ">") : str;
|
|
95
109
|
});
|
|
96
110
|
}
|
|
97
111
|
|
|
@@ -106,23 +120,15 @@ export function escapeLinks(text) {
|
|
|
106
120
|
*/
|
|
107
121
|
export function escapeBackslashAndLinksExceptCodeBlock(textInput) {
|
|
108
122
|
// ref: https://spec.commonmark.org/0.31.2/#fenced-code-blocks
|
|
109
|
-
// Allows up to 3 leading spaces before ``` and optional trailing characters
|
|
110
|
-
// Ignored via go/ees005
|
|
111
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
112
|
-
var openingCodeFenceRegex = /^( {0,3})```.*$/;
|
|
113
|
-
// Allows up to 3 leading spaces before ``` and optional trailing spaces or tabs
|
|
114
|
-
// Ignored via go/ees005
|
|
115
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
116
|
-
var closingCodeFenceRegex = /^( {0,3})```[ \t]*$/;
|
|
117
123
|
var isInsideCodeBlock = false;
|
|
118
124
|
var lines = textInput.split('\n');
|
|
119
125
|
// In the splitted array, we traverse through every line and check if it will be parsed as a codeblock.
|
|
120
126
|
return lines.map(function (line) {
|
|
121
|
-
if (!isInsideCodeBlock &&
|
|
127
|
+
if (!isInsideCodeBlock && OPENING_CODE_FENCE_REGEX.test(line)) {
|
|
122
128
|
isInsideCodeBlock = true;
|
|
123
129
|
return line;
|
|
124
130
|
}
|
|
125
|
-
if (isInsideCodeBlock &&
|
|
131
|
+
if (isInsideCodeBlock && CLOSING_CODE_FENCE_REGEX.test(line)) {
|
|
126
132
|
isInsideCodeBlock = false;
|
|
127
133
|
return line;
|
|
128
134
|
}
|
|
@@ -223,9 +229,7 @@ export var htmlHasInvalidLinkTags = function htmlHasInvalidLinkTags(html) {
|
|
|
223
229
|
// <li><a href="http://www.atlassian.com\"<a> href="http://www.atlassian.com\"http://www.atlassian.com</a></a></li>">
|
|
224
230
|
export var removeDuplicateInvalidLinks = function removeDuplicateInvalidLinks(html) {
|
|
225
231
|
if (htmlHasInvalidLinkTags(html)) {
|
|
226
|
-
|
|
227
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
228
|
-
var htmlArray = html.split(/(?=<a)/);
|
|
232
|
+
var htmlArray = html.split(SPLIT_ON_ANCHOR_REGEX);
|
|
229
233
|
var htmlArrayWithoutInvalidLinks = htmlArray.filter(function (item) {
|
|
230
234
|
return !(item.includes('<a') && item.includes('"></a>')) && !(item.includes('<a') && !item.includes('</a>'));
|
|
231
235
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-paste",
|
|
3
|
-
"version": "13.3.
|
|
3
|
+
"version": "13.3.1",
|
|
4
4
|
"description": "Paste plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@atlaskit/adf-schema": "^56.0.0",
|
|
23
23
|
"@atlaskit/adf-utils": "^20.0.0",
|
|
24
|
-
"@atlaskit/code": "^18.
|
|
24
|
+
"@atlaskit/code": "^18.2.0",
|
|
25
25
|
"@atlaskit/editor-markdown-transformer": "^6.0.0",
|
|
26
26
|
"@atlaskit/editor-plugin-analytics": "^12.0.0",
|
|
27
27
|
"@atlaskit/editor-plugin-annotation": "^12.0.0",
|
|
@@ -34,21 +34,21 @@
|
|
|
34
34
|
"@atlaskit/editor-plugin-mentions": "^14.5.0",
|
|
35
35
|
"@atlaskit/editor-prosemirror": "^8.0.0",
|
|
36
36
|
"@atlaskit/editor-tables": "^3.0.0",
|
|
37
|
-
"@atlaskit/flag": "^18.
|
|
38
|
-
"@atlaskit/icon": "^36.
|
|
37
|
+
"@atlaskit/flag": "^18.1.0",
|
|
38
|
+
"@atlaskit/icon": "^36.1.0",
|
|
39
39
|
"@atlaskit/insm": "^1.0.0",
|
|
40
40
|
"@atlaskit/media-client": "^37.1.0",
|
|
41
|
-
"@atlaskit/media-common": "^14.
|
|
41
|
+
"@atlaskit/media-common": "^14.2.0",
|
|
42
42
|
"@atlaskit/platform-feature-flags": "^2.0.0",
|
|
43
43
|
"@atlaskit/prosemirror-history": "^1.0.0",
|
|
44
|
-
"@atlaskit/tmp-editor-statsig": "^114.
|
|
45
|
-
"@atlaskit/tokens": "^15.
|
|
44
|
+
"@atlaskit/tmp-editor-statsig": "^114.5.0",
|
|
45
|
+
"@atlaskit/tokens": "^15.2.0",
|
|
46
46
|
"@babel/runtime": "^7.0.0",
|
|
47
47
|
"lodash": "^4.17.21",
|
|
48
48
|
"uuid": "^3.1.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@atlaskit/editor-common": "^116.
|
|
51
|
+
"@atlaskit/editor-common": "^116.17.0",
|
|
52
52
|
"react": "^18.2.0",
|
|
53
53
|
"react-dom": "^18.2.0",
|
|
54
54
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|