@adobe/helix-markdown-support 3.1.4 → 3.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 +21 -0
- package/package.json +6 -6
- package/src/mdast-sanitize-heading.js +32 -3
- package/src/mdast-sanitize-links.js +27 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [3.1.7](https://github.com/adobe/helix-markdown-support/compare/v3.1.6...v3.1.7) (2022-07-09)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update dependency mdast-util-to-hast to v12.1.2 ([3df98b2](https://github.com/adobe/helix-markdown-support/commit/3df98b2f9b51e41b47998fc61bce94896def9c8c))
|
|
7
|
+
|
|
8
|
+
## [3.1.6](https://github.com/adobe/helix-markdown-support/compare/v3.1.5...v3.1.6) (2022-05-30)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* move leading and trailing breaks out of heading ([#112](https://github.com/adobe/helix-markdown-support/issues/112)) ([87775dc](https://github.com/adobe/helix-markdown-support/commit/87775dcf189f024ccf789f8c883ab90d296c8d0d))
|
|
14
|
+
|
|
15
|
+
## [3.1.5](https://github.com/adobe/helix-markdown-support/compare/v3.1.4...v3.1.5) (2022-05-17)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* (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)
|
|
21
|
+
|
|
1
22
|
## [3.1.4](https://github.com/adobe/helix-markdown-support/compare/v3.1.3...v3.1.4) (2022-05-10)
|
|
2
23
|
|
|
3
24
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-markdown-support",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.7",
|
|
4
4
|
"description": "Helix Markdown Support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"hast-util-to-html": "8.0.3",
|
|
26
26
|
"js-yaml": "4.1.0",
|
|
27
|
-
"mdast-util-to-hast": "12.1.
|
|
27
|
+
"mdast-util-to-hast": "12.1.2",
|
|
28
28
|
"unist-util-find": "1.0.2",
|
|
29
29
|
"unist-util-visit": "4.1.0"
|
|
30
30
|
},
|
|
@@ -41,21 +41,21 @@
|
|
|
41
41
|
"@adobe/eslint-config-helix": "1.3.2",
|
|
42
42
|
"@semantic-release/changelog": "6.0.1",
|
|
43
43
|
"@semantic-release/git": "10.0.1",
|
|
44
|
-
"c8": "7.11.
|
|
44
|
+
"c8": "7.11.3",
|
|
45
45
|
"codecov": "3.8.3",
|
|
46
|
-
"eslint": "8.
|
|
46
|
+
"eslint": "8.19.0",
|
|
47
47
|
"eslint-plugin-header": "3.1.1",
|
|
48
48
|
"eslint-plugin-import": "2.26.0",
|
|
49
49
|
"husky": "8.0.1",
|
|
50
50
|
"junit-report-builder": "3.0.0",
|
|
51
|
-
"lint-staged": "
|
|
51
|
+
"lint-staged": "13.0.3",
|
|
52
52
|
"mdast-builder": "1.1.1",
|
|
53
53
|
"mocha": "10.0.0",
|
|
54
54
|
"mocha-multi-reporters": "1.5.1",
|
|
55
55
|
"remark-gfm": "3.0.1",
|
|
56
56
|
"remark-parse": "10.0.1",
|
|
57
57
|
"remark-stringify": "10.0.2",
|
|
58
|
-
"semantic-release": "19.0.
|
|
58
|
+
"semantic-release": "19.0.3",
|
|
59
59
|
"unified": "10.1.2",
|
|
60
60
|
"unist-util-inspect": "7.0.0"
|
|
61
61
|
},
|
|
@@ -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
|
|
@@ -41,7 +42,7 @@ export default function sanitizeHeading(tree, opts = {}) {
|
|
|
41
42
|
siblings.splice(index, 0, para);
|
|
42
43
|
// eslint-disable-next-line no-param-reassign
|
|
43
44
|
index += 1;
|
|
44
|
-
after
|
|
45
|
+
after += 1;
|
|
45
46
|
} else {
|
|
46
47
|
// move after heading
|
|
47
48
|
siblings.splice(after, 0, para);
|
|
@@ -49,13 +50,41 @@ export default function sanitizeHeading(tree, opts = {}) {
|
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
}
|
|
53
|
+
|
|
54
|
+
// move leading breaks before heading
|
|
55
|
+
while (children[0]?.type === 'break') {
|
|
56
|
+
const brk = children.shift();
|
|
57
|
+
siblings.splice(index, 0, brk);
|
|
58
|
+
// eslint-disable-next-line no-param-reassign
|
|
59
|
+
index += 1;
|
|
60
|
+
}
|
|
61
|
+
// move trailing breaks after heading
|
|
62
|
+
let last = children.length - 1;
|
|
63
|
+
while (children[last]?.type === 'break') {
|
|
64
|
+
const brk = children.pop();
|
|
65
|
+
siblings.splice(index + 1, 0, brk);
|
|
66
|
+
last -= 1;
|
|
67
|
+
}
|
|
68
|
+
// convert inline breaks to <br>
|
|
69
|
+
for (let i = 0; i < children.length; i += 1) {
|
|
70
|
+
if (children[i].type === 'break') {
|
|
71
|
+
children[i] = {
|
|
72
|
+
type: 'html',
|
|
73
|
+
value: '<br>',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
52
78
|
// remove empty headings
|
|
53
79
|
if (!children.length) {
|
|
54
80
|
siblings.splice(index, 1);
|
|
55
|
-
|
|
81
|
+
// eslint-disable-next-line no-param-reassign
|
|
82
|
+
index -= 1;
|
|
56
83
|
}
|
|
84
|
+
return index + 1;
|
|
57
85
|
}
|
|
58
|
-
|
|
86
|
+
|
|
87
|
+
return index + 1;
|
|
59
88
|
});
|
|
60
89
|
return tree;
|
|
61
90
|
}
|
|
@@ -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
|
});
|