@atlaskit/editor-plugin-paste 7.0.2 → 7.0.3

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
+ ## 7.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`2a6da53855a0e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2a6da53855a0e) -
8
+ [ux] While copy/pasting as plain text, allow code fence to have up to three spaces.
9
+ - Updated dependencies
10
+
3
11
  ## 7.0.2
4
12
 
5
13
  ### Patch Changes
@@ -121,30 +121,66 @@ function escapeLinks(text) {
121
121
  * const output = escapeBackslashAndLinksExceptCodeBlock(input); // 'This is a link: <https://example.com> and a backslash: \\\\\n```\ncode block https://example.com not escaped\ncode block \\ not escaped\n```'
122
122
  */
123
123
  function escapeBackslashAndLinksExceptCodeBlock(textInput) {
124
- var codeToken = '```';
125
- var isInsideCodeBlock = false;
126
- var lines = textInput.split('\n');
127
- // In the splitted array, we traverse through every line and check if it will be parsed as a codeblock.
128
- return lines.map(function (line) {
129
- if (line === codeToken) {
130
- // Toggle code block state
131
- isInsideCodeBlock = !isInsideCodeBlock;
132
- return line;
133
- } else if (line.startsWith(codeToken) && !isInsideCodeBlock) {
134
- // if there is some text after the ``` mark , it gets counted as language attribute only at the start of codeblock
135
- isInsideCodeBlock = true;
124
+ if ((0, _platformFeatureFlags.fg)('platform_editor_paste_code_fence_spaces')) {
125
+ // ref: https://spec.commonmark.org/0.31.2/#fenced-code-blocks
126
+ // Allows up to 3 leading spaces before ``` and optional trailing characters
127
+ // Ignored via go/ees005
128
+ // eslint-disable-next-line require-unicode-regexp
129
+ var openingCodeFenceRegex = /^( {0,3})```.*$/;
130
+ // Allows up to 3 leading spaces before ``` and optional trailing spaces or tabs
131
+ // Ignored via go/ees005
132
+ // eslint-disable-next-line require-unicode-regexp
133
+ var closingCodeFenceRegex = /^( {0,3})```[ \t]*$/;
134
+ var isInsideCodeBlock = false;
135
+ var lines = textInput.split('\n');
136
+ // In the splitted array, we traverse through every line and check if it will be parsed as a codeblock.
137
+ return lines.map(function (line) {
138
+ if (!isInsideCodeBlock && openingCodeFenceRegex.test(line)) {
139
+ isInsideCodeBlock = true;
140
+ return line;
141
+ }
142
+ if (isInsideCodeBlock && closingCodeFenceRegex.test(line)) {
143
+ isInsideCodeBlock = false;
144
+ return line;
145
+ }
146
+
147
+ // not code fence, don't escape anything inside code block
148
+ if (isInsideCodeBlock) {
149
+ return line;
150
+ } else {
151
+ // Ignored via go/ees005
152
+ // eslint-disable-next-line require-unicode-regexp
153
+ var escaped = line.replace(/\\/g, '\\\\');
154
+ escaped = escapeLinks(escaped);
155
+ return escaped;
156
+ }
157
+ }).join('\n');
158
+ } else {
159
+ var codeToken = '```';
160
+ var _isInsideCodeBlock = false;
161
+ var _lines = textInput.split('\n');
162
+ // In the splitted array, we traverse through every line and check if it will be parsed as a codeblock.
163
+ return _lines.map(function (line) {
164
+ if (line === codeToken) {
165
+ // Toggle code block state
166
+ _isInsideCodeBlock = !_isInsideCodeBlock;
167
+ return line;
168
+ } else if (line.startsWith(codeToken) && !_isInsideCodeBlock) {
169
+ // if there is some text after the ``` mark , it gets counted as language attribute only at the start of codeblock
170
+ _isInsideCodeBlock = true;
171
+ return line;
172
+ }
173
+ if (!_isInsideCodeBlock) {
174
+ // Only escape outside code blocks
175
+ // Ignored via go/ees005
176
+ // eslint-disable-next-line require-unicode-regexp
177
+ var escaped = line.replace(/\\/g, '\\\\');
178
+ escaped = escapeLinks(escaped);
179
+ return escaped;
180
+ }
136
181
  return line;
137
- }
138
- if (!isInsideCodeBlock) {
139
- // Only escape outside code blocks
140
- // Ignored via go/ees005
141
- // eslint-disable-next-line require-unicode-regexp
142
- var escaped = line.replace(/\\/g, '\\\\');
143
- escaped = escapeLinks(escaped);
144
- return escaped;
145
- }
146
- return line;
147
- }).join('\n');
182
+ }).join('\n');
183
+ }
148
184
  }
149
185
  function hasOnlyNodesOfType() {
150
186
  for (var _len = arguments.length, nodeTypes = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -99,30 +99,66 @@ export function escapeLinks(text) {
99
99
  * const output = escapeBackslashAndLinksExceptCodeBlock(input); // 'This is a link: <https://example.com> and a backslash: \\\\\n```\ncode block https://example.com not escaped\ncode block \\ not escaped\n```'
100
100
  */
101
101
  export function escapeBackslashAndLinksExceptCodeBlock(textInput) {
102
- const codeToken = '```';
103
- let isInsideCodeBlock = false;
104
- const lines = textInput.split('\n');
105
- // In the splitted array, we traverse through every line and check if it will be parsed as a codeblock.
106
- return lines.map(line => {
107
- if (line === codeToken) {
108
- // Toggle code block state
109
- isInsideCodeBlock = !isInsideCodeBlock;
110
- return line;
111
- } else if (line.startsWith(codeToken) && !isInsideCodeBlock) {
112
- // if there is some text after the ``` mark , it gets counted as language attribute only at the start of codeblock
113
- isInsideCodeBlock = true;
102
+ if (fg('platform_editor_paste_code_fence_spaces')) {
103
+ // ref: https://spec.commonmark.org/0.31.2/#fenced-code-blocks
104
+ // Allows up to 3 leading spaces before ``` and optional trailing characters
105
+ // Ignored via go/ees005
106
+ // eslint-disable-next-line require-unicode-regexp
107
+ const openingCodeFenceRegex = /^( {0,3})```.*$/;
108
+ // Allows up to 3 leading spaces before ``` and optional trailing spaces or tabs
109
+ // Ignored via go/ees005
110
+ // eslint-disable-next-line require-unicode-regexp
111
+ const closingCodeFenceRegex = /^( {0,3})```[ \t]*$/;
112
+ let isInsideCodeBlock = false;
113
+ const lines = textInput.split('\n');
114
+ // In the splitted array, we traverse through every line and check if it will be parsed as a codeblock.
115
+ return lines.map(line => {
116
+ if (!isInsideCodeBlock && openingCodeFenceRegex.test(line)) {
117
+ isInsideCodeBlock = true;
118
+ return line;
119
+ }
120
+ if (isInsideCodeBlock && closingCodeFenceRegex.test(line)) {
121
+ isInsideCodeBlock = false;
122
+ return line;
123
+ }
124
+
125
+ // not code fence, don't escape anything inside code block
126
+ if (isInsideCodeBlock) {
127
+ return line;
128
+ } else {
129
+ // Ignored via go/ees005
130
+ // eslint-disable-next-line require-unicode-regexp
131
+ let escaped = line.replace(/\\/g, '\\\\');
132
+ escaped = escapeLinks(escaped);
133
+ return escaped;
134
+ }
135
+ }).join('\n');
136
+ } else {
137
+ const codeToken = '```';
138
+ let isInsideCodeBlock = false;
139
+ const lines = textInput.split('\n');
140
+ // In the splitted array, we traverse through every line and check if it will be parsed as a codeblock.
141
+ return lines.map(line => {
142
+ if (line === codeToken) {
143
+ // Toggle code block state
144
+ isInsideCodeBlock = !isInsideCodeBlock;
145
+ return line;
146
+ } else if (line.startsWith(codeToken) && !isInsideCodeBlock) {
147
+ // if there is some text after the ``` mark , it gets counted as language attribute only at the start of codeblock
148
+ isInsideCodeBlock = true;
149
+ return line;
150
+ }
151
+ if (!isInsideCodeBlock) {
152
+ // Only escape outside code blocks
153
+ // Ignored via go/ees005
154
+ // eslint-disable-next-line require-unicode-regexp
155
+ let escaped = line.replace(/\\/g, '\\\\');
156
+ escaped = escapeLinks(escaped);
157
+ return escaped;
158
+ }
114
159
  return line;
115
- }
116
- if (!isInsideCodeBlock) {
117
- // Only escape outside code blocks
118
- // Ignored via go/ees005
119
- // eslint-disable-next-line require-unicode-regexp
120
- let escaped = line.replace(/\\/g, '\\\\');
121
- escaped = escapeLinks(escaped);
122
- return escaped;
123
- }
124
- return line;
125
- }).join('\n');
160
+ }).join('\n');
161
+ }
126
162
  }
127
163
  export function hasOnlyNodesOfType(...nodeTypes) {
128
164
  return slice => {
@@ -100,30 +100,66 @@ export function escapeLinks(text) {
100
100
  * const output = escapeBackslashAndLinksExceptCodeBlock(input); // 'This is a link: <https://example.com> and a backslash: \\\\\n```\ncode block https://example.com not escaped\ncode block \\ not escaped\n```'
101
101
  */
102
102
  export function escapeBackslashAndLinksExceptCodeBlock(textInput) {
103
- var codeToken = '```';
104
- var isInsideCodeBlock = false;
105
- var lines = textInput.split('\n');
106
- // In the splitted array, we traverse through every line and check if it will be parsed as a codeblock.
107
- return lines.map(function (line) {
108
- if (line === codeToken) {
109
- // Toggle code block state
110
- isInsideCodeBlock = !isInsideCodeBlock;
111
- return line;
112
- } else if (line.startsWith(codeToken) && !isInsideCodeBlock) {
113
- // if there is some text after the ``` mark , it gets counted as language attribute only at the start of codeblock
114
- isInsideCodeBlock = true;
103
+ if (fg('platform_editor_paste_code_fence_spaces')) {
104
+ // ref: https://spec.commonmark.org/0.31.2/#fenced-code-blocks
105
+ // Allows up to 3 leading spaces before ``` and optional trailing characters
106
+ // Ignored via go/ees005
107
+ // eslint-disable-next-line require-unicode-regexp
108
+ var openingCodeFenceRegex = /^( {0,3})```.*$/;
109
+ // Allows up to 3 leading spaces before ``` and optional trailing spaces or tabs
110
+ // Ignored via go/ees005
111
+ // eslint-disable-next-line require-unicode-regexp
112
+ var closingCodeFenceRegex = /^( {0,3})```[ \t]*$/;
113
+ var isInsideCodeBlock = false;
114
+ var lines = textInput.split('\n');
115
+ // In the splitted array, we traverse through every line and check if it will be parsed as a codeblock.
116
+ return lines.map(function (line) {
117
+ if (!isInsideCodeBlock && openingCodeFenceRegex.test(line)) {
118
+ isInsideCodeBlock = true;
119
+ return line;
120
+ }
121
+ if (isInsideCodeBlock && closingCodeFenceRegex.test(line)) {
122
+ isInsideCodeBlock = false;
123
+ return line;
124
+ }
125
+
126
+ // not code fence, don't escape anything inside code block
127
+ if (isInsideCodeBlock) {
128
+ return line;
129
+ } else {
130
+ // Ignored via go/ees005
131
+ // eslint-disable-next-line require-unicode-regexp
132
+ var escaped = line.replace(/\\/g, '\\\\');
133
+ escaped = escapeLinks(escaped);
134
+ return escaped;
135
+ }
136
+ }).join('\n');
137
+ } else {
138
+ var codeToken = '```';
139
+ var _isInsideCodeBlock = false;
140
+ var _lines = textInput.split('\n');
141
+ // In the splitted array, we traverse through every line and check if it will be parsed as a codeblock.
142
+ return _lines.map(function (line) {
143
+ if (line === codeToken) {
144
+ // Toggle code block state
145
+ _isInsideCodeBlock = !_isInsideCodeBlock;
146
+ return line;
147
+ } else if (line.startsWith(codeToken) && !_isInsideCodeBlock) {
148
+ // if there is some text after the ``` mark , it gets counted as language attribute only at the start of codeblock
149
+ _isInsideCodeBlock = true;
150
+ return line;
151
+ }
152
+ if (!_isInsideCodeBlock) {
153
+ // Only escape outside code blocks
154
+ // Ignored via go/ees005
155
+ // eslint-disable-next-line require-unicode-regexp
156
+ var escaped = line.replace(/\\/g, '\\\\');
157
+ escaped = escapeLinks(escaped);
158
+ return escaped;
159
+ }
115
160
  return line;
116
- }
117
- if (!isInsideCodeBlock) {
118
- // Only escape outside code blocks
119
- // Ignored via go/ees005
120
- // eslint-disable-next-line require-unicode-regexp
121
- var escaped = line.replace(/\\/g, '\\\\');
122
- escaped = escapeLinks(escaped);
123
- return escaped;
124
- }
125
- return line;
126
- }).join('\n');
161
+ }).join('\n');
162
+ }
127
163
  }
128
164
  export function hasOnlyNodesOfType() {
129
165
  for (var _len = arguments.length, nodeTypes = new Array(_len), _key = 0; _key < _len; _key++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-paste",
3
- "version": "7.0.2",
3
+ "version": "7.0.3",
4
4
  "description": "Paste plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -33,24 +33,24 @@
33
33
  "@atlaskit/editor-plugin-analytics": "^6.1.0",
34
34
  "@atlaskit/editor-plugin-annotation": "^6.1.0",
35
35
  "@atlaskit/editor-plugin-better-type-history": "^6.0.0",
36
- "@atlaskit/editor-plugin-card": "^11.1.0",
36
+ "@atlaskit/editor-plugin-card": "^11.2.0",
37
37
  "@atlaskit/editor-plugin-feature-flags": "^5.0.0",
38
38
  "@atlaskit/editor-plugin-list": "^8.0.0",
39
- "@atlaskit/editor-plugin-media": "^8.0.0",
39
+ "@atlaskit/editor-plugin-media": "^8.1.0",
40
40
  "@atlaskit/editor-plugin-mentions": "^8.0.0",
41
41
  "@atlaskit/editor-prosemirror": "7.0.0",
42
42
  "@atlaskit/editor-tables": "^2.9.0",
43
43
  "@atlaskit/insm": "^0.1.0",
44
- "@atlaskit/media-client": "^35.3.0",
44
+ "@atlaskit/media-client": "^35.5.0",
45
45
  "@atlaskit/media-common": "^12.3.0",
46
46
  "@atlaskit/platform-feature-flags": "^1.1.0",
47
- "@atlaskit/tmp-editor-statsig": "^13.0.0",
47
+ "@atlaskit/tmp-editor-statsig": "^13.4.0",
48
48
  "@babel/runtime": "^7.0.0",
49
49
  "lodash": "^4.17.21",
50
50
  "uuid": "^3.1.0"
51
51
  },
52
52
  "peerDependencies": {
53
- "@atlaskit/editor-common": "^110.4.0",
53
+ "@atlaskit/editor-common": "^110.7.0",
54
54
  "react": "^18.2.0",
55
55
  "react-dom": "^18.2.0"
56
56
  },
@@ -58,7 +58,7 @@
58
58
  "@af/visual-regression": "workspace:^",
59
59
  "@atlaskit/editor-plugin-block-type": "^9.0.0",
60
60
  "@atlaskit/editor-plugin-history": "^6.0.0",
61
- "@atlaskit/editor-plugin-type-ahead": "^6.1.0",
61
+ "@atlaskit/editor-plugin-type-ahead": "^6.3.0",
62
62
  "@atlaskit/ssr": "workspace:^",
63
63
  "@testing-library/react": "^13.4.0",
64
64
  "wait-for-expect": "^1.2.0"
@@ -123,6 +123,9 @@
123
123
  },
124
124
  "platform_editor_link_paste_select_all": {
125
125
  "type": "boolean"
126
+ },
127
+ "platform_editor_paste_code_fence_spaces": {
128
+ "type": "boolean"
126
129
  }
127
130
  }
128
131
  }