@podlite/schema 0.0.12 → 0.0.14
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 +38 -4
- package/README.md +40 -0
- package/lib/ast-helpers.js +1 -0
- package/lib/ast-inerator.d.ts +0 -1
- package/lib/ast-inerator.js +5 -13
- package/lib/blocks-helpers.d.ts +1 -1
- package/lib/blocks-helpers.js +15 -12
- package/lib/exportAny.js +14 -6
- package/lib/exportHtml.js +43 -36
- package/lib/grammar.js +30 -21
- package/lib/grammarfc.js +1099 -243
- package/lib/helpers/config.js +8 -3
- package/lib/helpers/corePlugins.d.ts +12 -0
- package/lib/helpers/corePlugins.js +26 -0
- package/lib/helpers/handlers.js +1 -0
- package/lib/helpers/ids.d.ts +18 -0
- package/lib/helpers/ids.js +74 -0
- package/lib/helpers/makeInterator.js +6 -3
- package/lib/helpers/makeQuery.js +5 -1
- package/lib/helpers/makeQuery.test.js +32 -22
- package/lib/helpers/makeTransformer.js +7 -10
- package/lib/helpers/plugins.d.ts +2 -0
- package/lib/helpers/plugins.js +27 -0
- package/lib/index.d.ts +24 -21
- package/lib/index.js +18 -8
- package/lib/pluggableParser.d.ts +27 -0
- package/lib/pluggableParser.js +80 -0
- package/lib/plugin-clean-location.js +6 -3
- package/lib/plugin-defn-fill-term.js +7 -4
- package/lib/plugin-formatting-codes.js +41 -12
- package/lib/plugin-group-defn.js +10 -10
- package/lib/plugin-group-items.js +22 -20
- package/lib/plugin-heading.js +6 -3
- package/lib/plugin-items.js +9 -6
- package/lib/plugin-tables.js +46 -31
- package/lib/plugin-vmargin.js +5 -3
- package/lib/query-helpers.js +9 -6
- package/lib/types.d.ts +78 -70
- package/lib/types.js +1 -0
- package/lib/writer.js +22 -7
- package/lib/writerHtml.js +3 -2
- package/package.json +9 -9
- package/schema/AstTree.json +116 -0
- package/schema/PodliteDocument.json +116 -0
- package/schema/index.d.ts +3 -3
- package/index.js +0 -2
|
@@ -9,8 +9,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
* and the remaining content is treated as the definition for the term.
|
|
10
10
|
*/
|
|
11
11
|
const makeTransformer_1 = __importDefault(require("./helpers/makeTransformer"));
|
|
12
|
-
exports.default = () =>
|
|
13
|
-
const transformer = (0, makeTransformer_1.default)({
|
|
12
|
+
exports.default = () => tree => {
|
|
13
|
+
const transformer = (0, makeTransformer_1.default)({
|
|
14
|
+
defn: node => {
|
|
14
15
|
// get first non blank block
|
|
15
16
|
const content = node.content;
|
|
16
17
|
// skip all blank blocks
|
|
@@ -31,7 +32,7 @@ exports.default = () => (tree) => {
|
|
|
31
32
|
type: 'para',
|
|
32
33
|
name: 'term',
|
|
33
34
|
text: term,
|
|
34
|
-
content: [{ type: 'text', value: term }]
|
|
35
|
+
content: [{ type: 'text', value: term }],
|
|
35
36
|
};
|
|
36
37
|
newContent.push(newTermPara);
|
|
37
38
|
if (!(splited.length == 1 && splited[0] === '')) {
|
|
@@ -47,6 +48,8 @@ exports.default = () => (tree) => {
|
|
|
47
48
|
}
|
|
48
49
|
node.content = newContent;
|
|
49
50
|
return node;
|
|
50
|
-
}
|
|
51
|
+
},
|
|
52
|
+
});
|
|
51
53
|
return transformer(tree, {});
|
|
52
54
|
};
|
|
55
|
+
//# sourceMappingURL=plugin-defn-fill-term.js.map
|
|
@@ -1,44 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
2
21
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
23
|
};
|
|
5
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
25
|
+
const fcparser = __importStar(require("./grammarfc"));
|
|
7
26
|
const makeTransformer_1 = __importDefault(require("./helpers/makeTransformer"));
|
|
8
27
|
const makeTransformer_2 = require("./helpers/makeTransformer");
|
|
9
28
|
const config_1 = __importDefault(require("./helpers/config"));
|
|
10
|
-
const middle = () =>
|
|
29
|
+
const middle = () => tree => {
|
|
11
30
|
const transformerBlocks = (0, makeTransformer_1.default)({
|
|
12
31
|
':para': (n, ctx, visiter) => {
|
|
13
32
|
return (0, makeTransformer_1.default)({
|
|
14
|
-
':text': (n, ctx) => {
|
|
15
|
-
|
|
33
|
+
':text': (n, ctx) => {
|
|
34
|
+
return fcparser.parse(n.value);
|
|
35
|
+
},
|
|
36
|
+
':verbatim': (n, ctx) => {
|
|
37
|
+
return fcparser.parse(n.value);
|
|
38
|
+
},
|
|
16
39
|
})(n, { ...ctx });
|
|
17
40
|
return n;
|
|
18
41
|
},
|
|
19
42
|
':block': (n, ctx, visiter) => {
|
|
20
43
|
// only =pod may have childs blocks
|
|
21
|
-
if (
|
|
44
|
+
if ('name' in n && n.name === 'pod')
|
|
22
45
|
return {
|
|
23
46
|
...n,
|
|
24
|
-
content: visiter(n.content, ctx, visiter)
|
|
47
|
+
content: visiter(n.content, ctx, visiter),
|
|
25
48
|
};
|
|
26
49
|
const conf = (0, config_1.default)(n, ctx);
|
|
27
|
-
const isCodeBlock =
|
|
28
|
-
const isDataBlock =
|
|
50
|
+
const isCodeBlock = 'name' in n && n.name === 'code';
|
|
51
|
+
const isDataBlock = 'name' in n && n.name === 'data';
|
|
52
|
+
const isMarkdownBlock = 'name' in n && n.name === 'markdown';
|
|
29
53
|
const allowValues = conf.getAllValues('allow');
|
|
30
54
|
// for code block not parse content by default
|
|
31
|
-
if ((isCodeBlock || isDataBlock) && allowValues.length == 0)
|
|
55
|
+
if ((isCodeBlock || isDataBlock || isMarkdownBlock) && allowValues.length == 0)
|
|
32
56
|
return n;
|
|
33
57
|
const allowed = allowValues.sort();
|
|
34
58
|
const transformer = (0, makeTransformer_1.default)({
|
|
35
|
-
':verbatim': (n, ctx) => {
|
|
36
|
-
|
|
59
|
+
':verbatim': (n, ctx) => {
|
|
60
|
+
return fcparser.parse(n.value, { allowed });
|
|
61
|
+
},
|
|
62
|
+
':text': (n, ctx) => {
|
|
63
|
+
return fcparser.parse(n.value, { allowed });
|
|
64
|
+
},
|
|
37
65
|
':block': (n, ctx) => {
|
|
38
66
|
if ((0, makeTransformer_2.isNamedBlock)(n.name))
|
|
39
67
|
return n;
|
|
40
68
|
return { ...n, content: transformer(n.content, { ...ctx }) };
|
|
41
|
-
}
|
|
69
|
+
},
|
|
42
70
|
});
|
|
43
71
|
return transformer(n, { ...ctx });
|
|
44
72
|
},
|
|
@@ -46,3 +74,4 @@ const middle = () => (tree) => {
|
|
|
46
74
|
return transformerBlocks(tree, {});
|
|
47
75
|
};
|
|
48
76
|
exports.default = middle;
|
|
77
|
+
//# sourceMappingURL=plugin-formatting-codes.js.map
|
package/lib/plugin-group-defn.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = () =>
|
|
4
|
-
const isNodesEqual = (n1, n2) =>
|
|
5
|
-
// if nodes items
|
|
3
|
+
exports.default = () => tree => {
|
|
4
|
+
const isNodesEqual = (n1, n2) =>
|
|
5
|
+
// if nodes items
|
|
6
6
|
(n1.name === 'item' || n1.name === 'defn') &&
|
|
7
7
|
n2.name === n1.name &&
|
|
8
8
|
n1['level'] === n2.level &&
|
|
9
|
-
isNumbered(n1) === isNumbered(n2)
|
|
10
|
-
const isNumbered =
|
|
11
|
-
const group =
|
|
9
|
+
isNumbered(n1) === isNumbered(n2);
|
|
10
|
+
const isNumbered = node => Boolean(node.config && node.config.numbered);
|
|
11
|
+
const group = a => {
|
|
12
12
|
let lastItem = {};
|
|
13
13
|
let result = a.reduce((a, i) => {
|
|
14
14
|
if (i.name === 'defn') {
|
|
@@ -41,14 +41,13 @@ exports.default = () => (tree) => {
|
|
|
41
41
|
return item;
|
|
42
42
|
}
|
|
43
43
|
// get type of list
|
|
44
|
-
const list = item[0].name === 'defn' ? 'variable' :
|
|
45
|
-
isNumbered(item[0]) ? 'ordered' : 'itemized';
|
|
44
|
+
const list = item[0].name === 'defn' ? 'variable' : isNumbered(item[0]) ? 'ordered' : 'itemized';
|
|
46
45
|
// create items container
|
|
47
46
|
return {
|
|
48
47
|
type: 'list',
|
|
49
48
|
list,
|
|
50
49
|
level: 1,
|
|
51
|
-
content: [...item]
|
|
50
|
+
content: [...item],
|
|
52
51
|
};
|
|
53
52
|
}
|
|
54
53
|
if (item.content && item.type !== 'fcode') {
|
|
@@ -57,7 +56,7 @@ exports.default = () => (tree) => {
|
|
|
57
56
|
return item;
|
|
58
57
|
});
|
|
59
58
|
};
|
|
60
|
-
const visit =
|
|
59
|
+
const visit = node => {
|
|
61
60
|
if (Array.isArray(node)) {
|
|
62
61
|
return group(node);
|
|
63
62
|
}
|
|
@@ -71,3 +70,4 @@ exports.default = () => (tree) => {
|
|
|
71
70
|
tree = visit(tree);
|
|
72
71
|
return tree;
|
|
73
72
|
};
|
|
73
|
+
//# sourceMappingURL=plugin-group-defn.js.map
|
|
@@ -4,46 +4,47 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const config_1 = __importDefault(require("./helpers/config"));
|
|
7
|
-
exports.default = () =>
|
|
8
|
-
const isNodesEqual = (n1, n2) =>
|
|
9
|
-
// if nodes items
|
|
7
|
+
exports.default = () => tree => {
|
|
8
|
+
const isNodesEqual = (n1, n2) =>
|
|
9
|
+
// if nodes items
|
|
10
10
|
(n1.name === 'item' || n1.name === 'defn') &&
|
|
11
11
|
n2.name === n1.name &&
|
|
12
12
|
n1['level'] === n2.level &&
|
|
13
|
-
isNumbered(n1) === isNumbered(n2)
|
|
14
|
-
const isNumbered =
|
|
13
|
+
isNumbered(n1) === isNumbered(n2);
|
|
14
|
+
const isNumbered = node => Boolean((0, config_1.default)(node, {}).exists('numbered'));
|
|
15
15
|
const group = (a, level = 1) => {
|
|
16
|
-
const isInListMode =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
const isInListMode = a => {
|
|
17
|
+
return a.length > 0 && a[a.length - 1].type === 'list';
|
|
18
|
+
};
|
|
19
|
+
const getList = a => {
|
|
20
|
+
if (isInListMode(a))
|
|
21
|
+
return a[a.length - 1];
|
|
22
|
+
};
|
|
23
|
+
const isInsertableToList = (l, i) => (i.name && i.name === 'item' && i.type && i.type === 'block') || i.type === 'blankline';
|
|
22
24
|
let lastItem = {};
|
|
23
25
|
let result = a.reduce((a, i) => {
|
|
24
26
|
// skip items out of level
|
|
25
27
|
if (i.name === 'item' && i.type === 'block' && i.level < level) {
|
|
26
28
|
return [...a, i];
|
|
27
29
|
}
|
|
28
|
-
if (i.name === 'item' &&
|
|
29
|
-
|
|
30
|
+
if (i.name === 'item' &&
|
|
31
|
+
i.type === 'block' &&
|
|
32
|
+
(!isInListMode(a) ||
|
|
30
33
|
// different type of list and item
|
|
31
34
|
// at the same level
|
|
32
|
-
(i.level === level
|
|
33
|
-
&&
|
|
34
|
-
getList(a).list !== (isNumbered(i) ? 'ordered' : 'itemized')))) {
|
|
35
|
+
(i.level === level && getList(a).list !== (isNumbered(i) ? 'ordered' : 'itemized')))) {
|
|
35
36
|
// create empty list
|
|
36
37
|
// list = ['ordered', 'variable', 'itemized']
|
|
37
38
|
a.push({
|
|
38
39
|
type: 'list',
|
|
39
40
|
level: i.level,
|
|
40
41
|
content: [],
|
|
41
|
-
list: isNumbered(i) ? 'ordered' : 'itemized'
|
|
42
|
+
list: isNumbered(i) ? 'ordered' : 'itemized',
|
|
42
43
|
});
|
|
43
44
|
}
|
|
44
45
|
// main logic
|
|
45
|
-
if (isInListMode(a)
|
|
46
|
-
|
|
46
|
+
if (isInListMode(a) && isInsertableToList(getList(a), i)) {
|
|
47
|
+
// getlist and push item to them
|
|
47
48
|
getList(a).content.push(i);
|
|
48
49
|
}
|
|
49
50
|
else {
|
|
@@ -66,7 +67,7 @@ exports.default = () => (tree) => {
|
|
|
66
67
|
return item;
|
|
67
68
|
});
|
|
68
69
|
};
|
|
69
|
-
const visit =
|
|
70
|
+
const visit = node => {
|
|
70
71
|
if (Array.isArray(node)) {
|
|
71
72
|
node = group(node);
|
|
72
73
|
}
|
|
@@ -80,3 +81,4 @@ exports.default = () => (tree) => {
|
|
|
80
81
|
tree = visit(tree);
|
|
81
82
|
return tree;
|
|
82
83
|
};
|
|
84
|
+
//# sourceMappingURL=plugin-group-items.js.map
|
package/lib/plugin-heading.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = () =>
|
|
4
|
-
const visit =
|
|
3
|
+
exports.default = () => tree => {
|
|
4
|
+
const visit = node => {
|
|
5
5
|
if (Array.isArray(node)) {
|
|
6
|
-
node.forEach(i => {
|
|
6
|
+
node.forEach(i => {
|
|
7
|
+
visit(i);
|
|
8
|
+
});
|
|
7
9
|
}
|
|
8
10
|
else {
|
|
9
11
|
if (node && node.type === 'block') {
|
|
@@ -30,3 +32,4 @@ exports.default = () => (tree) => {
|
|
|
30
32
|
visit(tree);
|
|
31
33
|
return tree;
|
|
32
34
|
};
|
|
35
|
+
//# sourceMappingURL=plugin-heading.js.map
|
package/lib/plugin-items.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = () =>
|
|
4
|
-
const visit =
|
|
3
|
+
exports.default = () => tree => {
|
|
4
|
+
const visit = node => {
|
|
5
5
|
if (Array.isArray(node)) {
|
|
6
|
-
node.forEach(i => {
|
|
6
|
+
node.forEach(i => {
|
|
7
|
+
visit(i);
|
|
8
|
+
});
|
|
7
9
|
}
|
|
8
10
|
else {
|
|
9
11
|
if (node && node.type === 'block') {
|
|
@@ -23,9 +25,9 @@ exports.default = () => (tree) => {
|
|
|
23
25
|
}
|
|
24
26
|
node.config = node.config || [];
|
|
25
27
|
node.config.push({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
name: 'numbered',
|
|
29
|
+
value: true,
|
|
30
|
+
type: 'boolean',
|
|
29
31
|
});
|
|
30
32
|
}
|
|
31
33
|
}
|
|
@@ -38,3 +40,4 @@ exports.default = () => (tree) => {
|
|
|
38
40
|
visit(tree);
|
|
39
41
|
return tree;
|
|
40
42
|
};
|
|
43
|
+
//# sourceMappingURL=plugin-items.js.map
|
package/lib/plugin-tables.js
CHANGED
|
@@ -10,12 +10,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
*/
|
|
11
11
|
const makeTransformer_1 = __importDefault(require("./helpers/makeTransformer"));
|
|
12
12
|
function flattenDeep(arr) {
|
|
13
|
-
return arr.reduce((acc, val) => Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val), []);
|
|
13
|
+
return arr.reduce((acc, val) => (Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val)), []);
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Helpers section
|
|
17
17
|
*/
|
|
18
|
-
// run cb in symbols pair
|
|
18
|
+
// run cb in symbols pair
|
|
19
19
|
const strbin = (str1, str2, cb) => {
|
|
20
20
|
let res = [];
|
|
21
21
|
for (let i = 0; str1.length > i; i++) {
|
|
@@ -28,33 +28,36 @@ const makeMask = (lines, separators) => {
|
|
|
28
28
|
// calculate template length
|
|
29
29
|
const tmplLength = Math.max(...[...lines, ...separators].map(s => s.length));
|
|
30
30
|
// make bin mask for each string
|
|
31
|
-
const masks = lines.map(
|
|
31
|
+
const masks = lines.map(str => {
|
|
32
32
|
/** make mask for each line
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
' The Shoveller | Eddie Stevens | King Arthur\'s singing shovel',
|
|
34
|
+
'0000000011111111111110001111111111111000001111111111111111111111111111' ]
|
|
35
|
+
then not(mask) ... then & masks
|
|
36
|
+
*/
|
|
37
37
|
// enlarge string to tmplLength
|
|
38
|
-
let tstr = str +
|
|
38
|
+
let tstr = str + ' '.repeat(tmplLength - str.length);
|
|
39
39
|
let mask = [];
|
|
40
40
|
const re = /\s+[+|\s]\s/g;
|
|
41
41
|
let match;
|
|
42
42
|
while ((match = re.exec(tstr)) != null) {
|
|
43
|
-
const tmpMask = '1'.repeat(match.index) +
|
|
44
|
-
'0'.repeat(match[0].length);
|
|
43
|
+
const tmpMask = '1'.repeat(match.index) + '0'.repeat(match[0].length);
|
|
45
44
|
mask.push(tmpMask + '1'.repeat(tmplLength - tmpMask.length));
|
|
46
45
|
}
|
|
47
|
-
return mask.reduce((a, b) => {
|
|
46
|
+
return mask.reduce((a, b) => {
|
|
47
|
+
return strbin(a, b, (i1, i2) => i1 & i2);
|
|
48
|
+
}, '1'.repeat(tmplLength));
|
|
48
49
|
});
|
|
49
50
|
// make result mask
|
|
50
|
-
const inverted = masks.map(m => strbin(m, '',
|
|
51
|
-
const columnTemplate = inverted.reduce((a, b) => {
|
|
51
|
+
const inverted = masks.map(m => strbin(m, '', i1 => (i1 == 0 ? 1 : 0)));
|
|
52
|
+
const columnTemplate = inverted.reduce((a, b) => {
|
|
53
|
+
return strbin(a, b, (i1, i2) => i1 & i2);
|
|
54
|
+
}, '1'.repeat(tmplLength));
|
|
52
55
|
return columnTemplate;
|
|
53
56
|
};
|
|
54
57
|
const extractColumnsByTemplate = (text, template) => {
|
|
55
|
-
const lines = flattenDeep(text
|
|
56
|
-
.
|
|
57
|
-
|
|
58
|
+
const lines = flattenDeep(text
|
|
59
|
+
.split(/\n/) // split each row by eol
|
|
60
|
+
.filter(str => str.length > 0));
|
|
58
61
|
const cols = lines.map(line => {
|
|
59
62
|
const re = /((1+|0+))/g;
|
|
60
63
|
let columns = [];
|
|
@@ -79,53 +82,65 @@ const extractColumnsByTemplate = (text, template) => {
|
|
|
79
82
|
/**
|
|
80
83
|
* Main transforms
|
|
81
84
|
*/
|
|
82
|
-
exports.default = () =>
|
|
83
|
-
const transformer = (0, makeTransformer_1.default)({
|
|
85
|
+
exports.default = () => tree => {
|
|
86
|
+
const transformer = (0, makeTransformer_1.default)({
|
|
87
|
+
table: node => {
|
|
84
88
|
let rows = [];
|
|
85
|
-
const collectValues =
|
|
89
|
+
const collectValues = row => {
|
|
90
|
+
rows.push(row.value);
|
|
91
|
+
};
|
|
86
92
|
// collect separators for calculate max length of rows
|
|
87
93
|
let seps = [];
|
|
88
94
|
(0, makeTransformer_1.default)({
|
|
89
95
|
'row:text': collectValues,
|
|
90
96
|
'head:text': collectValues,
|
|
91
|
-
':separator':
|
|
97
|
+
':separator': sep => {
|
|
98
|
+
seps.push(sep.text);
|
|
99
|
+
},
|
|
92
100
|
})(node);
|
|
93
101
|
// add table-caption
|
|
94
102
|
// if table empty return node as is
|
|
95
103
|
if (!rows.length)
|
|
96
104
|
return node;
|
|
97
|
-
const splitToLines =
|
|
98
|
-
.
|
|
105
|
+
const splitToLines = row => row
|
|
106
|
+
.split(/\n/) // split each row by eol
|
|
107
|
+
.filter(str => str.length > 0); // filter empty strings ( after slit )
|
|
99
108
|
// split each row into lines
|
|
100
109
|
const lines = flattenDeep(rows.map(splitToLines));
|
|
101
110
|
const separators = flattenDeep(seps.map(splitToLines));
|
|
102
111
|
// collect text rows
|
|
103
112
|
let textRows = [];
|
|
104
113
|
(0, makeTransformer_1.default)({
|
|
105
|
-
'row:text':
|
|
114
|
+
'row:text': row => {
|
|
115
|
+
textRows.push(row.value);
|
|
116
|
+
},
|
|
106
117
|
})(node);
|
|
107
118
|
const columnTemplate = makeMask(lines, separators);
|
|
108
|
-
const makeBlock = (name, content, ...attr) => {
|
|
119
|
+
const makeBlock = (name, content, ...attr) => {
|
|
120
|
+
return { ...attr, name, type: 'block', content: Array.isArray(content) ? content : [content] };
|
|
121
|
+
};
|
|
109
122
|
// make columns
|
|
110
123
|
const res = (0, makeTransformer_1.default)({
|
|
111
|
-
'row:text':
|
|
124
|
+
'row:text': row => {
|
|
112
125
|
if (textRows.length == 1) {
|
|
113
126
|
// split each text row into lines
|
|
114
127
|
const textRowsLines = flattenDeep([row.value].map(splitToLines));
|
|
115
|
-
return textRowsLines.map(
|
|
128
|
+
return textRowsLines.map(rowValue => {
|
|
116
129
|
const res = extractColumnsByTemplate(rowValue, columnTemplate);
|
|
117
|
-
return makeBlock('table_row', res.map(
|
|
130
|
+
return makeBlock('table_row', res.map(col => makeBlock('table_cell', { type: 'text', value: col })));
|
|
118
131
|
});
|
|
119
132
|
}
|
|
120
133
|
const res = extractColumnsByTemplate(row.value, columnTemplate);
|
|
121
|
-
return makeBlock('table_row', res.map(
|
|
134
|
+
return makeBlock('table_row', res.map(col => makeBlock('table_cell', { type: 'text', value: col })));
|
|
122
135
|
},
|
|
123
|
-
'head:text':
|
|
136
|
+
'head:text': head => {
|
|
124
137
|
const res = extractColumnsByTemplate(head.value, columnTemplate);
|
|
125
|
-
return makeBlock('table_head', res.map(
|
|
138
|
+
return makeBlock('table_head', res.map(col => makeBlock('table_cell', { type: 'text', value: col })));
|
|
126
139
|
},
|
|
127
140
|
})(node);
|
|
128
141
|
return res;
|
|
129
|
-
}
|
|
142
|
+
},
|
|
143
|
+
});
|
|
130
144
|
return transformer(tree, {});
|
|
131
145
|
};
|
|
146
|
+
//# sourceMappingURL=plugin-tables.js.map
|
package/lib/plugin-vmargin.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const middle = () =>
|
|
3
|
+
const middle = () => tree => {
|
|
4
4
|
const visit_node = (node, context = {}) => {
|
|
5
5
|
// if( (node.type || "").match(/(code|text)/) ) {
|
|
6
6
|
if (node.type == 'code' || node.type == 'text') {
|
|
7
7
|
if (node.margin && context.margin && context.margin.length > 0 && context.margin.length == node.margin.length) {
|
|
8
|
+
;
|
|
8
9
|
node.type = 'para';
|
|
9
10
|
}
|
|
10
11
|
if (node.type === 'code') {
|
|
@@ -17,13 +18,14 @@ const middle = () => (tree) => {
|
|
|
17
18
|
context.margin = typeof node.margin !== 'string' ? '' : node.margin;
|
|
18
19
|
let newctx = { ...context };
|
|
19
20
|
newctx.nest = (newctx.nest || 0) + 1;
|
|
20
|
-
node.content.map(
|
|
21
|
+
node.content.map(n => {
|
|
21
22
|
visit_node(n, context);
|
|
22
23
|
});
|
|
23
24
|
}
|
|
24
25
|
};
|
|
25
26
|
var ctx = {};
|
|
26
|
-
tree.forEach(
|
|
27
|
+
tree.forEach(n => visit_node(n, ctx));
|
|
27
28
|
return tree;
|
|
28
29
|
};
|
|
29
30
|
exports.default = middle;
|
|
31
|
+
//# sourceMappingURL=plugin-vmargin.js.map
|
package/lib/query-helpers.js
CHANGED
|
@@ -31,7 +31,7 @@ const compileQuery = (...obj) => {
|
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
33
|
// obj should accomplished if some queries is true
|
|
34
|
-
if (compiledQueries.some(
|
|
34
|
+
if (compiledQueries.some(fn => fn(item).length > 0)) {
|
|
35
35
|
result.push(item);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -43,7 +43,7 @@ exports.compileQuery = compileQuery;
|
|
|
43
43
|
const compileAtomQuery = (obj) => {
|
|
44
44
|
const queries = [];
|
|
45
45
|
if (obj instanceof Array) {
|
|
46
|
-
throw new Error(
|
|
46
|
+
throw new Error('Wrong query parameter [Array], should be [Function] or [Object]');
|
|
47
47
|
}
|
|
48
48
|
else if (typeof obj === 'function') {
|
|
49
49
|
queries.push(obj);
|
|
@@ -51,7 +51,7 @@ const compileAtomQuery = (obj) => {
|
|
|
51
51
|
else {
|
|
52
52
|
for (const entry of Object.entries(obj)) {
|
|
53
53
|
const [key, value] = entry;
|
|
54
|
-
const checkValue =
|
|
54
|
+
const checkValue = val => {
|
|
55
55
|
if (value instanceof Array) {
|
|
56
56
|
return value.includes(val);
|
|
57
57
|
}
|
|
@@ -81,7 +81,7 @@ const compileAtomQuery = (obj) => {
|
|
|
81
81
|
result.push(...AND(item));
|
|
82
82
|
}
|
|
83
83
|
// obj should accomplished if all queries to be true
|
|
84
|
-
if (queries.every(
|
|
84
|
+
if (queries.every(fn => fn(item))) {
|
|
85
85
|
result.push(item);
|
|
86
86
|
}
|
|
87
87
|
});
|
|
@@ -100,12 +100,14 @@ const getFromTree = (tree, ...queries) => {
|
|
|
100
100
|
}
|
|
101
101
|
let results = [];
|
|
102
102
|
let rules = {};
|
|
103
|
-
const transformer = (0, _1.makeTransformer)({
|
|
103
|
+
const transformer = (0, _1.makeTransformer)({
|
|
104
|
+
'*:*': (node, ctx) => {
|
|
104
105
|
results.push(node);
|
|
105
106
|
if ('content' in node) {
|
|
106
107
|
return { node, content: transformer(node.content, { ...ctx }) };
|
|
107
108
|
}
|
|
108
|
-
}
|
|
109
|
+
},
|
|
110
|
+
});
|
|
109
111
|
transformer(tree, {});
|
|
110
112
|
//convert queries
|
|
111
113
|
const queryAtoms = [];
|
|
@@ -131,3 +133,4 @@ const getFromTree = (tree, ...queries) => {
|
|
|
131
133
|
return (0, exports.compileQuery)(...queryAtoms)(results);
|
|
132
134
|
};
|
|
133
135
|
exports.getFromTree = getFromTree;
|
|
136
|
+
//# sourceMappingURL=query-helpers.js.map
|