@podlite/schema 0.0.12 → 0.0.13
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 +31 -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 +1 -0
- package/lib/grammarfc.js +1 -0
- 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 +39 -11
- 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 +69 -69
- package/lib/types.js +1 -0
- package/lib/writer.js +22 -7
- package/lib/writerHtml.js +3 -2
- package/package.json +7 -8
- package/schema/index.d.ts +3 -3
- package/index.js +0 -2
|
@@ -4,7 +4,7 @@ function flattenDeep(arr) {
|
|
|
4
4
|
if (!Array.isArray(arr)) {
|
|
5
5
|
return arr;
|
|
6
6
|
}
|
|
7
|
-
return arr.reduce((acc, val) => Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val), []);
|
|
7
|
+
return arr.reduce((acc, val) => (Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val)), []);
|
|
8
8
|
}
|
|
9
9
|
function thisFunc(rules) {
|
|
10
10
|
function interator(node, context) {
|
|
@@ -13,7 +13,7 @@ function thisFunc(rules) {
|
|
|
13
13
|
return flattenDeep(node.map(item => interator(item, context))).filter(Boolean);
|
|
14
14
|
}
|
|
15
15
|
if ('string' === typeof node) {
|
|
16
|
-
// convert string to lex node with type
|
|
16
|
+
// convert string to lex node with type
|
|
17
17
|
return interator({ type: 'text', value: node }, context);
|
|
18
18
|
}
|
|
19
19
|
// get first rule for this node
|
|
@@ -26,7 +26,9 @@ function thisFunc(rules) {
|
|
|
26
26
|
const nextRuleIndex = nextRuleSet.findIndex(rule => rule.isFor(node));
|
|
27
27
|
const defaultFn = (n = node, ctx = context, localInterator = interator) => {
|
|
28
28
|
if (nextRuleIndex !== -1) {
|
|
29
|
-
nextRuleSet[nextRuleIndex].fn(n, ctx, localInterator, () => {
|
|
29
|
+
nextRuleSet[nextRuleIndex].fn(n, ctx, localInterator, () => {
|
|
30
|
+
/* empty default action */
|
|
31
|
+
});
|
|
30
32
|
}
|
|
31
33
|
else {
|
|
32
34
|
return;
|
|
@@ -49,3 +51,4 @@ function thisFunc(rules) {
|
|
|
49
51
|
return interator;
|
|
50
52
|
}
|
|
51
53
|
exports.default = thisFunc;
|
|
54
|
+
//# sourceMappingURL=makeInterator.js.map
|
package/lib/helpers/makeQuery.js
CHANGED
|
@@ -87,7 +87,10 @@ const makeRule = (query, fn) => {
|
|
|
87
87
|
exports.makeRule = makeRule;
|
|
88
88
|
const makeRulesArray = (key, fn) => {
|
|
89
89
|
if (key instanceof Array) {
|
|
90
|
-
return key.reduce((acc, item) => {
|
|
90
|
+
return key.reduce((acc, item) => {
|
|
91
|
+
acc.push(...(0, exports.makeRulesArray)(item));
|
|
92
|
+
return acc;
|
|
93
|
+
}, []);
|
|
91
94
|
}
|
|
92
95
|
if (key instanceof Object) {
|
|
93
96
|
let rules = [];
|
|
@@ -101,3 +104,4 @@ const makeRulesArray = (key, fn) => {
|
|
|
101
104
|
return [(0, exports.makeRule)((0, exports.makePlug)(key), fn)];
|
|
102
105
|
};
|
|
103
106
|
exports.makeRulesArray = makeRulesArray;
|
|
107
|
+
//# sourceMappingURL=makeQuery.js.map
|
|
@@ -1,31 +1,40 @@
|
|
|
1
1
|
const makePlug = require('./makeQuery').makePlug;
|
|
2
2
|
const fixtures = [
|
|
3
|
-
'name:block',
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
'name:block',
|
|
4
|
+
{
|
|
5
|
+
name: 'name',
|
|
6
|
+
type: 'block',
|
|
6
7
|
},
|
|
7
|
-
'C<>',
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
'C<>',
|
|
9
|
+
{
|
|
10
|
+
name: 'C',
|
|
11
|
+
type: 'fcode',
|
|
10
12
|
},
|
|
11
|
-
':blankline',
|
|
12
|
-
|
|
13
|
+
':blankline',
|
|
14
|
+
{
|
|
15
|
+
type: 'blankline',
|
|
13
16
|
},
|
|
14
|
-
'*:block',
|
|
15
|
-
|
|
17
|
+
'*:block',
|
|
18
|
+
{
|
|
19
|
+
type: 'block',
|
|
16
20
|
},
|
|
17
|
-
'*:*',
|
|
18
|
-
|
|
19
|
-
'
|
|
20
|
-
|
|
21
|
+
'*:*',
|
|
22
|
+
{},
|
|
23
|
+
'*',
|
|
24
|
+
{},
|
|
25
|
+
'<>',
|
|
26
|
+
{
|
|
27
|
+
type: 'fcode',
|
|
21
28
|
},
|
|
22
|
-
'name',
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
'name',
|
|
30
|
+
{
|
|
31
|
+
name: 'name',
|
|
32
|
+
type: 'block',
|
|
25
33
|
},
|
|
26
|
-
'Special<>',
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
'Special<>',
|
|
35
|
+
{
|
|
36
|
+
name: 'Special',
|
|
37
|
+
type: 'fcode',
|
|
29
38
|
},
|
|
30
39
|
];
|
|
31
40
|
const pairs = fixtures.reduce(function (result, value, index, array) {
|
|
@@ -33,9 +42,10 @@ const pairs = fixtures.reduce(function (result, value, index, array) {
|
|
|
33
42
|
result.push(array.slice(index, index + 2));
|
|
34
43
|
return result;
|
|
35
44
|
}, []);
|
|
36
|
-
const log =
|
|
37
|
-
describe(
|
|
45
|
+
const log = a => console.log(JSON.stringify(a, null, 2));
|
|
46
|
+
describe('run make query helpers tests', () => {
|
|
38
47
|
pairs.map(([k, v], idx) => {
|
|
39
48
|
test(`test ${idx}`, () => expect(makePlug(k)).toEqual(v));
|
|
40
49
|
});
|
|
41
50
|
});
|
|
51
|
+
//# sourceMappingURL=makeQuery.test.js.map
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeTransformer = exports.isSemanticBlock = exports.isNamedBlock = void 0;
|
|
4
|
-
const
|
|
4
|
+
const makeQuery_1 = require("./makeQuery");
|
|
5
5
|
// the following names: MyBlock, myBlock are use for extending pod6
|
|
6
6
|
function isNamedBlock(name) {
|
|
7
|
-
return (name
|
|
8
|
-
&&
|
|
9
|
-
name !== name.toLowerCase()
|
|
10
|
-
&&
|
|
11
|
-
name !== name.toUpperCase());
|
|
7
|
+
return name && name !== name.toLowerCase() && name !== name.toUpperCase();
|
|
12
8
|
}
|
|
13
9
|
exports.isNamedBlock = isNamedBlock;
|
|
14
10
|
// skip warnings for semantic blocks
|
|
@@ -19,9 +15,9 @@ function isSemanticBlock(node) {
|
|
|
19
15
|
}
|
|
20
16
|
exports.isSemanticBlock = isSemanticBlock;
|
|
21
17
|
function flattenDeep(arr) {
|
|
22
|
-
return arr.reduce((acc, val) => Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val), []);
|
|
18
|
+
return arr.reduce((acc, val) => (Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val)), []);
|
|
23
19
|
}
|
|
24
|
-
const makeTransformer =
|
|
20
|
+
const makeTransformer = rule => {
|
|
25
21
|
let rules = [];
|
|
26
22
|
function use(key, fn) {
|
|
27
23
|
if (key instanceof Array) {
|
|
@@ -35,14 +31,14 @@ const makeTransformer = (rule) => {
|
|
|
35
31
|
}
|
|
36
32
|
return [];
|
|
37
33
|
}
|
|
38
|
-
rules.push(makeRule(makePlug(key), fn));
|
|
34
|
+
rules.push((0, makeQuery_1.makeRule)((0, makeQuery_1.makePlug)(key), fn));
|
|
39
35
|
}
|
|
40
36
|
function visiter(node, context = {}) {
|
|
41
37
|
if (node instanceof Array) {
|
|
42
38
|
return flattenDeep(node.map(item => visiter(item, context)));
|
|
43
39
|
}
|
|
44
40
|
if ('string' === typeof node) {
|
|
45
|
-
// convert string to lex node with type
|
|
41
|
+
// convert string to lex node with type
|
|
46
42
|
//return visiter({type:'text', value:node}, context)
|
|
47
43
|
return node;
|
|
48
44
|
}
|
|
@@ -68,3 +64,4 @@ const makeTransformer = (rule) => {
|
|
|
68
64
|
};
|
|
69
65
|
exports.makeTransformer = makeTransformer;
|
|
70
66
|
exports.default = exports.makeTransformer;
|
|
67
|
+
//# sourceMappingURL=makeTransformer.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toAnyRules = void 0;
|
|
4
|
+
const toAnyRules = (method, allplugins) => {
|
|
5
|
+
// make uniq plugins
|
|
6
|
+
const resultMap = allplugins.reverse().reduce((result, plugins) => {
|
|
7
|
+
for (const plugin of Object.entries(plugins)) {
|
|
8
|
+
const [key, val] = plugin;
|
|
9
|
+
if (!(key in result)) {
|
|
10
|
+
result[key] = val;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
}, {});
|
|
15
|
+
let result = {};
|
|
16
|
+
// prepare plugins for export <method>
|
|
17
|
+
for (const plugin of Object.entries(resultMap)) {
|
|
18
|
+
const [key, val = {}] = plugin;
|
|
19
|
+
//@ts-ignore
|
|
20
|
+
if (method in val) {
|
|
21
|
+
result[key] = val[method];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
exports.toAnyRules = toAnyRules;
|
|
27
|
+
//# sourceMappingURL=plugins.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ErrorObject } from 'ajv';
|
|
2
2
|
import { PodNode } from './types';
|
|
3
|
+
export { PodliteDocument } from './types';
|
|
3
4
|
export { AstTree } from './types';
|
|
4
5
|
export * from './types';
|
|
5
6
|
export * from './blocks-helpers';
|
|
@@ -11,6 +12,8 @@ export { makeTransformer, isNamedBlock, isSemanticBlock } from './helpers/makeTr
|
|
|
11
12
|
export { toAny } from './exportAny';
|
|
12
13
|
export { makeAttrs } from './helpers/config';
|
|
13
14
|
export { pluginCleanLocation } from './plugin-clean-location';
|
|
15
|
+
export { toAnyRules } from './helpers/plugins';
|
|
16
|
+
export { podlitePluggable, Podlite, PodliteExport, cleanIds, frozenIds } from './pluggableParser';
|
|
14
17
|
export declare function toAst(): {};
|
|
15
18
|
export declare type SchemaValidationError = ErrorObject<string, Record<string, any>>;
|
|
16
19
|
export declare function getTextContentFromNode(node: PodNode): string;
|
|
@@ -22,39 +25,39 @@ export interface Test {
|
|
|
22
25
|
ters: string;
|
|
23
26
|
}
|
|
24
27
|
export interface nBlock {
|
|
25
|
-
|
|
26
|
-
name:
|
|
28
|
+
type: 'block';
|
|
29
|
+
name: 'pod';
|
|
27
30
|
content: AST;
|
|
28
31
|
margin: string;
|
|
29
32
|
}
|
|
30
33
|
export interface nCode {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
type: 'code';
|
|
35
|
+
content: [];
|
|
36
|
+
name: string;
|
|
37
|
+
margin: string;
|
|
38
|
+
config: [];
|
|
39
|
+
text: string;
|
|
37
40
|
}
|
|
38
41
|
export interface nText {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
type: 'text';
|
|
43
|
+
content: [];
|
|
44
|
+
name: string;
|
|
45
|
+
margin: string;
|
|
46
|
+
config: [];
|
|
47
|
+
value: string;
|
|
45
48
|
}
|
|
46
49
|
export interface nPara {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
type: 'para';
|
|
51
|
+
content: [];
|
|
52
|
+
name: string;
|
|
53
|
+
margin: string;
|
|
54
|
+
config: [];
|
|
52
55
|
}
|
|
53
56
|
export interface nVerbatim {
|
|
54
57
|
type: 'verbatim';
|
|
55
58
|
value: string;
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
margin: string;
|
|
60
|
+
text: string;
|
|
58
61
|
}
|
|
59
62
|
export declare type Node = nBlock | nCode | nText | nPara | nVerbatim;
|
|
60
63
|
export declare type AST = Array<Node>;
|
package/lib/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
25
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.version = exports.Writer = exports.toHtml = exports.parse = exports.toTree = exports.isValidateError = exports.validateAst = exports.validateAstTree = exports.validatePodliteAst = exports.getTextContentFromNode = exports.toAst = exports.pluginCleanLocation = exports.makeAttrs = exports.toAny = exports.isSemanticBlock = exports.isNamedBlock = exports.makeTransformer = exports.makeInterator = void 0;
|
|
28
|
+
exports.version = exports.Writer = exports.toHtml = exports.parse = exports.toTree = exports.isValidateError = exports.validateAst = exports.validateAstTree = exports.validatePodliteAst = exports.getTextContentFromNode = exports.toAst = exports.frozenIds = exports.cleanIds = exports.podlitePluggable = exports.toAnyRules = exports.pluginCleanLocation = exports.makeAttrs = exports.toAny = exports.isSemanticBlock = exports.isNamedBlock = exports.makeTransformer = exports.makeInterator = void 0;
|
|
29
29
|
const ajv_1 = __importDefault(require("ajv"));
|
|
30
30
|
const pointer = __importStar(require("json-pointer"));
|
|
31
31
|
const jsonShemes = __importStar(require("../schema"));
|
|
@@ -47,7 +47,12 @@ var config_1 = require("./helpers/config");
|
|
|
47
47
|
Object.defineProperty(exports, "makeAttrs", { enumerable: true, get: function () { return config_1.makeAttrs; } });
|
|
48
48
|
var plugin_clean_location_1 = require("./plugin-clean-location");
|
|
49
49
|
Object.defineProperty(exports, "pluginCleanLocation", { enumerable: true, get: function () { return plugin_clean_location_1.pluginCleanLocation; } });
|
|
50
|
-
|
|
50
|
+
var plugins_1 = require("./helpers/plugins");
|
|
51
|
+
Object.defineProperty(exports, "toAnyRules", { enumerable: true, get: function () { return plugins_1.toAnyRules; } });
|
|
52
|
+
var pluggableParser_1 = require("./pluggableParser");
|
|
53
|
+
Object.defineProperty(exports, "podlitePluggable", { enumerable: true, get: function () { return pluggableParser_1.podlitePluggable; } });
|
|
54
|
+
Object.defineProperty(exports, "cleanIds", { enumerable: true, get: function () { return pluggableParser_1.cleanIds; } });
|
|
55
|
+
Object.defineProperty(exports, "frozenIds", { enumerable: true, get: function () { return pluggableParser_1.frozenIds; } });
|
|
51
56
|
const parser = __importStar(require("./grammar"));
|
|
52
57
|
const plugin_vmargin_1 = __importDefault(require("./plugin-vmargin"));
|
|
53
58
|
const plugin_formatting_codes_1 = __importDefault(require("./plugin-formatting-codes"));
|
|
@@ -65,10 +70,10 @@ const ajv = new ajv_1.default({ strict: true, allowUnionTypes: true });
|
|
|
65
70
|
function getTextContentFromNode(node) {
|
|
66
71
|
let text = '';
|
|
67
72
|
const rules = {
|
|
68
|
-
|
|
73
|
+
':text': node => {
|
|
69
74
|
text += node.value;
|
|
70
75
|
},
|
|
71
|
-
|
|
76
|
+
':verbatim': node => {
|
|
72
77
|
text += node.value;
|
|
73
78
|
},
|
|
74
79
|
};
|
|
@@ -77,9 +82,13 @@ function getTextContentFromNode(node) {
|
|
|
77
82
|
return text;
|
|
78
83
|
}
|
|
79
84
|
exports.getTextContentFromNode = getTextContentFromNode;
|
|
80
|
-
function validatePodliteAst(data) {
|
|
85
|
+
function validatePodliteAst(data) {
|
|
86
|
+
return validateAst(data, 'PodliteDocument');
|
|
87
|
+
}
|
|
81
88
|
exports.validatePodliteAst = validatePodliteAst;
|
|
82
|
-
function validateAstTree(data) {
|
|
89
|
+
function validateAstTree(data) {
|
|
90
|
+
return validateAst(data, 'AstTree');
|
|
91
|
+
}
|
|
83
92
|
exports.validateAstTree = validateAstTree;
|
|
84
93
|
function validateAst(data, Name = 'AstTree') {
|
|
85
94
|
const AstTreeSchema = jsonShemes[Name];
|
|
@@ -126,8 +135,8 @@ function makeTree() {
|
|
|
126
135
|
return;
|
|
127
136
|
}
|
|
128
137
|
function use(plugin) {
|
|
129
|
-
if (![
|
|
130
|
-
throw
|
|
138
|
+
if (!['function'].includes(typeof plugin)) {
|
|
139
|
+
throw plugin;
|
|
131
140
|
}
|
|
132
141
|
plugins.push(plugin);
|
|
133
142
|
return chain;
|
|
@@ -157,3 +166,4 @@ Object.defineProperty(exports, "Writer", { enumerable: true, get: function () {
|
|
|
157
166
|
// https://stackoverflow.com/questions/51070138/how-to-import-package-json-into-typescript-file-without-including-it-in-the-comp
|
|
158
167
|
const { version: VERSION } = require('../package.json');
|
|
159
168
|
exports.version = VERSION;
|
|
169
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Plugins, PodliteDocument } from '.';
|
|
2
|
+
export { cleanIds, frozenIds } from './helpers/ids';
|
|
3
|
+
export interface podlitePluggableOpt {
|
|
4
|
+
plugins?: Plugins;
|
|
5
|
+
}
|
|
6
|
+
export interface PodliteExport {
|
|
7
|
+
errors: any;
|
|
8
|
+
toString: () => string;
|
|
9
|
+
valueOf: () => string;
|
|
10
|
+
indexingTerms: any;
|
|
11
|
+
annotations: any;
|
|
12
|
+
defenitions: any;
|
|
13
|
+
interator: any;
|
|
14
|
+
}
|
|
15
|
+
export interface Podlite {
|
|
16
|
+
toAstResult: (ast: PodliteDocument) => PodliteExport;
|
|
17
|
+
(): any;
|
|
18
|
+
use: (plugin: Plugins) => Podlite;
|
|
19
|
+
parse: (text: string, opt?: {
|
|
20
|
+
skipChain: number;
|
|
21
|
+
podMode: number;
|
|
22
|
+
}) => PodliteDocument;
|
|
23
|
+
toHtml: (ast: PodliteDocument) => PodliteExport;
|
|
24
|
+
toAst: (ast: PodliteDocument) => PodliteDocument;
|
|
25
|
+
getPlugins: () => Array<Plugins>;
|
|
26
|
+
}
|
|
27
|
+
export declare const podlitePluggable: (params?: podlitePluggableOpt) => Podlite;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.podlitePluggable = exports.frozenIds = exports.cleanIds = void 0;
|
|
7
|
+
const _1 = require(".");
|
|
8
|
+
const ids_1 = __importDefault(require("./helpers/ids"));
|
|
9
|
+
const corePlugins_1 = __importDefault(require("./helpers/corePlugins"));
|
|
10
|
+
var ids_2 = require("./helpers/ids");
|
|
11
|
+
Object.defineProperty(exports, "cleanIds", { enumerable: true, get: function () { return ids_2.cleanIds; } });
|
|
12
|
+
Object.defineProperty(exports, "frozenIds", { enumerable: true, get: function () { return ids_2.frozenIds; } });
|
|
13
|
+
const podlitePluggable = ({ plugins = {} } = {}) => {
|
|
14
|
+
let instance = function () { };
|
|
15
|
+
let _plugins = [];
|
|
16
|
+
instance.use = (onj) => {
|
|
17
|
+
for (const plugin of Object.entries(onj)) {
|
|
18
|
+
const [key, val] = plugin;
|
|
19
|
+
if (typeof val === 'function') {
|
|
20
|
+
_plugins.push({ [key]: { toAst: val } });
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
_plugins.push({ [key]: val });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return instance;
|
|
27
|
+
};
|
|
28
|
+
instance.parse = (text, opt = { skipChain: 0, podMode: 1 }) => {
|
|
29
|
+
const rawTree = (0, _1.toTree)().use(ids_1.default).parse(text, opt);
|
|
30
|
+
const root = (0, _1.mkRootBlock)({ margin: '' }, rawTree);
|
|
31
|
+
return root;
|
|
32
|
+
};
|
|
33
|
+
instance.toAst = ast => {
|
|
34
|
+
return instance.toAstResult(ast).interator;
|
|
35
|
+
};
|
|
36
|
+
instance.toAstResult = ast => {
|
|
37
|
+
// get plugins for Ast
|
|
38
|
+
const toAstPlugins = (0, _1.toAnyRules)('toAst', instance.getPlugins());
|
|
39
|
+
const result = (0, _1.toAny)()
|
|
40
|
+
.use({
|
|
41
|
+
'*': () => (node, ctx, interator) => {
|
|
42
|
+
if ('content' in node) {
|
|
43
|
+
node.content = interator(node.content, ctx);
|
|
44
|
+
}
|
|
45
|
+
return node;
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
.use(toAstPlugins)
|
|
49
|
+
.run(ast);
|
|
50
|
+
// add second pass
|
|
51
|
+
const toAstAfterPlugins = (0, _1.toAnyRules)('toAstAfter', instance.getPlugins());
|
|
52
|
+
if (Object.keys(toAstAfterPlugins).length) {
|
|
53
|
+
const resultAfter = (0, _1.toAny)()
|
|
54
|
+
.use({
|
|
55
|
+
'*': () => (node, ctx, interator) => {
|
|
56
|
+
if ('content' in node) {
|
|
57
|
+
node.content = interator(node.content, ctx);
|
|
58
|
+
}
|
|
59
|
+
return node;
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
.use(toAstAfterPlugins)
|
|
63
|
+
.run(ast);
|
|
64
|
+
return resultAfter;
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
};
|
|
68
|
+
instance.toHtml = ast => {
|
|
69
|
+
const toHtmlPlugins = (0, _1.toAnyRules)('toHtml', instance.getPlugins());
|
|
70
|
+
return (0, _1.toHtml)({}).use(toHtmlPlugins).run(ast, null);
|
|
71
|
+
};
|
|
72
|
+
instance.getPlugins = () => _plugins;
|
|
73
|
+
// init core plugins
|
|
74
|
+
instance.use(corePlugins_1.default);
|
|
75
|
+
// init external plugins
|
|
76
|
+
instance.use(plugins);
|
|
77
|
+
return instance;
|
|
78
|
+
};
|
|
79
|
+
exports.podlitePluggable = podlitePluggable;
|
|
80
|
+
//# sourceMappingURL=pluggableParser.js.map
|
|
@@ -9,15 +9,18 @@ exports.pluginCleanLocation = void 0;
|
|
|
9
9
|
* use in test suite
|
|
10
10
|
*/
|
|
11
11
|
const makeTransformer_1 = __importDefault(require("./helpers/makeTransformer"));
|
|
12
|
-
const pluginCleanLocation = () =>
|
|
13
|
-
const transformer = (0, makeTransformer_1.default)({
|
|
12
|
+
const pluginCleanLocation = () => tree => {
|
|
13
|
+
const transformer = (0, makeTransformer_1.default)({
|
|
14
|
+
'*': (node, ctx, visiter) => {
|
|
14
15
|
if (node.content) {
|
|
15
16
|
node.content = visiter(node.content, ctx, visiter);
|
|
16
17
|
}
|
|
17
18
|
delete node.location;
|
|
18
19
|
return node;
|
|
19
|
-
}
|
|
20
|
+
},
|
|
21
|
+
});
|
|
20
22
|
return transformer(tree, {});
|
|
21
23
|
};
|
|
22
24
|
exports.pluginCleanLocation = pluginCleanLocation;
|
|
23
25
|
exports.default = exports.pluginCleanLocation;
|
|
26
|
+
//# sourceMappingURL=plugin-clean-location.js.map
|
|
@@ -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,71 @@
|
|
|
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';
|
|
29
52
|
const allowValues = conf.getAllValues('allow');
|
|
30
53
|
// for code block not parse content by default
|
|
31
54
|
if ((isCodeBlock || isDataBlock) && allowValues.length == 0)
|
|
32
55
|
return n;
|
|
33
56
|
const allowed = allowValues.sort();
|
|
34
57
|
const transformer = (0, makeTransformer_1.default)({
|
|
35
|
-
':verbatim': (n, ctx) => {
|
|
36
|
-
|
|
58
|
+
':verbatim': (n, ctx) => {
|
|
59
|
+
return fcparser.parse(n.value, { allowed });
|
|
60
|
+
},
|
|
61
|
+
':text': (n, ctx) => {
|
|
62
|
+
return fcparser.parse(n.value, { allowed });
|
|
63
|
+
},
|
|
37
64
|
':block': (n, ctx) => {
|
|
38
65
|
if ((0, makeTransformer_2.isNamedBlock)(n.name))
|
|
39
66
|
return n;
|
|
40
67
|
return { ...n, content: transformer(n.content, { ...ctx }) };
|
|
41
|
-
}
|
|
68
|
+
},
|
|
42
69
|
});
|
|
43
70
|
return transformer(n, { ...ctx });
|
|
44
71
|
},
|
|
@@ -46,3 +73,4 @@ const middle = () => (tree) => {
|
|
|
46
73
|
return transformerBlocks(tree, {});
|
|
47
74
|
};
|
|
48
75
|
exports.default = middle;
|
|
76
|
+
//# 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
|