@adobe/helix-markdown-support 1.4.0 → 3.0.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/.circleci/config.yml +3 -3
- package/.eslintrc.cjs +27 -0
- package/.github/workflows/semantic-release.yaml +2 -2
- package/.husky/pre-commit +4 -0
- package/.mocha-multi.json +6 -0
- package/.nycrc.json +10 -0
- package/.releaserc.cjs +16 -0
- package/CHANGELOG.md +38 -0
- package/package.json +35 -40
- package/src/index.js +9 -17
- package/src/mdast-fix-code-flow.js +2 -4
- package/src/mdast-robust-tables.js +50 -26
- package/src/mdast-sanitize-formats.js +2 -4
- package/src/mdast-sanitize-heading.js +2 -4
- package/src/mdast-sanitize-links.js +67 -0
- package/src/mdast-sanitize-text.js +113 -0
- package/src/mdast-suppress-spacecode.js +2 -4
- package/src/remark-breaks-as-spaces.js +1 -3
- package/src/remark-matter/from-markdown.js +2 -4
- package/src/remark-matter/index.js +5 -7
- package/src/remark-matter/syntax.js +4 -8
- package/src/remark-matter/to-markdown.js +1 -3
- package/.github/move.yml +0 -16
- package/docs/API.md +0 -12
package/.circleci/config.yml
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
version: 2.1
|
|
2
2
|
executors:
|
|
3
|
-
|
|
3
|
+
node14:
|
|
4
4
|
docker:
|
|
5
|
-
- image: circleci/node:
|
|
5
|
+
- image: circleci/node:14
|
|
6
6
|
environment:
|
|
7
7
|
NPM_CONFIG_PREFIX: ~/.npm-global
|
|
8
8
|
|
|
@@ -29,7 +29,7 @@ commands:
|
|
|
29
29
|
|
|
30
30
|
jobs:
|
|
31
31
|
build:
|
|
32
|
-
executor:
|
|
32
|
+
executor: node14
|
|
33
33
|
|
|
34
34
|
steps:
|
|
35
35
|
- setup
|
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2019 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
root: true,
|
|
15
|
+
extends: '@adobe/helix',
|
|
16
|
+
env: {
|
|
17
|
+
node: true,
|
|
18
|
+
es6: true,
|
|
19
|
+
},
|
|
20
|
+
parserOptions: {
|
|
21
|
+
sourceType: 'module',
|
|
22
|
+
ecmaVersion: 2020,
|
|
23
|
+
},
|
|
24
|
+
rules: {
|
|
25
|
+
'import/extensions': 0,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
@@ -10,10 +10,10 @@ jobs:
|
|
|
10
10
|
if: "!contains(github.event.head_commit.message, '[skip ci]')"
|
|
11
11
|
steps:
|
|
12
12
|
- uses: actions/checkout@v2
|
|
13
|
-
- name: Use Node.js
|
|
13
|
+
- name: Use Node.js 14.x
|
|
14
14
|
uses: actions/setup-node@v2
|
|
15
15
|
with:
|
|
16
|
-
node-version: '
|
|
16
|
+
node-version: '14.x'
|
|
17
17
|
- run: npm install
|
|
18
18
|
- run: npm test
|
|
19
19
|
- run: npm run semantic-release
|
package/.nycrc.json
ADDED
package/.releaserc.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
plugins: [
|
|
3
|
+
"@semantic-release/commit-analyzer",
|
|
4
|
+
"@semantic-release/release-notes-generator",
|
|
5
|
+
["@semantic-release/changelog", {
|
|
6
|
+
"changelogFile": "CHANGELOG.md",
|
|
7
|
+
}],
|
|
8
|
+
"@semantic-release/npm",
|
|
9
|
+
["@semantic-release/git", {
|
|
10
|
+
"assets": ["package.json", "CHANGELOG.md"],
|
|
11
|
+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
12
|
+
}],
|
|
13
|
+
["@semantic-release/github", {}]
|
|
14
|
+
],
|
|
15
|
+
branches: [ 'main' ],
|
|
16
|
+
};
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
+
# [3.0.0](https://github.com/adobe/helix-markdown-support/compare/v2.0.1...v3.0.0) (2021-12-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* convert to esm ([0b5e09b](https://github.com/adobe/helix-markdown-support/commit/0b5e09bac1e7e26128d7af8f25c85eadc82ff56c))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* only esm supported
|
|
12
|
+
|
|
13
|
+
## [2.0.1](https://github.com/adobe/helix-markdown-support/compare/v2.0.0...v2.0.1) (2021-07-23)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* allow html in table cells ([9afe468](https://github.com/adobe/helix-markdown-support/commit/9afe468057101b28d17ae218f45666e1ec9829c6))
|
|
19
|
+
|
|
20
|
+
# [2.0.0](https://github.com/adobe/helix-markdown-support/compare/v1.5.0...v2.0.0) (2021-06-09)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
|
|
25
|
+
* **table:** convert all tables to HTML and convey cell alignment ([#27](https://github.com/adobe/helix-markdown-support/issues/27)) ([154bfe4](https://github.com/adobe/helix-markdown-support/commit/154bfe46e0416272fa08122e447ab4aea2cafc58)), closes [#26](https://github.com/adobe/helix-markdown-support/issues/26)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### BREAKING CHANGES
|
|
29
|
+
|
|
30
|
+
* **table:** simple md tables no longer remain markdown
|
|
31
|
+
|
|
32
|
+
# [1.5.0](https://github.com/adobe/helix-markdown-support/compare/v1.4.0...v1.5.0) (2021-05-11)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
### Features
|
|
36
|
+
|
|
37
|
+
* **mdast:** add more sanitizing functions ([#31](https://github.com/adobe/helix-markdown-support/issues/31)) ([39bc415](https://github.com/adobe/helix-markdown-support/commit/39bc415fb03446ff9342c8716df69e7758963f32))
|
|
38
|
+
|
|
1
39
|
# [1.4.0](https://github.com/adobe/helix-markdown-support/compare/v1.3.1...v1.4.0) (2021-02-16)
|
|
2
40
|
|
|
3
41
|
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-markdown-support",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Helix Markdown Support",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"scripts": {
|
|
6
|
-
"test": "
|
|
7
|
-
"test-ci": "
|
|
8
|
-
"lint": "
|
|
7
|
+
"test": " c8 mocha",
|
|
8
|
+
"test-ci": "c8 mocha && codecov",
|
|
9
|
+
"lint": "eslint .",
|
|
9
10
|
"semantic-release": "semantic-release",
|
|
10
|
-
"
|
|
11
|
-
"commit": "git-cz"
|
|
11
|
+
"prepare": "husky install"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
@@ -22,49 +22,44 @@
|
|
|
22
22
|
"homepage": "https://github.com/adobe/helix-markdown-support#readme",
|
|
23
23
|
"main": "src/index.js",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"hast-util-to-html": "
|
|
26
|
-
"js-yaml": "4.
|
|
27
|
-
"mdast-util-to-hast": "
|
|
28
|
-
"unist-util-
|
|
25
|
+
"hast-util-to-html": "8.0.3",
|
|
26
|
+
"js-yaml": "4.1.0",
|
|
27
|
+
"mdast-util-to-hast": "12.0.0",
|
|
28
|
+
"unist-util-find": "1.0.2",
|
|
29
|
+
"unist-util-visit": "4.1.0"
|
|
30
|
+
},
|
|
31
|
+
"mocha": {
|
|
32
|
+
"spec": "test/**/*.test.js",
|
|
33
|
+
"recursive": "true",
|
|
34
|
+
"reporter": "mocha-multi-reporters",
|
|
35
|
+
"reporter-options": "configFile=.mocha-multi.json"
|
|
29
36
|
},
|
|
30
37
|
"peerDependencies": {
|
|
31
|
-
"unified": "
|
|
38
|
+
"unified": "10.x"
|
|
32
39
|
},
|
|
33
40
|
"devDependencies": {
|
|
34
|
-
"@adobe/eslint-config-helix": "1.1
|
|
35
|
-
"@semantic-release/changelog": "
|
|
36
|
-
"@semantic-release/git": "
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"commitizen": "4.2.3",
|
|
41
|
-
"cz-conventional-changelog": "3.3.0",
|
|
42
|
-
"eslint": "7.20.0",
|
|
41
|
+
"@adobe/eslint-config-helix": "1.3.1",
|
|
42
|
+
"@semantic-release/changelog": "6.0.1",
|
|
43
|
+
"@semantic-release/git": "10.0.1",
|
|
44
|
+
"c8": "7.10.0",
|
|
45
|
+
"codecov": "3.8.3",
|
|
46
|
+
"eslint": "8.4.0",
|
|
43
47
|
"eslint-plugin-header": "3.1.1",
|
|
44
|
-
"eslint-plugin-import": "2.
|
|
45
|
-
"
|
|
46
|
-
"jsdoc-to-markdown": "6.0.1",
|
|
48
|
+
"eslint-plugin-import": "2.25.3",
|
|
49
|
+
"husky": "7.0.4",
|
|
47
50
|
"junit-report-builder": "3.0.0",
|
|
48
|
-
"lint-staged": "
|
|
51
|
+
"lint-staged": "12.1.2",
|
|
49
52
|
"mdast-builder": "1.1.1",
|
|
50
|
-
"mocha": "
|
|
51
|
-
"
|
|
52
|
-
"remark-gfm": "
|
|
53
|
-
"remark-parse": "
|
|
54
|
-
"remark-stringify": "
|
|
55
|
-
"semantic-release": "
|
|
56
|
-
"unified": "
|
|
57
|
-
"unist-util-inspect": "
|
|
53
|
+
"mocha": "9.1.3",
|
|
54
|
+
"mocha-multi-reporters": "1.5.1",
|
|
55
|
+
"remark-gfm": "3.0.1",
|
|
56
|
+
"remark-parse": "10.0.1",
|
|
57
|
+
"remark-stringify": "10.0.2",
|
|
58
|
+
"semantic-release": "18.0.1",
|
|
59
|
+
"unified": "10.1.1",
|
|
60
|
+
"unist-util-inspect": "7.0.0"
|
|
58
61
|
},
|
|
59
62
|
"lint-staged": {
|
|
60
63
|
"*.js": "eslint"
|
|
61
|
-
},
|
|
62
|
-
"config": {
|
|
63
|
-
"commitizen": {
|
|
64
|
-
"path": "node_modules/cz-conventional-changelog"
|
|
65
|
-
},
|
|
66
|
-
"ghooks": {
|
|
67
|
-
"pre-commit": "npx lint-staged"
|
|
68
|
-
}
|
|
69
64
|
}
|
|
70
65
|
}
|
package/src/index.js
CHANGED
|
@@ -10,20 +10,12 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
remarkMatter,
|
|
23
|
-
robustTables,
|
|
24
|
-
breaksAsSpaces,
|
|
25
|
-
sanitizeHeading,
|
|
26
|
-
suppressSpaceCode,
|
|
27
|
-
sanitizeFormats,
|
|
28
|
-
fixCodeFlow,
|
|
29
|
-
};
|
|
13
|
+
export { default as remarkMatter } from './remark-matter/index.js';
|
|
14
|
+
export { default as robustTables } from './mdast-robust-tables.js';
|
|
15
|
+
export { default as breaksAsSpaces } from './remark-breaks-as-spaces.js';
|
|
16
|
+
export { default as sanitizeHeading } from './mdast-sanitize-heading.js';
|
|
17
|
+
export { default as suppressSpaceCode } from './mdast-suppress-spacecode.js';
|
|
18
|
+
export { default as sanitizeFormats } from './mdast-sanitize-formats.js';
|
|
19
|
+
export { default as fixCodeFlow } from './mdast-fix-code-flow.js';
|
|
20
|
+
export { default as sanitizeLinks } from './mdast-sanitize-links.js';
|
|
21
|
+
export { default as sanitizeText } from './mdast-sanitize-text.js';
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
/* eslint-disable no-param-reassign */
|
|
13
|
-
|
|
13
|
+
import { visit } from 'unist-util-visit';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* ensures that `code` is at a flow level. i.e. outside a paragraph
|
|
@@ -18,7 +18,7 @@ const visit = require('unist-util-visit');
|
|
|
18
18
|
* @param {object} tree
|
|
19
19
|
* @returns {object} The modified (original) tree.
|
|
20
20
|
*/
|
|
21
|
-
function fixCodeFlow(tree) {
|
|
21
|
+
export default function fixCodeFlow(tree) {
|
|
22
22
|
visit(tree, (node, index, parent) => {
|
|
23
23
|
if (node.type === 'paragraph' && node.children) {
|
|
24
24
|
for (let i = 0; i < node.children.length; i += 1) {
|
|
@@ -54,5 +54,3 @@ function fixCodeFlow(tree) {
|
|
|
54
54
|
});
|
|
55
55
|
return tree;
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
module.exports = fixCodeFlow;
|
|
@@ -10,44 +10,68 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
/* eslint-disable no-param-reassign */
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
import { toHast as md2hast } from 'mdast-util-to-hast';
|
|
14
|
+
import { toHtml as hast2html } from 'hast-util-to-html';
|
|
15
|
+
import { visit } from 'unist-util-visit';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Converts
|
|
18
|
+
* Converts tables to HTML
|
|
19
19
|
*
|
|
20
20
|
* @param {object} tree
|
|
21
21
|
* @returns {object} The modified (original) tree.
|
|
22
22
|
*/
|
|
23
|
-
function robustTables(tree) {
|
|
23
|
+
export default function robustTables(tree) {
|
|
24
24
|
visit(tree, (node) => {
|
|
25
|
-
if (node.type !== '
|
|
25
|
+
if (node.type !== 'table') {
|
|
26
26
|
return visit.CONTINUE;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
28
|
+
let html = '<table>\n';
|
|
29
|
+
(node.children /* c8 ignore next */ || []).forEach((row) => {
|
|
30
|
+
html += ' <tr>\n';
|
|
31
|
+
(row.children /* c8 ignore next */ || []).forEach((cell) => {
|
|
32
|
+
let align = '';
|
|
33
|
+
if (cell.align === 'right') {
|
|
34
|
+
align = ' align="right"';
|
|
35
|
+
} else if (cell.align === 'center') {
|
|
36
|
+
align = ' align="center"';
|
|
37
|
+
} else if (cell.align === 'both') {
|
|
38
|
+
align = ' align="justify"';
|
|
39
|
+
}
|
|
40
|
+
if (cell.valign === 'middle') {
|
|
41
|
+
align += ' valign="middle"';
|
|
42
|
+
} else if (cell.valign === 'bottom') {
|
|
43
|
+
align += ' valign="bottom"';
|
|
44
|
+
}
|
|
45
|
+
html += ` <td${align}>`;
|
|
46
|
+
|
|
47
|
+
// if cell contains only 1 single paragraph, unwrap it
|
|
48
|
+
let { children } = cell;
|
|
49
|
+
if (children && children.length === 1 && children[0].type === 'paragraph') {
|
|
50
|
+
children = children[0].children;
|
|
44
51
|
}
|
|
45
|
-
|
|
52
|
+
|
|
53
|
+
(children /* c8 ignore next */ || []).forEach((child) => {
|
|
54
|
+
if (child.type === 'html') {
|
|
55
|
+
html += child.value;
|
|
56
|
+
} else {
|
|
57
|
+
const cellHtml = hast2html(md2hast(child));
|
|
58
|
+
if (child.type === 'code') {
|
|
59
|
+
// code needs special treatment, otherwise the newlines disappear.
|
|
60
|
+
html += cellHtml.replace(/\r?\n/g, '<br>');
|
|
61
|
+
} else {
|
|
62
|
+
html += cellHtml.replace(/\r?\n/g, ' ');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
html += '</td>\n';
|
|
46
67
|
});
|
|
47
|
-
|
|
68
|
+
html += ' </tr>\n';
|
|
69
|
+
});
|
|
70
|
+
html += '</table>';
|
|
71
|
+
node.type = 'html';
|
|
72
|
+
node.value = html;
|
|
73
|
+
delete node.children;
|
|
48
74
|
return visit.CONTINUE;
|
|
49
75
|
});
|
|
50
76
|
return tree;
|
|
51
77
|
}
|
|
52
|
-
|
|
53
|
-
module.exports = robustTables;
|
|
@@ -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
|
-
|
|
12
|
+
import { visit } from 'unist-util-visit';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Sanitizes text:
|
|
@@ -19,7 +19,7 @@ const visit = require('unist-util-visit');
|
|
|
19
19
|
* @param {object} tree
|
|
20
20
|
* @returns {object} The modified (original) tree.
|
|
21
21
|
*/
|
|
22
|
-
function sanitizeFormats(tree) {
|
|
22
|
+
export default function sanitizeFormats(tree) {
|
|
23
23
|
visit(tree, (node, index, parent) => {
|
|
24
24
|
const { children: siblings = [] } = parent || {};
|
|
25
25
|
const { children } = node;
|
|
@@ -47,5 +47,3 @@ function sanitizeFormats(tree) {
|
|
|
47
47
|
});
|
|
48
48
|
return tree;
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
module.exports = sanitizeFormats;
|
|
@@ -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
|
-
|
|
12
|
+
import { visit } from 'unist-util-visit';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Sanitizes headings:
|
|
@@ -18,7 +18,7 @@ const visit = require('unist-util-visit');
|
|
|
18
18
|
* @param {object} tree
|
|
19
19
|
* @returns {object} The modified (original) tree.
|
|
20
20
|
*/
|
|
21
|
-
function sanitizeHeading(tree) {
|
|
21
|
+
export default function sanitizeHeading(tree) {
|
|
22
22
|
visit(tree, (node, index, parent) => {
|
|
23
23
|
const { children: siblings = [] } = parent || {};
|
|
24
24
|
const { children = [] } = node;
|
|
@@ -46,5 +46,3 @@ function sanitizeHeading(tree) {
|
|
|
46
46
|
});
|
|
47
47
|
return tree;
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
module.exports = sanitizeHeading;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { visit } from 'unist-util-visit';
|
|
13
|
+
import find from 'unist-util-find';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Sanitizes links:
|
|
17
|
+
* - unwraps formatting in links if possible. eg: [_text_](...) -> _[test](...)_
|
|
18
|
+
*
|
|
19
|
+
* @param {object} tree
|
|
20
|
+
* @returns {object} The modified (original) tree.
|
|
21
|
+
*/
|
|
22
|
+
export default function sanitizeLinks(tree) {
|
|
23
|
+
visit(tree, (node, index, parent) => {
|
|
24
|
+
const { children = [] } = node;
|
|
25
|
+
if (node.type === 'link' && children.length === 1) {
|
|
26
|
+
const [linkText] = children;
|
|
27
|
+
if (linkText.type === 'emphasis' || linkText.type === 'strong' || linkText.type === 'delete') {
|
|
28
|
+
// collapse consecutive texts
|
|
29
|
+
for (let i = 1; i < linkText.children.length; i += 1) {
|
|
30
|
+
if (linkText.children[i].type === 'text' && linkText.children[i - 1].type === 'text') {
|
|
31
|
+
linkText.children[i - 1].value += linkText.children[i].value;
|
|
32
|
+
linkText.children.splice(i, 1);
|
|
33
|
+
i -= 1;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// set the link's children to the inner nodes
|
|
38
|
+
// eslint-disable-next-line no-param-reassign
|
|
39
|
+
node.children = linkText.children;
|
|
40
|
+
|
|
41
|
+
// replace the node with the formatting
|
|
42
|
+
// eslint-disable-next-line no-param-reassign
|
|
43
|
+
parent.children[index] = linkText;
|
|
44
|
+
|
|
45
|
+
// set the formatting children to the link
|
|
46
|
+
linkText.children = [node];
|
|
47
|
+
|
|
48
|
+
// check if link text last trailing space, this would now result in wrong md:
|
|
49
|
+
// **[Curves on the iPad. ](https://....)**The curves
|
|
50
|
+
const text = find(node, (n) => n.type === 'text');
|
|
51
|
+
if (text) {
|
|
52
|
+
const trimmed = text.value.trimEnd();
|
|
53
|
+
if (trimmed !== text.value) {
|
|
54
|
+
text.value = trimmed;
|
|
55
|
+
// insert text node after
|
|
56
|
+
parent.children.splice(index + 1, 0, {
|
|
57
|
+
type: 'text',
|
|
58
|
+
value: ' ',
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return visit.CONTINUE;
|
|
65
|
+
});
|
|
66
|
+
return tree;
|
|
67
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { visit } from 'unist-util-visit';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Sanitizes text:
|
|
16
|
+
* - collapses consecutive text blocks
|
|
17
|
+
* - trims ends of texts before break
|
|
18
|
+
* - trims ends of texts at the end
|
|
19
|
+
* - moves leading and trailing whitespaces out of formats
|
|
20
|
+
* - removes leading whitespaces before images
|
|
21
|
+
*
|
|
22
|
+
* @param {object} tree
|
|
23
|
+
* @returns {object} The modified (original) tree.
|
|
24
|
+
*/
|
|
25
|
+
export default function sanitizeText(tree) {
|
|
26
|
+
visit(tree, (node, index, parent) => {
|
|
27
|
+
const { children: siblings = [] } = parent || {};
|
|
28
|
+
const { children = [] } = node;
|
|
29
|
+
|
|
30
|
+
// collapse text blocks
|
|
31
|
+
if (index > 0 && node.type === 'text' && siblings[index - 1].type === 'text') {
|
|
32
|
+
siblings[index - 1].value += node.value;
|
|
33
|
+
siblings.splice(index, 1);
|
|
34
|
+
return index - 1;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if ((node.type === 'strong' || node.type === 'emphasis' || node.type === 'delete') && children.length) {
|
|
38
|
+
// check if last text block has a trailing whitespace
|
|
39
|
+
const last = children[children.length - 1];
|
|
40
|
+
if (last.type === 'text') {
|
|
41
|
+
const trimmed = last.value.trimEnd();
|
|
42
|
+
if (trimmed !== last.value) {
|
|
43
|
+
const newText = {
|
|
44
|
+
type: 'text',
|
|
45
|
+
value: last.value.substring(trimmed.length),
|
|
46
|
+
};
|
|
47
|
+
if (!trimmed && children.length === 1) {
|
|
48
|
+
// if formatting block would now be empty, remove it
|
|
49
|
+
siblings.splice(index, 1, newText);
|
|
50
|
+
return index - 1;
|
|
51
|
+
} else {
|
|
52
|
+
// add space after
|
|
53
|
+
last.value = trimmed;
|
|
54
|
+
siblings.splice(index + 1, 0, newText);
|
|
55
|
+
}
|
|
56
|
+
return index;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// check if the first text block has a leading whitespace
|
|
60
|
+
const first = children[0];
|
|
61
|
+
if (first.type === 'text') {
|
|
62
|
+
const trimmed = first.value.trimStart();
|
|
63
|
+
if (trimmed !== first.value) {
|
|
64
|
+
const newText = {
|
|
65
|
+
type: 'text',
|
|
66
|
+
value: first.value.substring(0, first.value.length - trimmed.length),
|
|
67
|
+
};
|
|
68
|
+
first.value = trimmed;
|
|
69
|
+
// insert before
|
|
70
|
+
siblings.splice(index, 0, newText);
|
|
71
|
+
return index;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// remove leading whitespace in paragraphs
|
|
77
|
+
if (parent && index === 0 && parent.type === 'paragraph' && node.type === 'text') {
|
|
78
|
+
// eslint-disable-next-line no-param-reassign
|
|
79
|
+
node.value = node.value.trimStart();
|
|
80
|
+
if (!node.value) {
|
|
81
|
+
siblings.splice(index, 1);
|
|
82
|
+
return index;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// remove trailing whitespace if last text block
|
|
87
|
+
if (node.type === 'text' && index === siblings.length - 1) {
|
|
88
|
+
// eslint-disable-next-line no-param-reassign
|
|
89
|
+
node.value = node.value.trimEnd();
|
|
90
|
+
if (!node.value) {
|
|
91
|
+
siblings.splice(index, 1);
|
|
92
|
+
return index - 1;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// remove trailing whitespace before break blocks
|
|
96
|
+
if (node.type === 'break') {
|
|
97
|
+
// eslint-disable-next-line no-param-reassign
|
|
98
|
+
delete node.value;
|
|
99
|
+
if (index > 0) {
|
|
100
|
+
const prev = siblings[index - 1];
|
|
101
|
+
if (prev.type === 'text') {
|
|
102
|
+
prev.value = prev.value.trimEnd();
|
|
103
|
+
if (!prev.value) {
|
|
104
|
+
siblings.splice(index - 1, 1);
|
|
105
|
+
return index - 1;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return visit.CONTINUE;
|
|
111
|
+
});
|
|
112
|
+
return tree;
|
|
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
|
-
|
|
12
|
+
import { visit } 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,
|
|
@@ -18,7 +18,7 @@ const visit = require('unist-util-visit');
|
|
|
18
18
|
* @param {object} tree
|
|
19
19
|
* @returns {object} The modified (original) tree.
|
|
20
20
|
*/
|
|
21
|
-
function suppressSpaceCode(tree) {
|
|
21
|
+
export default function suppressSpaceCode(tree) {
|
|
22
22
|
visit(tree, (child, index, parent) => {
|
|
23
23
|
const { children } = parent || {};
|
|
24
24
|
if (child.type === 'text'
|
|
@@ -31,5 +31,3 @@ function suppressSpaceCode(tree) {
|
|
|
31
31
|
});
|
|
32
32
|
return tree;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
module.exports = suppressSpaceCode;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
/**
|
|
14
14
|
* Remark extension that handles soft-breaks correctly.
|
|
15
15
|
*/
|
|
16
|
-
function softBreak() {
|
|
16
|
+
export default function softBreak() {
|
|
17
17
|
function handleBreak(node, _, context) {
|
|
18
18
|
if (context.stack.indexOf('tableCell') !== -1) {
|
|
19
19
|
return ' ';
|
|
@@ -31,5 +31,3 @@ function softBreak() {
|
|
|
31
31
|
},
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
module.exports = softBreak;
|
|
@@ -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
|
-
|
|
12
|
+
import jsYaml from 'js-yaml';
|
|
13
13
|
|
|
14
14
|
function open(token) {
|
|
15
15
|
this.enter({ type: 'yaml', value: '', payload: {} }, token);
|
|
@@ -38,7 +38,7 @@ function value(token) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// eslint-disable-next-line no-unused-vars
|
|
41
|
-
function fromMarkdown(options = {}) {
|
|
41
|
+
export default function fromMarkdown(options = {}) {
|
|
42
42
|
return {
|
|
43
43
|
enter: {
|
|
44
44
|
yaml: open,
|
|
@@ -49,5 +49,3 @@ function fromMarkdown(options = {}) {
|
|
|
49
49
|
},
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
module.exports = fromMarkdown;
|
|
@@ -9,9 +9,9 @@
|
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
import fromMarkdown from './from-markdown.js';
|
|
13
|
+
import toMarkdown from './to-markdown.js';
|
|
14
|
+
import syntax from './syntax.js';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Front- and mid-matter remark plugin.
|
|
@@ -83,11 +83,11 @@ const syntax = require('./syntax.js');
|
|
|
83
83
|
* @param {object} options Plugin options
|
|
84
84
|
* @param {Function} options.errorHandler Function that is invoked on yaml parsing errors.
|
|
85
85
|
*/
|
|
86
|
-
function matterPlugin(options) {
|
|
86
|
+
export default function matterPlugin(options) {
|
|
87
87
|
const data = this.data();
|
|
88
88
|
|
|
89
89
|
function add(field, value) {
|
|
90
|
-
/*
|
|
90
|
+
/* c8 ignore next 2 */
|
|
91
91
|
if (data[field]) {
|
|
92
92
|
data[field].push(value);
|
|
93
93
|
} else {
|
|
@@ -99,5 +99,3 @@ function matterPlugin(options) {
|
|
|
99
99
|
add('fromMarkdownExtensions', fromMarkdown(options));
|
|
100
100
|
add('toMarkdownExtensions', toMarkdown(options));
|
|
101
101
|
}
|
|
102
|
-
|
|
103
|
-
module.exports = matterPlugin;
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
/* eslint-disable no-use-before-define */
|
|
13
|
-
|
|
13
|
+
import jsYaml from 'js-yaml';
|
|
14
14
|
|
|
15
15
|
const type = (v) => ((v !== undefined && v !== null) ? v.constructor : v);
|
|
16
16
|
|
|
@@ -33,11 +33,9 @@ function validYaml(str, errorHandler) {
|
|
|
33
33
|
if (Array.isArray(payload)) {
|
|
34
34
|
payloadType = 'Array';
|
|
35
35
|
}
|
|
36
|
-
errorHandler(
|
|
37
|
-
'Found ambiguous frontmatter block: Block contains valid yaml, but '
|
|
36
|
+
errorHandler('Found ambiguous frontmatter block: Block contains valid yaml, but '
|
|
38
37
|
+ `it's data type is "${payloadType}" instead of Object. `
|
|
39
|
-
+ 'Make sure your yaml blocks contain only key-value pairs at the root level!', str
|
|
40
|
-
);
|
|
38
|
+
+ 'Make sure your yaml blocks contain only key-value pairs at the root level!', str);
|
|
41
39
|
}
|
|
42
40
|
return false;
|
|
43
41
|
}
|
|
@@ -265,12 +263,10 @@ function parse(options) {
|
|
|
265
263
|
}
|
|
266
264
|
}
|
|
267
265
|
|
|
268
|
-
function create(options = {}) {
|
|
266
|
+
export default function create(options = {}) {
|
|
269
267
|
return {
|
|
270
268
|
flow: {
|
|
271
269
|
[CODE_DASH]: [parse(options)],
|
|
272
270
|
},
|
|
273
271
|
};
|
|
274
272
|
}
|
|
275
|
-
|
|
276
|
-
module.exports = create;
|
|
@@ -9,12 +9,10 @@
|
|
|
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
|
-
function toMarkdown() {
|
|
12
|
+
export default function toMarkdown() {
|
|
13
13
|
return {
|
|
14
14
|
handlers: {
|
|
15
15
|
yaml: (node) => `---\n${node.value.trim()}\n---`,
|
|
16
16
|
},
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
module.exports = toMarkdown;
|
package/.github/move.yml
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# Configuration for move-issues - https://github.com/dessant/move-issues
|
|
2
|
-
|
|
3
|
-
# Delete the command comment when it contains no other content
|
|
4
|
-
deleteCommand: true
|
|
5
|
-
|
|
6
|
-
# Close the source issue after moving
|
|
7
|
-
closeSourceIssue: true
|
|
8
|
-
|
|
9
|
-
# Lock the source issue after moving
|
|
10
|
-
lockSourceIssue: true
|
|
11
|
-
|
|
12
|
-
# Mention issue and comment authors
|
|
13
|
-
mentionAuthors: true
|
|
14
|
-
|
|
15
|
-
# Preserve mentions in the issue content
|
|
16
|
-
keepContentMentions: true
|
package/docs/API.md
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<a name="main"></a>
|
|
2
|
-
|
|
3
|
-
## main(name) ⇒ <code>string</code>
|
|
4
|
-
This is the main function
|
|
5
|
-
|
|
6
|
-
**Kind**: global function
|
|
7
|
-
**Returns**: <code>string</code> - a greeting
|
|
8
|
-
|
|
9
|
-
| Param | Type | Default | Description |
|
|
10
|
-
| --- | --- | --- | --- |
|
|
11
|
-
| name | <code>string</code> | <code>"world"</code> | name of the person to greet |
|
|
12
|
-
|