@atlaskit/editor-wikimarkup-transformer 11.1.5 → 11.1.7

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.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [`12399f5aaa1`](https://bitbucket.org/atlassian/atlassian-frontend/commits/12399f5aaa1) - Adding custom regex for escaping of media, link and mention.
8
+
9
+ ## 11.1.6
10
+
11
+ ### Patch Changes
12
+
13
+ - [`ea34f8260e3`](https://bitbucket.org/atlassian/atlassian-frontend/commits/ea34f8260e3) - Wiki to adf: Tables headings to be strong by default
14
+
3
15
  ## 11.1.5
4
16
 
5
17
  ### Patch Changes
@@ -33,6 +33,17 @@ var _underline = require("../marks/underline");
33
33
  * we want to process other marks before it.
34
34
  */
35
35
  var markEncoderMapping = new Map([['em', _em.em], ['strike', _strike.strike], ['strong', _strong.strong], ['subsup', _subsup.subsup], ['underline', _underline.underline], ['textColor', _color.textColor], ['link', _link.link], ['code', _code.code]]);
36
+ /**
37
+ * ADFEXP-131: Improved logic for escaping metacharacters "[" and "!"
38
+ * Before this change, any instance of "[" and "!" was being escaped
39
+ * "[" is used for mentions
40
+ * "!" is used for media
41
+ */
42
+
43
+ var MENTION_ESCAPE_PATTERN = '(\\[~)'; // Matches pattern like [~
44
+
45
+ var MEDIA_ESCAPE_PATTERN = '(![^ !]+)(!)'; // Matches non space content between two consecutive "!" e.g. !filename.txt!
46
+
36
47
  /**
37
48
  * Checks if the node's content needs to be escaped before continuing processing.
38
49
  * Currently, the `code` mark and `codeBlock` nodes handle their own escaping, and
@@ -50,14 +61,15 @@ var isEscapeNeeded = function isEscapeNeeded(node, parent) {
50
61
  };
51
62
  /**
52
63
  * ESS-2569: Removing the backsalshes from the regex
64
+ * ADFEXP-131: Improved logic for escaping metacharacters "[" and "!"
53
65
  */
54
66
 
55
67
 
56
68
  function escapingWikiFormatter(text) {
57
- var pattern = ['([![])'].concat((0, _toConsumableArray2.default)(_keyword.macroKeywordTokenMap.map(function (macro) {
69
+ var pattern = [MENTION_ESCAPE_PATTERN].concat((0, _toConsumableArray2.default)(_keyword.macroKeywordTokenMap.map(function (macro) {
58
70
  return "(".concat(macro.regex.source.replace('^', ''), ")");
59
71
  }))).join('|');
60
- return text.replace(new RegExp(pattern, 'g'), '\\$&');
72
+ 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!
61
73
  }
62
74
 
63
75
  var text = function text(node) {
@@ -1,10 +1,16 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
8
  exports.table = void 0;
7
9
 
10
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
+
12
+ var _prosemirrorModel = require("prosemirror-model");
13
+
8
14
  var _tableBuilder = require("../builder/table-builder");
9
15
 
10
16
  var _text = require("../text");
@@ -23,6 +29,8 @@ var _whitespace = require("./whitespace");
23
29
 
24
30
  var _keyword = require("./keyword");
25
31
 
32
+ var _text2 = require("../utils/text");
33
+
26
34
  /*
27
35
  The following are currently NOT supported
28
36
  1. Macros
@@ -345,9 +353,55 @@ function bufferToCells(style, buffer, cellsBuffer, schema, ignoreTokenTypes, con
345
353
  ignoreTokenTypes: ignoreTokenTypes,
346
354
  input: buffer
347
355
  });
356
+
357
+ if (style === '||') {
358
+ contentNode = contentNode.map(function (e) {
359
+ return createTableHeader(e, schema);
360
+ });
361
+ }
362
+
348
363
  cellsBuffer.push({
349
364
  style: style,
350
365
  content: (0, _normalize.normalizePMNodes)(contentNode, schema)
351
366
  });
352
367
  }
368
+ }
369
+
370
+ function createTableHeader(pmNode, schema) {
371
+ var mark = schema.marks.strong.create();
372
+
373
+ if (pmNode.type.name === 'text' && !(0, _text2.hasAnyOfMarks)(pmNode, ['strong', 'code'])) {
374
+ return pmNode.mark([].concat((0, _toConsumableArray2.default)(pmNode.marks), [mark]));
375
+ } else if (pmNode.childCount > 0 && pmNode.firstChild && pmNode.child(0)) {
376
+ var jsonNode = traverseJsonNodeAndAddMarks(pmNode.toJSON(), 'strong', schema);
377
+ pmNode = _prosemirrorModel.Node.fromJSON(schema, jsonNode);
378
+ return pmNode;
379
+ }
380
+
381
+ return pmNode;
382
+ }
383
+
384
+ function traverseJsonNodeAndAddMarks(node, mark, schema) {
385
+ if (node.type === 'text') {
386
+ if (node.marks && node.marks.find(function (_ref2) {
387
+ var type = _ref2.type;
388
+ return type === 'strong' || type === 'code';
389
+ })) {
390
+ return node;
391
+ }
392
+
393
+ node.marks = node.marks ? [].concat((0, _toConsumableArray2.default)(node.marks), [{
394
+ type: mark
395
+ }]) : [{
396
+ type: mark
397
+ }];
398
+ }
399
+
400
+ if (node.content && Array.isArray(node.content)) {
401
+ node.content.map(function (e) {
402
+ return traverseJsonNodeAndAddMarks(e, mark, schema);
403
+ });
404
+ }
405
+
406
+ return node;
353
407
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-wikimarkup-transformer",
3
- "version": "11.1.5",
3
+ "version": "11.1.7",
4
4
  "sideEffects": false
5
5
  }
@@ -14,6 +14,17 @@ import { underline } from '../marks/underline';
14
14
  */
15
15
 
16
16
  const markEncoderMapping = new Map([['em', em], ['strike', strike], ['strong', strong], ['subsup', subsup], ['underline', underline], ['textColor', textColor], ['link', link], ['code', code]]);
17
+ /**
18
+ * ADFEXP-131: Improved logic for escaping metacharacters "[" and "!"
19
+ * Before this change, any instance of "[" and "!" was being escaped
20
+ * "[" is used for mentions
21
+ * "!" is used for media
22
+ */
23
+
24
+ const MENTION_ESCAPE_PATTERN = '(\\[~)'; // Matches pattern like [~
25
+
26
+ const MEDIA_ESCAPE_PATTERN = '(![^ !]+)(!)'; // Matches non space content between two consecutive "!" e.g. !filename.txt!
27
+
17
28
  /**
18
29
  * Checks if the node's content needs to be escaped before continuing processing.
19
30
  * Currently, the `code` mark and `codeBlock` nodes handle their own escaping, and
@@ -29,12 +40,13 @@ const isEscapeNeeded = (node, parent) => {
29
40
  };
30
41
  /**
31
42
  * ESS-2569: Removing the backsalshes from the regex
43
+ * ADFEXP-131: Improved logic for escaping metacharacters "[" and "!"
32
44
  */
33
45
 
34
46
 
35
47
  function escapingWikiFormatter(text) {
36
- const pattern = ['([![])', ...macroKeywordTokenMap.map(macro => `(${macro.regex.source.replace('^', '')})`)].join('|');
37
- return text.replace(new RegExp(pattern, 'g'), '\\$&');
48
+ const pattern = [MENTION_ESCAPE_PATTERN, ...macroKeywordTokenMap.map(macro => `(${macro.regex.source.replace('^', '')})`)].join('|');
49
+ 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!
38
50
  }
39
51
 
40
52
  export const text = (node, {
@@ -1,3 +1,4 @@
1
+ import { Node as PMNode } from 'prosemirror-model';
1
2
  import { TableBuilder } from '../builder/table-builder';
2
3
  import { parseString } from '../text';
3
4
  import { normalizePMNodes } from '../utils/normalize';
@@ -8,6 +9,7 @@ import { TokenType } from './';
8
9
  import { parseNewlineOnly } from './whitespace';
9
10
  import { parseMacroKeyword } from './keyword';
10
11
  import { parseToken } from './';
12
+ import { hasAnyOfMarks } from '../utils/text';
11
13
  /*
12
14
  The following are currently NOT supported
13
15
  1. Macros
@@ -319,15 +321,58 @@ export const table = ({
319
321
 
320
322
  function bufferToCells(style, buffer, cellsBuffer, schema, ignoreTokenTypes, context) {
321
323
  if (buffer.length) {
322
- const contentNode = parseString({
324
+ let contentNode = parseString({
323
325
  schema,
324
326
  context,
325
327
  ignoreTokenTypes: ignoreTokenTypes,
326
328
  input: buffer
327
329
  });
330
+
331
+ if (style === '||') {
332
+ contentNode = contentNode.map(e => {
333
+ return createTableHeader(e, schema);
334
+ });
335
+ }
336
+
328
337
  cellsBuffer.push({
329
338
  style,
330
339
  content: normalizePMNodes(contentNode, schema)
331
340
  });
332
341
  }
342
+ }
343
+
344
+ function createTableHeader(pmNode, schema) {
345
+ const mark = schema.marks.strong.create();
346
+
347
+ if (pmNode.type.name === 'text' && !hasAnyOfMarks(pmNode, ['strong', 'code'])) {
348
+ return pmNode.mark([...pmNode.marks, mark]);
349
+ } else if (pmNode.childCount > 0 && pmNode.firstChild && pmNode.child(0)) {
350
+ const jsonNode = traverseJsonNodeAndAddMarks(pmNode.toJSON(), 'strong', schema);
351
+ pmNode = PMNode.fromJSON(schema, jsonNode);
352
+ return pmNode;
353
+ }
354
+
355
+ return pmNode;
356
+ }
357
+
358
+ function traverseJsonNodeAndAddMarks(node, mark, schema) {
359
+ if (node.type === 'text') {
360
+ if (node.marks && node.marks.find(({
361
+ type
362
+ }) => type === 'strong' || type === 'code')) {
363
+ return node;
364
+ }
365
+
366
+ node.marks = node.marks ? [...node.marks, {
367
+ type: mark
368
+ }] : [{
369
+ type: mark
370
+ }];
371
+ }
372
+
373
+ if (node.content && Array.isArray(node.content)) {
374
+ node.content.map(e => traverseJsonNodeAndAddMarks(e, mark, schema));
375
+ }
376
+
377
+ return node;
333
378
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-wikimarkup-transformer",
3
- "version": "11.1.5",
3
+ "version": "11.1.7",
4
4
  "sideEffects": false
5
5
  }
@@ -15,6 +15,17 @@ import { underline } from '../marks/underline';
15
15
  */
16
16
 
17
17
  var markEncoderMapping = new Map([['em', em], ['strike', strike], ['strong', strong], ['subsup', subsup], ['underline', underline], ['textColor', textColor], ['link', link], ['code', code]]);
18
+ /**
19
+ * ADFEXP-131: Improved logic for escaping metacharacters "[" and "!"
20
+ * Before this change, any instance of "[" and "!" was being escaped
21
+ * "[" is used for mentions
22
+ * "!" is used for media
23
+ */
24
+
25
+ var MENTION_ESCAPE_PATTERN = '(\\[~)'; // Matches pattern like [~
26
+
27
+ var MEDIA_ESCAPE_PATTERN = '(![^ !]+)(!)'; // Matches non space content between two consecutive "!" e.g. !filename.txt!
28
+
18
29
  /**
19
30
  * Checks if the node's content needs to be escaped before continuing processing.
20
31
  * Currently, the `code` mark and `codeBlock` nodes handle their own escaping, and
@@ -32,14 +43,15 @@ var isEscapeNeeded = function isEscapeNeeded(node, parent) {
32
43
  };
33
44
  /**
34
45
  * ESS-2569: Removing the backsalshes from the regex
46
+ * ADFEXP-131: Improved logic for escaping metacharacters "[" and "!"
35
47
  */
36
48
 
37
49
 
38
50
  function escapingWikiFormatter(text) {
39
- var pattern = ['([![])'].concat(_toConsumableArray(macroKeywordTokenMap.map(function (macro) {
51
+ var pattern = [MENTION_ESCAPE_PATTERN].concat(_toConsumableArray(macroKeywordTokenMap.map(function (macro) {
40
52
  return "(".concat(macro.regex.source.replace('^', ''), ")");
41
53
  }))).join('|');
42
- return text.replace(new RegExp(pattern, 'g'), '\\$&');
54
+ 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!
43
55
  }
44
56
 
45
57
  export var text = function text(node) {
@@ -1,3 +1,5 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import { Node as PMNode } from 'prosemirror-model';
1
3
  import { TableBuilder } from '../builder/table-builder';
2
4
  import { parseString } from '../text';
3
5
  import { normalizePMNodes } from '../utils/normalize';
@@ -8,6 +10,7 @@ import { TokenType } from './';
8
10
  import { parseNewlineOnly } from './whitespace';
9
11
  import { parseMacroKeyword } from './keyword';
10
12
  import { parseToken } from './';
13
+ import { hasAnyOfMarks } from '../utils/text';
11
14
  /*
12
15
  The following are currently NOT supported
13
16
  1. Macros
@@ -328,9 +331,55 @@ function bufferToCells(style, buffer, cellsBuffer, schema, ignoreTokenTypes, con
328
331
  ignoreTokenTypes: ignoreTokenTypes,
329
332
  input: buffer
330
333
  });
334
+
335
+ if (style === '||') {
336
+ contentNode = contentNode.map(function (e) {
337
+ return createTableHeader(e, schema);
338
+ });
339
+ }
340
+
331
341
  cellsBuffer.push({
332
342
  style: style,
333
343
  content: normalizePMNodes(contentNode, schema)
334
344
  });
335
345
  }
346
+ }
347
+
348
+ function createTableHeader(pmNode, schema) {
349
+ var mark = schema.marks.strong.create();
350
+
351
+ if (pmNode.type.name === 'text' && !hasAnyOfMarks(pmNode, ['strong', 'code'])) {
352
+ return pmNode.mark([].concat(_toConsumableArray(pmNode.marks), [mark]));
353
+ } else if (pmNode.childCount > 0 && pmNode.firstChild && pmNode.child(0)) {
354
+ var jsonNode = traverseJsonNodeAndAddMarks(pmNode.toJSON(), 'strong', schema);
355
+ pmNode = PMNode.fromJSON(schema, jsonNode);
356
+ return pmNode;
357
+ }
358
+
359
+ return pmNode;
360
+ }
361
+
362
+ function traverseJsonNodeAndAddMarks(node, mark, schema) {
363
+ if (node.type === 'text') {
364
+ if (node.marks && node.marks.find(function (_ref2) {
365
+ var type = _ref2.type;
366
+ return type === 'strong' || type === 'code';
367
+ })) {
368
+ return node;
369
+ }
370
+
371
+ node.marks = node.marks ? [].concat(_toConsumableArray(node.marks), [{
372
+ type: mark
373
+ }]) : [{
374
+ type: mark
375
+ }];
376
+ }
377
+
378
+ if (node.content && Array.isArray(node.content)) {
379
+ node.content.map(function (e) {
380
+ return traverseJsonNodeAndAddMarks(e, mark, schema);
381
+ });
382
+ }
383
+
384
+ return node;
336
385
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-wikimarkup-transformer",
3
- "version": "11.1.5",
3
+ "version": "11.1.7",
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.5",
3
+ "version": "11.1.7",
4
4
  "description": "Wiki markup transformer for JIRA and Confluence",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -40,12 +40,12 @@
40
40
  "devDependencies": {
41
41
  "@atlaskit/activity": "^1.0.1",
42
42
  "@atlaskit/docs": "*",
43
- "@atlaskit/editor-common": "^69.3.0",
44
- "@atlaskit/editor-core": "^172.2.0",
43
+ "@atlaskit/editor-common": "^70.1.0",
44
+ "@atlaskit/editor-core": "^173.0.0",
45
45
  "@atlaskit/editor-test-helpers": "^17.2.0",
46
46
  "@atlaskit/mention": "^21.0.0",
47
47
  "@atlaskit/profilecard": "^17.2.0",
48
- "@atlaskit/renderer": "^101.1.0",
48
+ "@atlaskit/renderer": "^102.0.0",
49
49
  "@atlaskit/util-data-test": "^17.5.0",
50
50
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
51
51
  "@emotion/react": "^11.7.1",
package/report.api.md CHANGED
@@ -1,12 +1,17 @@
1
+ <!-- API Report Version: 2.2 -->
2
+
1
3
  ## API Report File for "@atlaskit/editor-wikimarkup-transformer"
2
4
 
3
- > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
5
+ > Do not edit this file. This report is auto-generated using [API Extractor](https://api-extractor.com/).
6
+ > [Learn more about API reports](https://hello.atlassian.net/wiki/spaces/UR/pages/1825484529/Package+API+Reports)
7
+
8
+ ### Table of contents
4
9
 
5
- <!--
6
- Generated API Report version: 2.0
7
- -->
10
+ - [Main Entry Types](#main-entry-types)
8
11
 
9
- [Learn more about API reports](https://hello.atlassian.net/wiki/spaces/UR/pages/1825484529/Package+API+Reports)
12
+ ### Main Entry Types
13
+
14
+ <!--SECTION START: Main Entry Types-->
10
15
 
11
16
  ```ts
12
17
  import { Node as Node_2 } from 'prosemirror-model';
@@ -23,8 +28,8 @@ interface Context {
23
28
  // (undocumented)
24
29
  readonly defaults?: {
25
30
  readonly media?: {
26
- width: number | null;
27
- height: number | null;
31
+ width: null | number;
32
+ height: null | number;
28
33
  };
29
34
  };
30
35
  // (undocumented)
@@ -78,3 +83,5 @@ export default WikiMarkupTransformer;
78
83
 
79
84
  // (No @packageDocumentation comment for this package)
80
85
  ```
86
+
87
+ <!--SECTION END: Main Entry Types-->
@@ -0,0 +1,76 @@
1
+ ## API Report File for "@atlaskit/editor-wikimarkup-transformer"
2
+
3
+ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
+
5
+ ```ts
6
+
7
+ import { Node as Node_2 } from 'prosemirror-model';
8
+ import { Schema } from 'prosemirror-model';
9
+
10
+ // @public (undocumented)
11
+ interface Context {
12
+ // (undocumented)
13
+ readonly conversion?: {
14
+ readonly inlineCardConversion?: ConversionMap;
15
+ readonly mediaConversion?: MediaConversionMap;
16
+ mentionConversion?: ConversionMap;
17
+ };
18
+ // (undocumented)
19
+ readonly defaults?: {
20
+ readonly media?: {
21
+ width: null | number;
22
+ height: null | number;
23
+ };
24
+ };
25
+ // (undocumented)
26
+ readonly hydration?: {
27
+ readonly media?: {
28
+ targetCollectionId?: string;
29
+ };
30
+ };
31
+ // (undocumented)
32
+ readonly issueKeyRegex?: RegExp | undefined;
33
+ // (undocumented)
34
+ readonly tokenErrCallback?: TokenErrCallback;
35
+ }
36
+
37
+ // @public (undocumented)
38
+ interface ConversionMap {
39
+ // (undocumented)
40
+ [key: string]: string;
41
+ }
42
+
43
+ // @public (undocumented)
44
+ interface MediaConversionMap {
45
+ // (undocumented)
46
+ [key: string]: {
47
+ transform?: string;
48
+ embed?: boolean;
49
+ };
50
+ }
51
+
52
+ // @public (undocumented)
53
+ type TokenErrCallback = (err: Error, tokenType: string) => void;
54
+
55
+ // @public (undocumented)
56
+ interface Transformer_2<T> {
57
+ // (undocumented)
58
+ encode(node: Node_2): T;
59
+ // (undocumented)
60
+ parse(content: T): Node_2;
61
+ }
62
+
63
+ // @public (undocumented)
64
+ class WikiMarkupTransformer implements Transformer_2<string> {
65
+ constructor(schema?: Schema);
66
+ // (undocumented)
67
+ encode(node: Node_2, context?: Context): string;
68
+ // (undocumented)
69
+ parse(wikiMarkup: string, context?: Context): Node_2;
70
+ }
71
+ export { WikiMarkupTransformer }
72
+ export default WikiMarkupTransformer;
73
+
74
+ // (No @packageDocumentation comment for this package)
75
+
76
+ ```