@adobe/helix-markdown-support 3.0.0 → 3.1.0
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 +7 -0
- package/package.json +6 -6
- package/src/mdast-fix-code-flow.js +2 -2
- package/src/mdast-robust-tables.js +3 -3
- package/src/mdast-sanitize-formats.js +2 -2
- package/src/mdast-sanitize-heading.js +21 -8
- package/src/mdast-sanitize-links.js +2 -2
- package/src/mdast-sanitize-text.js +2 -2
- package/src/mdast-suppress-spacecode.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [3.1.0](https://github.com/adobe/helix-markdown-support/compare/v3.0.0...v3.1.0) (2022-01-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* improve sanitize-headings to move leading images before heading ([292dc72](https://github.com/adobe/helix-markdown-support/commit/292dc72dbe43def0d97e8f1c528eeb065b3bff12)), closes [#83](https://github.com/adobe/helix-markdown-support/issues/83)
|
|
7
|
+
|
|
1
8
|
# [3.0.0](https://github.com/adobe/helix-markdown-support/compare/v2.0.1...v3.0.0) (2021-12-07)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-markdown-support",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Helix Markdown Support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -38,17 +38,17 @@
|
|
|
38
38
|
"unified": "10.x"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@adobe/eslint-config-helix": "1.3.
|
|
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.
|
|
44
|
+
"c8": "7.11.0",
|
|
45
45
|
"codecov": "3.8.3",
|
|
46
|
-
"eslint": "8.
|
|
46
|
+
"eslint": "8.6.0",
|
|
47
47
|
"eslint-plugin-header": "3.1.1",
|
|
48
|
-
"eslint-plugin-import": "2.25.
|
|
48
|
+
"eslint-plugin-import": "2.25.4",
|
|
49
49
|
"husky": "7.0.4",
|
|
50
50
|
"junit-report-builder": "3.0.0",
|
|
51
|
-
"lint-staged": "12.1.
|
|
51
|
+
"lint-staged": "12.1.7",
|
|
52
52
|
"mdast-builder": "1.1.1",
|
|
53
53
|
"mocha": "9.1.3",
|
|
54
54
|
"mocha-multi-reporters": "1.5.1",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
/* eslint-disable no-param-reassign */
|
|
13
|
-
import { visit } from 'unist-util-visit';
|
|
13
|
+
import { visit, CONTINUE } from 'unist-util-visit';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* ensures that `code` is at a flow level. i.e. outside a paragraph
|
|
@@ -50,7 +50,7 @@ export default function fixCodeFlow(tree) {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
// return index;
|
|
53
|
-
return
|
|
53
|
+
return CONTINUE;
|
|
54
54
|
});
|
|
55
55
|
return tree;
|
|
56
56
|
}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
/* eslint-disable no-param-reassign */
|
|
13
13
|
import { toHast as md2hast } from 'mdast-util-to-hast';
|
|
14
14
|
import { toHtml as hast2html } from 'hast-util-to-html';
|
|
15
|
-
import { visit } from 'unist-util-visit';
|
|
15
|
+
import { visit, CONTINUE } from 'unist-util-visit';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Converts tables to HTML
|
|
@@ -23,7 +23,7 @@ import { visit } from 'unist-util-visit';
|
|
|
23
23
|
export default function robustTables(tree) {
|
|
24
24
|
visit(tree, (node) => {
|
|
25
25
|
if (node.type !== 'table') {
|
|
26
|
-
return
|
|
26
|
+
return CONTINUE;
|
|
27
27
|
}
|
|
28
28
|
let html = '<table>\n';
|
|
29
29
|
(node.children /* c8 ignore next */ || []).forEach((row) => {
|
|
@@ -71,7 +71,7 @@ export default function robustTables(tree) {
|
|
|
71
71
|
node.type = 'html';
|
|
72
72
|
node.value = html;
|
|
73
73
|
delete node.children;
|
|
74
|
-
return
|
|
74
|
+
return CONTINUE;
|
|
75
75
|
});
|
|
76
76
|
return tree;
|
|
77
77
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import { visit } from 'unist-util-visit';
|
|
12
|
+
import { visit, CONTINUE } from 'unist-util-visit';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Sanitizes text:
|
|
@@ -43,7 +43,7 @@ export default function sanitizeFormats(tree) {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
return
|
|
46
|
+
return CONTINUE;
|
|
47
47
|
});
|
|
48
48
|
return tree;
|
|
49
49
|
}
|
|
@@ -13,36 +13,49 @@ import { visit } from 'unist-util-visit';
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Sanitizes headings:
|
|
16
|
-
* - (re)move images
|
|
16
|
+
* - (re)move images ('before', 'both', 'after')
|
|
17
17
|
*
|
|
18
18
|
* @param {object} tree
|
|
19
|
+
* @param {object} [opts] options
|
|
20
|
+
* @param {string} [opts.imageHandling] specifies how images are handled. defaults to 'after'.
|
|
19
21
|
* @returns {object} The modified (original) tree.
|
|
20
22
|
*/
|
|
21
|
-
export default function sanitizeHeading(tree) {
|
|
23
|
+
export default function sanitizeHeading(tree, opts = {}) {
|
|
24
|
+
const { imageHandling = 'after' } = opts;
|
|
22
25
|
visit(tree, (node, index, parent) => {
|
|
23
26
|
const { children: siblings = [] } = parent || {};
|
|
24
27
|
const { children = [] } = node;
|
|
28
|
+
let after = index + 1;
|
|
25
29
|
if (node.type === 'heading') {
|
|
26
30
|
for (let i = 0; i < children.length; i += 1) {
|
|
27
31
|
const child = children[i];
|
|
28
32
|
if (child.type === 'image') {
|
|
29
|
-
// move after heading
|
|
30
|
-
children.splice(i, 1);
|
|
31
|
-
i -= 1;
|
|
32
33
|
const para = {
|
|
33
34
|
type: 'paragraph',
|
|
34
35
|
children: [child],
|
|
35
36
|
};
|
|
36
|
-
|
|
37
|
+
children.splice(i, 1);
|
|
38
|
+
i -= 1;
|
|
39
|
+
if ((i < 0 && imageHandling !== 'after') || imageHandling === 'before') {
|
|
40
|
+
// move before heading
|
|
41
|
+
siblings.splice(index, 0, para);
|
|
42
|
+
// eslint-disable-next-line no-param-reassign
|
|
43
|
+
index += 1;
|
|
44
|
+
after = index + 1;
|
|
45
|
+
} else {
|
|
46
|
+
// move after heading
|
|
47
|
+
siblings.splice(after, 0, para);
|
|
48
|
+
after += 1;
|
|
49
|
+
}
|
|
37
50
|
}
|
|
38
51
|
}
|
|
39
52
|
// remove empty headings
|
|
40
53
|
if (!children.length) {
|
|
41
54
|
siblings.splice(index, 1);
|
|
42
|
-
|
|
55
|
+
after -= 1;
|
|
43
56
|
}
|
|
44
57
|
}
|
|
45
|
-
return
|
|
58
|
+
return after;
|
|
46
59
|
});
|
|
47
60
|
return tree;
|
|
48
61
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import { visit } from 'unist-util-visit';
|
|
12
|
+
import { visit, CONTINUE } from 'unist-util-visit';
|
|
13
13
|
import find from 'unist-util-find';
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -61,7 +61,7 @@ export default function sanitizeLinks(tree) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
return
|
|
64
|
+
return CONTINUE;
|
|
65
65
|
});
|
|
66
66
|
return tree;
|
|
67
67
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import { visit } from 'unist-util-visit';
|
|
12
|
+
import { visit, CONTINUE } from 'unist-util-visit';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Sanitizes text:
|
|
@@ -107,7 +107,7 @@ export default function sanitizeText(tree) {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
return
|
|
110
|
+
return CONTINUE;
|
|
111
111
|
});
|
|
112
112
|
return tree;
|
|
113
113
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import { visit } from 'unist-util-visit';
|
|
12
|
+
import { visit, CONTINUE } from 'unist-util-visit';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Looks for text starting with 4 spaces. As this would render as code in some markdown,
|
|
@@ -27,7 +27,7 @@ export default function suppressSpaceCode(tree) {
|
|
|
27
27
|
// eslint-disable-next-line no-param-reassign
|
|
28
28
|
child.value = child.value.replace(/^\s+/, ' ');
|
|
29
29
|
}
|
|
30
|
-
return
|
|
30
|
+
return CONTINUE;
|
|
31
31
|
});
|
|
32
32
|
return tree;
|
|
33
33
|
}
|