@adobe/helix-markdown-support 3.1.3 → 3.1.6
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 +4 -4
- package/src/mdast-robust-tables.js +13 -7
- 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.6](https://github.com/adobe/helix-markdown-support/compare/v3.1.5...v3.1.6) (2022-05-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* 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))
|
|
7
|
+
|
|
8
|
+
## [3.1.5](https://github.com/adobe/helix-markdown-support/compare/v3.1.4...v3.1.5) (2022-05-17)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* (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)
|
|
14
|
+
|
|
15
|
+
## [3.1.4](https://github.com/adobe/helix-markdown-support/compare/v3.1.3...v3.1.4) (2022-05-10)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* preserve spans ([#109](https://github.com/adobe/helix-markdown-support/issues/109)) ([9d6ba00](https://github.com/adobe/helix-markdown-support/commit/9d6ba00e2623349bf469ab56bb093f5dbed976fc))
|
|
21
|
+
|
|
1
22
|
## [3.1.3](https://github.com/adobe/helix-markdown-support/compare/v3.1.2...v3.1.3) (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.6",
|
|
4
4
|
"description": "Helix Markdown Support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -41,14 +41,14 @@
|
|
|
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.16.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": "12.4.
|
|
51
|
+
"lint-staged": "12.4.2",
|
|
52
52
|
"mdast-builder": "1.1.1",
|
|
53
53
|
"mocha": "10.0.0",
|
|
54
54
|
"mocha-multi-reporters": "1.5.1",
|
|
@@ -29,20 +29,26 @@ export default function robustTables(tree) {
|
|
|
29
29
|
(node.children /* c8 ignore next */ || []).forEach((row) => {
|
|
30
30
|
html += ' <tr>\n';
|
|
31
31
|
(row.children /* c8 ignore next */ || []).forEach((cell) => {
|
|
32
|
-
let
|
|
32
|
+
let attrs = '';
|
|
33
33
|
if (cell.align === 'right') {
|
|
34
|
-
|
|
34
|
+
attrs = ' align="right"';
|
|
35
35
|
} else if (cell.align === 'center') {
|
|
36
|
-
|
|
36
|
+
attrs = ' align="center"';
|
|
37
37
|
} else if (cell.align === 'both') {
|
|
38
|
-
|
|
38
|
+
attrs = ' align="justify"';
|
|
39
39
|
}
|
|
40
40
|
if (cell.valign === 'middle') {
|
|
41
|
-
|
|
41
|
+
attrs += ' valign="middle"';
|
|
42
42
|
} else if (cell.valign === 'bottom') {
|
|
43
|
-
|
|
43
|
+
attrs += ' valign="bottom"';
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
if (cell.rowSpan > 1) {
|
|
46
|
+
attrs += ` rowspan="${cell.rowSpan}"`;
|
|
47
|
+
}
|
|
48
|
+
if (cell.colSpan > 1) {
|
|
49
|
+
attrs += ` colspan="${cell.colSpan}"`;
|
|
50
|
+
}
|
|
51
|
+
html += ` <td${attrs}>`;
|
|
46
52
|
|
|
47
53
|
// if cell contains only 1 single paragraph, unwrap it
|
|
48
54
|
let { children } = cell;
|
|
@@ -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
|
});
|