@adobe/helix-markdown-support 3.1.4 → 3.1.5

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,3 +1,10 @@
1
+ ## [3.1.5](https://github.com/adobe/helix-markdown-support/compare/v3.1.4...v3.1.5) (2022-05-17)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * (re)move breaks in links and headings ([621c85b](https://github.com/adobe/helix-markdown-support/commit/621c85b664621e56111e00e9cbb9cd7d648471d6)), closes [#106](https://github.com/adobe/helix-markdown-support/issues/106)
7
+
1
8
  ## [3.1.4](https://github.com/adobe/helix-markdown-support/compare/v3.1.3...v3.1.4) (2022-05-10)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-markdown-support",
3
- "version": "3.1.4",
3
+ "version": "3.1.5",
4
4
  "description": "Helix Markdown Support",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -14,6 +14,7 @@ import { visit } from 'unist-util-visit';
14
14
  /**
15
15
  * Sanitizes headings:
16
16
  * - (re)move images ('before', 'both', 'after')
17
+ * - converts BREAKs inside headings to <br>.
17
18
  *
18
19
  * @param {object} tree
19
20
  * @param {object} [opts] options
@@ -47,6 +48,9 @@ export default function sanitizeHeading(tree, opts = {}) {
47
48
  siblings.splice(after, 0, para);
48
49
  after += 1;
49
50
  }
51
+ } else if (child.type === 'break') {
52
+ child.type = 'html';
53
+ child.value = '<br>';
50
54
  }
51
55
  }
52
56
  // remove empty headings
@@ -15,6 +15,8 @@ import find from 'unist-util-find';
15
15
  /**
16
16
  * Sanitizes links:
17
17
  * - unwraps formatting in links if possible. eg: [_text_](...) -> _[test](...)_
18
+ * - moves leading, trailing BREAKs out of link
19
+ * - converts BREAKs inside link to <br>.
18
20
  *
19
21
  * @param {object} tree
20
22
  * @returns {object} The modified (original) tree.
@@ -60,6 +62,31 @@ export default function sanitizeLinks(tree) {
60
62
  }
61
63
  }
62
64
  }
65
+ } else if (node.type === 'link' && children.length > 1) {
66
+ // move leading breaks outside of link
67
+ while (children[0]?.type === 'break') {
68
+ const brk = children.shift();
69
+ parent.children.splice(index, 0, brk);
70
+ // eslint-disable-next-line no-param-reassign
71
+ index += 1;
72
+ }
73
+ // move trailing breaks after link
74
+ let last = children.length - 1;
75
+ while (children[last]?.type === 'break') {
76
+ const brk = children.pop();
77
+ parent.children.splice(index + 1, 0, brk);
78
+ last -= 1;
79
+ }
80
+ // convert inline breaks to <br>
81
+ for (let i = 0; i < children.length; i += 1) {
82
+ if (children[i].type === 'break') {
83
+ children[i] = {
84
+ type: 'html',
85
+ value: '<br>',
86
+ };
87
+ }
88
+ }
89
+ return index + 1;
63
90
  }
64
91
  return CONTINUE;
65
92
  });