@atlaskit/editor-wikimarkup-transformer 11.1.14 → 11.1.16

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,17 @@
1
1
  # @atlaskit/editor-wikimarkup-transformer
2
2
 
3
+ ## 11.1.16
4
+
5
+ ### Patch Changes
6
+
7
+ - [`5ae242b554c`](https://bitbucket.org/atlassian/atlassian-frontend/commits/5ae242b554c) - updated logic to handle multiple linebreaks inside a macro within a list
8
+
9
+ ## 11.1.15
10
+
11
+ ### Patch Changes
12
+
13
+ - [`7c57f6550f7`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7c57f6550f7) - Updated metacharacter escaping logic in encoder
14
+
3
15
  ## 11.1.14
4
16
 
5
17
  ### Patch Changes
@@ -30,6 +30,7 @@ var markEncoderMapping = new Map([['em', _em.em], ['strike', _strike.strike], ['
30
30
  */
31
31
  var MENTION_ESCAPE_PATTERN = '(\\[~)'; // Matches pattern like [~
32
32
  var MEDIA_ESCAPE_PATTERN = '(![^ !]+)(!)'; // Matches non space content between two consecutive "!" e.g. !filename.txt!
33
+ var MEDIA_GROUP_ESCAPE_PATTERN = '(\\[\\^[^ ]+)(\\])'; // Matches non space content between two consecutive "[^" "]" e.g. [^filename.txt]
33
34
 
34
35
  /**
35
36
  * Checks if the node's content needs to be escaped before continuing processing.
@@ -53,9 +54,9 @@ function escapingWikiFormatter(text) {
53
54
  var pattern = [MENTION_ESCAPE_PATTERN].concat((0, _toConsumableArray2.default)(_keyword.macroKeywordTokenMap.map(function (macro) {
54
55
  return "(".concat(macro.regex.source.replace('^', ''), ")");
55
56
  }))).join('|');
56
- return text.replace(new RegExp(pattern, 'g'), '\\$&').replace(new RegExp(MEDIA_ESCAPE_PATTERN, 'g'), '\\$1\\$2'); // Extra step required for media as currently both ends need to be escaped e.q. !filename.txt!
57
+ return text.replace(new RegExp(pattern, 'g'), '\\$&').replace(new RegExp(MEDIA_ESCAPE_PATTERN, 'g'), '\\$1\\$2') // Extra step required for media as currently both ends need to be escaped e.q. !filename.txt!
58
+ .replace(new RegExp(MEDIA_GROUP_ESCAPE_PATTERN, 'g'), '\\$1\\$2');
57
59
  }
58
-
59
60
  var text = function text(node) {
60
61
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
61
62
  parent = _ref.parent;
@@ -42,8 +42,16 @@ var list = function list(_ref) {
42
42
  var builder = null;
43
43
  var contentBuffer = [];
44
44
  var output = [];
45
+ var isWithinMacro = false;
46
+ var macroLength = 0;
45
47
  while (index < input.length) {
46
48
  var char = input.charAt(index);
49
+
50
+ // Reset macro flags -> if we finished parsing the macro block. There can be multiple concecutive macros in a same listItem
51
+ if (isWithinMacro && index === macroLength) {
52
+ isWithinMacro = false;
53
+ macroLength = 0;
54
+ }
47
55
  switch (state) {
48
56
  case processState.NEW_LINE:
49
57
  {
@@ -107,7 +115,8 @@ var list = function list(_ref) {
107
115
 
108
116
  // If we encounter an empty line, we should end the list
109
117
  var emptyLineMatch = substring.match(EMPTY_LINE_REGEXP);
110
- if (emptyLineMatch) {
118
+ // ADFEXP-371 -> We should not end the list if we are inside a macro and we encountered a new line
119
+ if (emptyLineMatch && !isWithinMacro) {
111
120
  state = processState.END;
112
121
  continue;
113
122
  }
@@ -143,33 +152,42 @@ var list = function list(_ref) {
143
152
  if (token.type === 'text') {
144
153
  buffer.push(token.text);
145
154
  } else {
146
- var _contentBuffer3;
147
155
  // We found a macro in the list...
148
156
  if (!builder) {
149
157
  // Something is really wrong here
150
158
  return fallback(input, position);
151
159
  }
152
- if (buffer.length > 0) {
153
- var _contentBuffer2;
154
- /**
155
- * Wrapup what is already in the string buffer and save it to
156
- * contentBuffer
157
- */
158
- var _content = (0, _text.parseString)({
159
- ignoreTokenTypes: ignoreTokenTypes,
160
- schema: schema,
161
- context: context,
162
- input: buffer.join(''),
163
- includeLeadingSpace: true
164
- });
165
- (_contentBuffer2 = contentBuffer).push.apply(_contentBuffer2, (0, _toConsumableArray2.default)(sanitize(_content, schema)));
166
- buffer = [];
160
+ // if (buffer.length > 0) {
161
+ // /**
162
+ // * Wrapup what is already in the string buffer and save it to
163
+ // * contentBuffer
164
+ // */
165
+ // const content = parseString({
166
+ // ignoreTokenTypes,
167
+ // schema,
168
+ // context,
169
+ // input: buffer.join(''),
170
+ // includeLeadingSpace: true,
171
+ // });
172
+ // contentBuffer.push(...sanitize(content, schema));
173
+ // buffer = [];
174
+ // }
175
+
176
+ // contentBuffer.push(...sanitize(token.nodes, schema));
177
+ // }
178
+ // index += token.length;
179
+ // state = processState.BUFFER;
180
+ // continue;
181
+
182
+ // ADFEXP-371 -> check if we encountered a macro and also that we are not inside a macro block already.
183
+ if (token && !isWithinMacro) {
184
+ isWithinMacro = true;
185
+ // macroLength will help to reset the isWithinMacro flag once we have sucessfully parsed entire macro block
186
+ macroLength = index + token.length;
167
187
  }
168
- (_contentBuffer3 = contentBuffer).push.apply(_contentBuffer3, (0, _toConsumableArray2.default)(sanitize(token.nodes, schema)));
169
188
  }
170
- index += token.length;
171
- state = processState.BUFFER;
172
- continue;
189
+ buffer.push(char);
190
+ break;
173
191
  }
174
192
  case processState.END:
175
193
  {
@@ -178,16 +196,16 @@ var list = function list(_ref) {
178
196
  return fallback(input, position);
179
197
  }
180
198
  if (buffer.length > 0) {
181
- var _contentBuffer4;
199
+ var _contentBuffer2;
182
200
  // Wrap up previous list item and clear buffer
183
- var _content2 = (0, _text.parseString)({
201
+ var _content = (0, _text.parseString)({
184
202
  ignoreTokenTypes: ignoreTokenTypes,
185
203
  schema: schema,
186
204
  context: context,
187
205
  input: buffer.join(''),
188
206
  includeLeadingSpace: true
189
207
  });
190
- (_contentBuffer4 = contentBuffer).push.apply(_contentBuffer4, (0, _toConsumableArray2.default)(_content2));
208
+ (_contentBuffer2 = contentBuffer).push.apply(_contentBuffer2, (0, _toConsumableArray2.default)(_content));
191
209
  }
192
210
  builder.add([{
193
211
  style: lastListSymbols,
@@ -204,16 +222,16 @@ var list = function list(_ref) {
204
222
  index++;
205
223
  }
206
224
  if (buffer.length > 0) {
207
- var _contentBuffer5;
225
+ var _contentBuffer3;
208
226
  // Wrap up what's left in the buffer
209
- var _content3 = (0, _text.parseString)({
227
+ var _content2 = (0, _text.parseString)({
210
228
  ignoreTokenTypes: ignoreTokenTypes,
211
229
  schema: schema,
212
230
  context: context,
213
231
  input: buffer.join(''),
214
232
  includeLeadingSpace: true
215
233
  });
216
- (_contentBuffer5 = contentBuffer).push.apply(_contentBuffer5, (0, _toConsumableArray2.default)(_content3));
234
+ (_contentBuffer3 = contentBuffer).push.apply(_contentBuffer3, (0, _toConsumableArray2.default)(_content2));
217
235
  }
218
236
  if (builder) {
219
237
  builder.add([{
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-wikimarkup-transformer",
3
- "version": "11.1.14",
3
+ "version": "11.1.16",
4
4
  "sideEffects": false
5
5
  }
@@ -23,6 +23,7 @@ const markEncoderMapping = new Map([['em', em], ['strike', strike], ['strong', s
23
23
  */
24
24
  const MENTION_ESCAPE_PATTERN = '(\\[~)'; // Matches pattern like [~
25
25
  const MEDIA_ESCAPE_PATTERN = '(![^ !]+)(!)'; // Matches non space content between two consecutive "!" e.g. !filename.txt!
26
+ const MEDIA_GROUP_ESCAPE_PATTERN = '(\\[\\^[^ ]+)(\\])'; // Matches non space content between two consecutive "[^" "]" e.g. [^filename.txt]
26
27
 
27
28
  /**
28
29
  * Checks if the node's content needs to be escaped before continuing processing.
@@ -42,9 +43,9 @@ const isEscapeNeeded = (node, parent) => {
42
43
  */
43
44
  function escapingWikiFormatter(text) {
44
45
  const pattern = [MENTION_ESCAPE_PATTERN, ...macroKeywordTokenMap.map(macro => `(${macro.regex.source.replace('^', '')})`)].join('|');
45
- return text.replace(new RegExp(pattern, 'g'), '\\$&').replace(new RegExp(MEDIA_ESCAPE_PATTERN, 'g'), '\\$1\\$2'); // Extra step required for media as currently both ends need to be escaped e.q. !filename.txt!
46
+ return text.replace(new RegExp(pattern, 'g'), '\\$&').replace(new RegExp(MEDIA_ESCAPE_PATTERN, 'g'), '\\$1\\$2') // Extra step required for media as currently both ends need to be escaped e.q. !filename.txt!
47
+ .replace(new RegExp(MEDIA_GROUP_ESCAPE_PATTERN, 'g'), '\\$1\\$2');
46
48
  }
47
-
48
49
  export const text = (node, {
49
50
  parent
50
51
  } = {}) => {
@@ -33,8 +33,16 @@ export const list = ({
33
33
  let builder = null;
34
34
  let contentBuffer = [];
35
35
  const output = [];
36
+ let isWithinMacro = false;
37
+ let macroLength = 0;
36
38
  while (index < input.length) {
37
39
  const char = input.charAt(index);
40
+
41
+ // Reset macro flags -> if we finished parsing the macro block. There can be multiple concecutive macros in a same listItem
42
+ if (isWithinMacro && index === macroLength) {
43
+ isWithinMacro = false;
44
+ macroLength = 0;
45
+ }
38
46
  switch (state) {
39
47
  case processState.NEW_LINE:
40
48
  {
@@ -96,7 +104,8 @@ export const list = ({
96
104
 
97
105
  // If we encounter an empty line, we should end the list
98
106
  const emptyLineMatch = substring.match(EMPTY_LINE_REGEXP);
99
- if (emptyLineMatch) {
107
+ // ADFEXP-371 -> We should not end the list if we are inside a macro and we encountered a new line
108
+ if (emptyLineMatch && !isWithinMacro) {
100
109
  state = processState.END;
101
110
  continue;
102
111
  }
@@ -137,26 +146,37 @@ export const list = ({
137
146
  // Something is really wrong here
138
147
  return fallback(input, position);
139
148
  }
140
- if (buffer.length > 0) {
141
- /**
142
- * Wrapup what is already in the string buffer and save it to
143
- * contentBuffer
144
- */
145
- const content = parseString({
146
- ignoreTokenTypes,
147
- schema,
148
- context,
149
- input: buffer.join(''),
150
- includeLeadingSpace: true
151
- });
152
- contentBuffer.push(...sanitize(content, schema));
153
- buffer = [];
149
+ // if (buffer.length > 0) {
150
+ // /**
151
+ // * Wrapup what is already in the string buffer and save it to
152
+ // * contentBuffer
153
+ // */
154
+ // const content = parseString({
155
+ // ignoreTokenTypes,
156
+ // schema,
157
+ // context,
158
+ // input: buffer.join(''),
159
+ // includeLeadingSpace: true,
160
+ // });
161
+ // contentBuffer.push(...sanitize(content, schema));
162
+ // buffer = [];
163
+ // }
164
+
165
+ // contentBuffer.push(...sanitize(token.nodes, schema));
166
+ // }
167
+ // index += token.length;
168
+ // state = processState.BUFFER;
169
+ // continue;
170
+
171
+ // ADFEXP-371 -> check if we encountered a macro and also that we are not inside a macro block already.
172
+ if (token && !isWithinMacro) {
173
+ isWithinMacro = true;
174
+ // macroLength will help to reset the isWithinMacro flag once we have sucessfully parsed entire macro block
175
+ macroLength = index + token.length;
154
176
  }
155
- contentBuffer.push(...sanitize(token.nodes, schema));
156
177
  }
157
- index += token.length;
158
- state = processState.BUFFER;
159
- continue;
178
+ buffer.push(char);
179
+ break;
160
180
  }
161
181
  case processState.END:
162
182
  {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-wikimarkup-transformer",
3
- "version": "11.1.14",
3
+ "version": "11.1.16",
4
4
  "sideEffects": false
5
5
  }
@@ -24,6 +24,7 @@ var markEncoderMapping = new Map([['em', em], ['strike', strike], ['strong', str
24
24
  */
25
25
  var MENTION_ESCAPE_PATTERN = '(\\[~)'; // Matches pattern like [~
26
26
  var MEDIA_ESCAPE_PATTERN = '(![^ !]+)(!)'; // Matches non space content between two consecutive "!" e.g. !filename.txt!
27
+ var MEDIA_GROUP_ESCAPE_PATTERN = '(\\[\\^[^ ]+)(\\])'; // Matches non space content between two consecutive "[^" "]" e.g. [^filename.txt]
27
28
 
28
29
  /**
29
30
  * Checks if the node's content needs to be escaped before continuing processing.
@@ -47,9 +48,9 @@ function escapingWikiFormatter(text) {
47
48
  var pattern = [MENTION_ESCAPE_PATTERN].concat(_toConsumableArray(macroKeywordTokenMap.map(function (macro) {
48
49
  return "(".concat(macro.regex.source.replace('^', ''), ")");
49
50
  }))).join('|');
50
- return text.replace(new RegExp(pattern, 'g'), '\\$&').replace(new RegExp(MEDIA_ESCAPE_PATTERN, 'g'), '\\$1\\$2'); // Extra step required for media as currently both ends need to be escaped e.q. !filename.txt!
51
+ return text.replace(new RegExp(pattern, 'g'), '\\$&').replace(new RegExp(MEDIA_ESCAPE_PATTERN, 'g'), '\\$1\\$2') // Extra step required for media as currently both ends need to be escaped e.q. !filename.txt!
52
+ .replace(new RegExp(MEDIA_GROUP_ESCAPE_PATTERN, 'g'), '\\$1\\$2');
51
53
  }
52
-
53
54
  export var text = function text(node) {
54
55
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
55
56
  parent = _ref.parent;
@@ -34,8 +34,16 @@ export var list = function list(_ref) {
34
34
  var builder = null;
35
35
  var contentBuffer = [];
36
36
  var output = [];
37
+ var isWithinMacro = false;
38
+ var macroLength = 0;
37
39
  while (index < input.length) {
38
40
  var char = input.charAt(index);
41
+
42
+ // Reset macro flags -> if we finished parsing the macro block. There can be multiple concecutive macros in a same listItem
43
+ if (isWithinMacro && index === macroLength) {
44
+ isWithinMacro = false;
45
+ macroLength = 0;
46
+ }
39
47
  switch (state) {
40
48
  case processState.NEW_LINE:
41
49
  {
@@ -99,7 +107,8 @@ export var list = function list(_ref) {
99
107
 
100
108
  // If we encounter an empty line, we should end the list
101
109
  var emptyLineMatch = substring.match(EMPTY_LINE_REGEXP);
102
- if (emptyLineMatch) {
110
+ // ADFEXP-371 -> We should not end the list if we are inside a macro and we encountered a new line
111
+ if (emptyLineMatch && !isWithinMacro) {
103
112
  state = processState.END;
104
113
  continue;
105
114
  }
@@ -135,33 +144,42 @@ export var list = function list(_ref) {
135
144
  if (token.type === 'text') {
136
145
  buffer.push(token.text);
137
146
  } else {
138
- var _contentBuffer3;
139
147
  // We found a macro in the list...
140
148
  if (!builder) {
141
149
  // Something is really wrong here
142
150
  return fallback(input, position);
143
151
  }
144
- if (buffer.length > 0) {
145
- var _contentBuffer2;
146
- /**
147
- * Wrapup what is already in the string buffer and save it to
148
- * contentBuffer
149
- */
150
- var _content = parseString({
151
- ignoreTokenTypes: ignoreTokenTypes,
152
- schema: schema,
153
- context: context,
154
- input: buffer.join(''),
155
- includeLeadingSpace: true
156
- });
157
- (_contentBuffer2 = contentBuffer).push.apply(_contentBuffer2, _toConsumableArray(sanitize(_content, schema)));
158
- buffer = [];
152
+ // if (buffer.length > 0) {
153
+ // /**
154
+ // * Wrapup what is already in the string buffer and save it to
155
+ // * contentBuffer
156
+ // */
157
+ // const content = parseString({
158
+ // ignoreTokenTypes,
159
+ // schema,
160
+ // context,
161
+ // input: buffer.join(''),
162
+ // includeLeadingSpace: true,
163
+ // });
164
+ // contentBuffer.push(...sanitize(content, schema));
165
+ // buffer = [];
166
+ // }
167
+
168
+ // contentBuffer.push(...sanitize(token.nodes, schema));
169
+ // }
170
+ // index += token.length;
171
+ // state = processState.BUFFER;
172
+ // continue;
173
+
174
+ // ADFEXP-371 -> check if we encountered a macro and also that we are not inside a macro block already.
175
+ if (token && !isWithinMacro) {
176
+ isWithinMacro = true;
177
+ // macroLength will help to reset the isWithinMacro flag once we have sucessfully parsed entire macro block
178
+ macroLength = index + token.length;
159
179
  }
160
- (_contentBuffer3 = contentBuffer).push.apply(_contentBuffer3, _toConsumableArray(sanitize(token.nodes, schema)));
161
180
  }
162
- index += token.length;
163
- state = processState.BUFFER;
164
- continue;
181
+ buffer.push(char);
182
+ break;
165
183
  }
166
184
  case processState.END:
167
185
  {
@@ -170,16 +188,16 @@ export var list = function list(_ref) {
170
188
  return fallback(input, position);
171
189
  }
172
190
  if (buffer.length > 0) {
173
- var _contentBuffer4;
191
+ var _contentBuffer2;
174
192
  // Wrap up previous list item and clear buffer
175
- var _content2 = parseString({
193
+ var _content = parseString({
176
194
  ignoreTokenTypes: ignoreTokenTypes,
177
195
  schema: schema,
178
196
  context: context,
179
197
  input: buffer.join(''),
180
198
  includeLeadingSpace: true
181
199
  });
182
- (_contentBuffer4 = contentBuffer).push.apply(_contentBuffer4, _toConsumableArray(_content2));
200
+ (_contentBuffer2 = contentBuffer).push.apply(_contentBuffer2, _toConsumableArray(_content));
183
201
  }
184
202
  builder.add([{
185
203
  style: lastListSymbols,
@@ -196,16 +214,16 @@ export var list = function list(_ref) {
196
214
  index++;
197
215
  }
198
216
  if (buffer.length > 0) {
199
- var _contentBuffer5;
217
+ var _contentBuffer3;
200
218
  // Wrap up what's left in the buffer
201
- var _content3 = parseString({
219
+ var _content2 = parseString({
202
220
  ignoreTokenTypes: ignoreTokenTypes,
203
221
  schema: schema,
204
222
  context: context,
205
223
  input: buffer.join(''),
206
224
  includeLeadingSpace: true
207
225
  });
208
- (_contentBuffer5 = contentBuffer).push.apply(_contentBuffer5, _toConsumableArray(_content3));
226
+ (_contentBuffer3 = contentBuffer).push.apply(_contentBuffer3, _toConsumableArray(_content2));
209
227
  }
210
228
  if (builder) {
211
229
  builder.add([{
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-wikimarkup-transformer",
3
- "version": "11.1.14",
3
+ "version": "11.1.16",
4
4
  "sideEffects": false
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-wikimarkup-transformer",
3
- "version": "11.1.14",
3
+ "version": "11.1.16",
4
4
  "description": "Wiki markup transformer for JIRA and Confluence",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -33,7 +33,7 @@
33
33
  "devDependencies": {
34
34
  "@atlaskit/activity": "^1.0.1",
35
35
  "@atlaskit/docs": "*",
36
- "@atlaskit/editor-common": "^72.8.0",
36
+ "@atlaskit/editor-common": "^72.9.0",
37
37
  "@atlaskit/editor-core": "^182.1.0",
38
38
  "@atlaskit/editor-test-helpers": "^18.2.0",
39
39
  "@atlaskit/mention": "^22.0.0",