@adobe/helix-markdown-support 3.1.8 → 4.0.2
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 +8 -19
- package/.eslintrc.cjs +1 -0
- package/CHANGELOG.md +26 -0
- package/package.json +16 -7
- package/src/gridtable/README.md +207 -0
- package/src/gridtable/from-markdown.js +273 -0
- package/src/gridtable/index.js +91 -0
- package/src/gridtable/mdast2hast-handler.js +119 -0
- package/src/gridtable/remark-plugin.js +36 -0
- package/src/gridtable/syntax.js +352 -0
- package/src/gridtable/to-markdown.js +538 -0
- package/src/gridtable/types.js +17 -0
- package/src/index.js +2 -1
- package/src/{remark-matter → matter}/from-markdown.js +4 -3
- package/src/{remark-matter → matter}/index.js +2 -19
- package/src/matter/remark-plugin.js +31 -0
- package/src/{remark-matter → matter}/syntax.js +3 -2
- package/src/{remark-matter → matter}/to-markdown.js +3 -1
- package/src/matter/types.js +12 -0
- package/src/mdast-dereference.js +65 -0
- package/src/mdast-image-references.js +55 -0
- package/src/mdast-robust-tables.js +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 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
|
+
export const TYPE_YAML = 'yaml';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 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
|
+
/* eslint-disable no-param-reassign */
|
|
13
|
+
import { visit, CONTINUE } from 'unist-util-visit';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Dereferences image and link references. Removes definitions no longer used.
|
|
17
|
+
*
|
|
18
|
+
* @param {object} tree
|
|
19
|
+
* @returns {object} The modified (original) tree.
|
|
20
|
+
*/
|
|
21
|
+
export default function dDereference(tree) {
|
|
22
|
+
const definitions = new Map();
|
|
23
|
+
|
|
24
|
+
// first find all definitions
|
|
25
|
+
visit(tree, (node, idx, parent) => {
|
|
26
|
+
if (node.type === 'definition') {
|
|
27
|
+
definitions.set(node.identifier, {
|
|
28
|
+
node,
|
|
29
|
+
parent,
|
|
30
|
+
refCount: 0,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return CONTINUE;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// find references
|
|
37
|
+
visit(tree, (node) => {
|
|
38
|
+
if (node.type === 'imageReference' || node.type === 'linkReference') {
|
|
39
|
+
const { identifier } = node;
|
|
40
|
+
const def = definitions.get(identifier);
|
|
41
|
+
if (def) {
|
|
42
|
+
def.refCount += 1;
|
|
43
|
+
node.url = def.node.url;
|
|
44
|
+
if (def.node.title) {
|
|
45
|
+
node.title = def.node.title;
|
|
46
|
+
}
|
|
47
|
+
node.type = node.type === 'imageReference'
|
|
48
|
+
? 'image'
|
|
49
|
+
: 'link';
|
|
50
|
+
delete node.identifier;
|
|
51
|
+
delete node.referenceType;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return CONTINUE;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// clean used definitions
|
|
58
|
+
for (const def of definitions.values()) {
|
|
59
|
+
if (def.refCount) {
|
|
60
|
+
const idx = def.parent.children.indexOf(def.node);
|
|
61
|
+
def.parent.children.splice(idx, 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return tree;
|
|
65
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 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
|
+
/* eslint-disable no-param-reassign */
|
|
13
|
+
import { visit, CONTINUE } from 'unist-util-visit';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates image references. Replaces images with a `imageReference` and respective `definition`
|
|
17
|
+
* nodes.
|
|
18
|
+
*
|
|
19
|
+
* @param {object} tree
|
|
20
|
+
* @returns {object} The modified (original) tree.
|
|
21
|
+
*/
|
|
22
|
+
export default function imageReferences(tree) {
|
|
23
|
+
const images = new Map();
|
|
24
|
+
const definitions = [];
|
|
25
|
+
|
|
26
|
+
visit(tree, (node) => {
|
|
27
|
+
if (node.type === 'image') {
|
|
28
|
+
const { url, alt = '', title } = node;
|
|
29
|
+
const key = `${url}\n${title}`;
|
|
30
|
+
let identifier = images.get(key);
|
|
31
|
+
if (!identifier) {
|
|
32
|
+
identifier = `image${images.size}`;
|
|
33
|
+
images.set(key, identifier);
|
|
34
|
+
const def = {
|
|
35
|
+
type: 'definition',
|
|
36
|
+
identifier,
|
|
37
|
+
url,
|
|
38
|
+
};
|
|
39
|
+
if (title) {
|
|
40
|
+
def.title = title;
|
|
41
|
+
}
|
|
42
|
+
definitions.push(def);
|
|
43
|
+
}
|
|
44
|
+
delete node.title;
|
|
45
|
+
node.type = 'imageReference';
|
|
46
|
+
node.identifier = identifier;
|
|
47
|
+
node.referenceType = 'full';
|
|
48
|
+
node.alt = alt.trim();
|
|
49
|
+
}
|
|
50
|
+
return CONTINUE;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
tree.children.push(...definitions);
|
|
54
|
+
return tree;
|
|
55
|
+
}
|
|
@@ -34,7 +34,7 @@ export default function robustTables(tree) {
|
|
|
34
34
|
attrs = ' align="right"';
|
|
35
35
|
} else if (cell.align === 'center') {
|
|
36
36
|
attrs = ' align="center"';
|
|
37
|
-
} else if (cell.align === '
|
|
37
|
+
} else if (cell.align === 'justify') {
|
|
38
38
|
attrs = ' align="justify"';
|
|
39
39
|
}
|
|
40
40
|
if (cell.valign === 'middle') {
|