@podlite/schema 0.0.11 → 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 +36 -4
- package/LICENSE +1 -1
- package/README.md +40 -0
- package/lib/ast-helpers.d.ts +1 -1
- package/lib/ast-helpers.js +2 -1
- package/lib/ast-inerator.d.ts +0 -1
- package/lib/ast-inerator.js +7 -15
- package/lib/blocks-helpers.d.ts +1 -1
- package/lib/blocks-helpers.js +15 -12
- package/lib/exportAny.d.ts +19 -0
- package/lib/exportAny.js +72 -0
- package/lib/exportHtml.d.ts +15 -0
- package/lib/exportHtml.js +284 -0
- package/lib/grammar.d.ts +14 -0
- package/lib/grammar.js +6396 -0
- package/lib/grammarfc.d.ts +14 -0
- package/lib/grammarfc.js +3363 -0
- package/lib/helpers/config.d.ts +12 -0
- package/lib/helpers/config.js +56 -0
- package/lib/helpers/corePlugins.d.ts +12 -0
- package/lib/helpers/corePlugins.js +26 -0
- package/lib/helpers/handlers.d.ts +47 -0
- package/lib/helpers/handlers.js +120 -0
- package/lib/helpers/ids.d.ts +18 -0
- package/lib/helpers/ids.js +74 -0
- package/lib/helpers/makeInterator.d.ts +5 -0
- package/lib/helpers/makeInterator.js +54 -0
- package/lib/helpers/makeQuery.d.ts +47 -0
- package/lib/helpers/makeQuery.js +107 -0
- package/lib/helpers/makeQuery.test.d.ts +1 -0
- package/lib/helpers/makeQuery.test.js +51 -0
- package/lib/helpers/makeTransformer.d.ts +7 -0
- package/lib/helpers/makeTransformer.js +67 -0
- package/lib/helpers/plugins.d.ts +2 -0
- package/lib/helpers/plugins.js +27 -0
- package/lib/index.d.ts +64 -0
- package/lib/index.js +85 -5
- package/lib/pluggableParser.d.ts +27 -0
- package/lib/pluggableParser.js +80 -0
- package/lib/plugin-clean-location.d.ts +2 -0
- package/lib/plugin-clean-location.js +26 -0
- package/lib/plugin-defn-fill-term.d.ts +2 -0
- package/lib/plugin-defn-fill-term.js +55 -0
- package/lib/plugin-formatting-codes.d.ts +3 -0
- package/lib/plugin-formatting-codes.js +76 -0
- package/lib/plugin-group-defn.d.ts +2 -0
- package/lib/plugin-group-defn.js +73 -0
- package/lib/plugin-group-items.d.ts +2 -0
- package/lib/plugin-group-items.js +84 -0
- package/lib/plugin-heading.d.ts +2 -0
- package/lib/plugin-heading.js +35 -0
- package/lib/plugin-items.d.ts +2 -0
- package/lib/plugin-items.js +43 -0
- package/lib/plugin-tables.d.ts +5 -0
- package/lib/plugin-tables.js +146 -0
- package/lib/plugin-vmargin.d.ts +3 -0
- package/lib/plugin-vmargin.js +31 -0
- package/lib/query-helpers.d.ts +2 -1
- package/lib/query-helpers.js +10 -10
- package/lib/types.d.ts +69 -69
- package/lib/types.js +1 -0
- package/lib/writer.d.ts +30 -0
- package/lib/writer.js +106 -0
- package/lib/writerHtml.d.ts +11 -0
- package/lib/writerHtml.js +34 -0
- package/package.json +18 -10
- package/schema/index.d.ts +3 -3
- package/index.js +0 -2
- package/lib/helpers.d.ts +0 -1
- package/lib/helpers.js +0 -5
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeTransformer = exports.isSemanticBlock = exports.isNamedBlock = void 0;
|
|
4
|
+
const makeQuery_1 = require("./makeQuery");
|
|
5
|
+
// the following names: MyBlock, myBlock are use for extending pod6
|
|
6
|
+
function isNamedBlock(name) {
|
|
7
|
+
return name && name !== name.toLowerCase() && name !== name.toUpperCase();
|
|
8
|
+
}
|
|
9
|
+
exports.isNamedBlock = isNamedBlock;
|
|
10
|
+
// skip warnings for semantic blocks
|
|
11
|
+
function isSemanticBlock(node) {
|
|
12
|
+
const name = node.name || '';
|
|
13
|
+
const isTypeBlock = (node.type || '') === 'block';
|
|
14
|
+
return isTypeBlock && name === name.toUpperCase();
|
|
15
|
+
}
|
|
16
|
+
exports.isSemanticBlock = isSemanticBlock;
|
|
17
|
+
function flattenDeep(arr) {
|
|
18
|
+
return arr.reduce((acc, val) => (Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val)), []);
|
|
19
|
+
}
|
|
20
|
+
const makeTransformer = rule => {
|
|
21
|
+
let rules = [];
|
|
22
|
+
function use(key, fn) {
|
|
23
|
+
if (key instanceof Array) {
|
|
24
|
+
console.warn(`[pod] Unsupported param for ${key}`);
|
|
25
|
+
}
|
|
26
|
+
if (key instanceof Object) {
|
|
27
|
+
for (var prop in key) {
|
|
28
|
+
if (key.hasOwnProperty(prop)) {
|
|
29
|
+
use(prop, key[prop]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
rules.push((0, makeQuery_1.makeRule)((0, makeQuery_1.makePlug)(key), fn));
|
|
35
|
+
}
|
|
36
|
+
function visiter(node, context = {}) {
|
|
37
|
+
if (node instanceof Array) {
|
|
38
|
+
return flattenDeep(node.map(item => visiter(item, context)));
|
|
39
|
+
}
|
|
40
|
+
if ('string' === typeof node) {
|
|
41
|
+
// convert string to lex node with type
|
|
42
|
+
//return visiter({type:'text', value:node}, context)
|
|
43
|
+
return node;
|
|
44
|
+
}
|
|
45
|
+
// get first rule for this node
|
|
46
|
+
const reversed = rules.slice();
|
|
47
|
+
reversed.reverse();
|
|
48
|
+
const ruleIndex = reversed.findIndex(rule => rule.isFor(node));
|
|
49
|
+
if (ruleIndex !== -1) {
|
|
50
|
+
return reversed[ruleIndex].fn(node, context, visiter);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
// not found rule
|
|
54
|
+
const newNode = { ...node };
|
|
55
|
+
if (newNode.hasOwnProperty('content')) {
|
|
56
|
+
newNode.content = visiter(newNode.content, context);
|
|
57
|
+
}
|
|
58
|
+
return newNode;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
use(rule);
|
|
62
|
+
visiter.rules = rules;
|
|
63
|
+
return visiter;
|
|
64
|
+
};
|
|
65
|
+
exports.makeTransformer = makeTransformer;
|
|
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,11 +1,19 @@
|
|
|
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';
|
|
6
7
|
export * from './query-helpers';
|
|
7
8
|
export * from './ast-helpers';
|
|
9
|
+
export * from './helpers/handlers';
|
|
8
10
|
export { makeInterator } from './ast-inerator';
|
|
11
|
+
export { makeTransformer, isNamedBlock, isSemanticBlock } from './helpers/makeTransformer';
|
|
12
|
+
export { toAny } from './exportAny';
|
|
13
|
+
export { makeAttrs } from './helpers/config';
|
|
14
|
+
export { pluginCleanLocation } from './plugin-clean-location';
|
|
15
|
+
export { toAnyRules } from './helpers/plugins';
|
|
16
|
+
export { podlitePluggable, Podlite, PodliteExport, cleanIds, frozenIds } from './pluggableParser';
|
|
9
17
|
export declare function toAst(): {};
|
|
10
18
|
export declare type SchemaValidationError = ErrorObject<string, Record<string, any>>;
|
|
11
19
|
export declare function getTextContentFromNode(node: PodNode): string;
|
|
@@ -16,3 +24,59 @@ export declare function isValidateError(result: SchemaValidationError[], src: an
|
|
|
16
24
|
export interface Test {
|
|
17
25
|
ters: string;
|
|
18
26
|
}
|
|
27
|
+
export interface nBlock {
|
|
28
|
+
type: 'block';
|
|
29
|
+
name: 'pod';
|
|
30
|
+
content: AST;
|
|
31
|
+
margin: string;
|
|
32
|
+
}
|
|
33
|
+
export interface nCode {
|
|
34
|
+
type: 'code';
|
|
35
|
+
content: [];
|
|
36
|
+
name: string;
|
|
37
|
+
margin: string;
|
|
38
|
+
config: [];
|
|
39
|
+
text: string;
|
|
40
|
+
}
|
|
41
|
+
export interface nText {
|
|
42
|
+
type: 'text';
|
|
43
|
+
content: [];
|
|
44
|
+
name: string;
|
|
45
|
+
margin: string;
|
|
46
|
+
config: [];
|
|
47
|
+
value: string;
|
|
48
|
+
}
|
|
49
|
+
export interface nPara {
|
|
50
|
+
type: 'para';
|
|
51
|
+
content: [];
|
|
52
|
+
name: string;
|
|
53
|
+
margin: string;
|
|
54
|
+
config: [];
|
|
55
|
+
}
|
|
56
|
+
export interface nVerbatim {
|
|
57
|
+
type: 'verbatim';
|
|
58
|
+
value: string;
|
|
59
|
+
margin: string;
|
|
60
|
+
text: string;
|
|
61
|
+
}
|
|
62
|
+
export declare type Node = nBlock | nCode | nText | nPara | nVerbatim;
|
|
63
|
+
export declare type AST = Array<Node>;
|
|
64
|
+
export declare type ParserPlugin = (opt: {
|
|
65
|
+
skipChain: number;
|
|
66
|
+
podMode: number;
|
|
67
|
+
}) => (param: AST) => AST;
|
|
68
|
+
declare function makeTree(): {
|
|
69
|
+
(): void;
|
|
70
|
+
use: (plugin: ParserPlugin) => any;
|
|
71
|
+
parse: (src: string, opt?: {
|
|
72
|
+
skipChain: number;
|
|
73
|
+
podMode: number;
|
|
74
|
+
}) => AST;
|
|
75
|
+
};
|
|
76
|
+
export { makeTree as toTree };
|
|
77
|
+
declare const parse: Function;
|
|
78
|
+
export { parse as parse };
|
|
79
|
+
export { default as toHtml } from './exportHtml';
|
|
80
|
+
export { default as Writer } from './writer';
|
|
81
|
+
declare const VERSION: any;
|
|
82
|
+
export { VERSION as version };
|
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.isValidateError = exports.validateAst = exports.validateAstTree = exports.validatePodliteAst = exports.getTextContentFromNode = exports.toAst = 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"));
|
|
@@ -34,8 +34,34 @@ __exportStar(require("./types"), exports);
|
|
|
34
34
|
__exportStar(require("./blocks-helpers"), exports);
|
|
35
35
|
__exportStar(require("./query-helpers"), exports);
|
|
36
36
|
__exportStar(require("./ast-helpers"), exports);
|
|
37
|
+
__exportStar(require("./helpers/handlers"), exports);
|
|
37
38
|
var ast_inerator_2 = require("./ast-inerator");
|
|
38
39
|
Object.defineProperty(exports, "makeInterator", { enumerable: true, get: function () { return ast_inerator_2.makeInterator; } });
|
|
40
|
+
var makeTransformer_1 = require("./helpers/makeTransformer");
|
|
41
|
+
Object.defineProperty(exports, "makeTransformer", { enumerable: true, get: function () { return makeTransformer_1.makeTransformer; } });
|
|
42
|
+
Object.defineProperty(exports, "isNamedBlock", { enumerable: true, get: function () { return makeTransformer_1.isNamedBlock; } });
|
|
43
|
+
Object.defineProperty(exports, "isSemanticBlock", { enumerable: true, get: function () { return makeTransformer_1.isSemanticBlock; } });
|
|
44
|
+
var exportAny_1 = require("./exportAny");
|
|
45
|
+
Object.defineProperty(exports, "toAny", { enumerable: true, get: function () { return exportAny_1.toAny; } });
|
|
46
|
+
var config_1 = require("./helpers/config");
|
|
47
|
+
Object.defineProperty(exports, "makeAttrs", { enumerable: true, get: function () { return config_1.makeAttrs; } });
|
|
48
|
+
var plugin_clean_location_1 = require("./plugin-clean-location");
|
|
49
|
+
Object.defineProperty(exports, "pluginCleanLocation", { enumerable: true, get: function () { return plugin_clean_location_1.pluginCleanLocation; } });
|
|
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; } });
|
|
56
|
+
const parser = __importStar(require("./grammar"));
|
|
57
|
+
const plugin_vmargin_1 = __importDefault(require("./plugin-vmargin"));
|
|
58
|
+
const plugin_formatting_codes_1 = __importDefault(require("./plugin-formatting-codes"));
|
|
59
|
+
const plugin_items_1 = __importDefault(require("./plugin-items"));
|
|
60
|
+
const plugin_heading_1 = __importDefault(require("./plugin-heading"));
|
|
61
|
+
const plugin_group_defn_1 = __importDefault(require("./plugin-group-defn"));
|
|
62
|
+
const plugin_group_items_1 = __importDefault(require("./plugin-group-items"));
|
|
63
|
+
const plugin_defn_fill_term_1 = __importDefault(require("./plugin-defn-fill-term"));
|
|
64
|
+
const plugin_tables_1 = __importDefault(require("./plugin-tables"));
|
|
39
65
|
function toAst() {
|
|
40
66
|
return {};
|
|
41
67
|
}
|
|
@@ -44,10 +70,10 @@ const ajv = new ajv_1.default({ strict: true, allowUnionTypes: true });
|
|
|
44
70
|
function getTextContentFromNode(node) {
|
|
45
71
|
let text = '';
|
|
46
72
|
const rules = {
|
|
47
|
-
|
|
73
|
+
':text': node => {
|
|
48
74
|
text += node.value;
|
|
49
75
|
},
|
|
50
|
-
|
|
76
|
+
':verbatim': node => {
|
|
51
77
|
text += node.value;
|
|
52
78
|
},
|
|
53
79
|
};
|
|
@@ -56,9 +82,13 @@ function getTextContentFromNode(node) {
|
|
|
56
82
|
return text;
|
|
57
83
|
}
|
|
58
84
|
exports.getTextContentFromNode = getTextContentFromNode;
|
|
59
|
-
function validatePodliteAst(data) {
|
|
85
|
+
function validatePodliteAst(data) {
|
|
86
|
+
return validateAst(data, 'PodliteDocument');
|
|
87
|
+
}
|
|
60
88
|
exports.validatePodliteAst = validatePodliteAst;
|
|
61
|
-
function validateAstTree(data) {
|
|
89
|
+
function validateAstTree(data) {
|
|
90
|
+
return validateAst(data, 'AstTree');
|
|
91
|
+
}
|
|
62
92
|
exports.validateAstTree = validateAstTree;
|
|
63
93
|
function validateAst(data, Name = 'AstTree') {
|
|
64
94
|
const AstTreeSchema = jsonShemes[Name];
|
|
@@ -87,3 +117,53 @@ function isValidateError(result, src) {
|
|
|
87
117
|
return undefined;
|
|
88
118
|
}
|
|
89
119
|
exports.isValidateError = isValidateError;
|
|
120
|
+
function makeTree() {
|
|
121
|
+
var plugins = [];
|
|
122
|
+
chain.use = use;
|
|
123
|
+
chain.parse = parse;
|
|
124
|
+
chain.use(plugin_vmargin_1.default);
|
|
125
|
+
chain.use(plugin_items_1.default);
|
|
126
|
+
chain.use(plugin_heading_1.default);
|
|
127
|
+
chain.use(plugin_defn_fill_term_1.default);
|
|
128
|
+
chain.use(plugin_tables_1.default);
|
|
129
|
+
chain.use(plugin_formatting_codes_1.default);
|
|
130
|
+
// save order for the next two plugins
|
|
131
|
+
chain.use(plugin_group_items_1.default);
|
|
132
|
+
chain.use(plugin_group_defn_1.default);
|
|
133
|
+
return chain;
|
|
134
|
+
function chain() {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
function use(plugin) {
|
|
138
|
+
if (!['function'].includes(typeof plugin)) {
|
|
139
|
+
throw plugin;
|
|
140
|
+
}
|
|
141
|
+
plugins.push(plugin);
|
|
142
|
+
return chain;
|
|
143
|
+
}
|
|
144
|
+
function parse(src, opt = { skipChain: 0, podMode: 1 }) {
|
|
145
|
+
let tree = parser.parse(src, { podMode: opt.podMode });
|
|
146
|
+
if (!opt.skipChain) {
|
|
147
|
+
for (let i = 0; i < plugins.length; i++) {
|
|
148
|
+
const plugin = plugins[i];
|
|
149
|
+
// init
|
|
150
|
+
const visitor = plugin(opt);
|
|
151
|
+
// process tree
|
|
152
|
+
tree = visitor(tree);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return tree;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.toTree = makeTree;
|
|
159
|
+
const parse = makeTree().parse;
|
|
160
|
+
exports.parse = parse;
|
|
161
|
+
var exportHtml_1 = require("./exportHtml");
|
|
162
|
+
Object.defineProperty(exports, "toHtml", { enumerable: true, get: function () { return __importDefault(exportHtml_1).default; } });
|
|
163
|
+
var writer_1 = require("./writer");
|
|
164
|
+
Object.defineProperty(exports, "Writer", { enumerable: true, get: function () { return __importDefault(writer_1).default; } });
|
|
165
|
+
// Cannot be `import` as it's not under TS root dir
|
|
166
|
+
// https://stackoverflow.com/questions/51070138/how-to-import-package-json-into-typescript-file-without-including-it-in-the-comp
|
|
167
|
+
const { version: VERSION } = require('../package.json');
|
|
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
|
|
@@ -0,0 +1,26 @@
|
|
|
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.pluginCleanLocation = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Delete location attribute
|
|
9
|
+
* use in test suite
|
|
10
|
+
*/
|
|
11
|
+
const makeTransformer_1 = __importDefault(require("./helpers/makeTransformer"));
|
|
12
|
+
const pluginCleanLocation = () => tree => {
|
|
13
|
+
const transformer = (0, makeTransformer_1.default)({
|
|
14
|
+
'*': (node, ctx, visiter) => {
|
|
15
|
+
if (node.content) {
|
|
16
|
+
node.content = visiter(node.content, ctx, visiter);
|
|
17
|
+
}
|
|
18
|
+
delete node.location;
|
|
19
|
+
return node;
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
return transformer(tree, {});
|
|
23
|
+
};
|
|
24
|
+
exports.pluginCleanLocation = pluginCleanLocation;
|
|
25
|
+
exports.default = exports.pluginCleanLocation;
|
|
26
|
+
//# sourceMappingURL=plugin-clean-location.js.map
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
/**
|
|
7
|
+
* Plugin for fill term's for defn. From S26:
|
|
8
|
+
* The first non-blank line of content is treated as a term being defined,
|
|
9
|
+
* and the remaining content is treated as the definition for the term.
|
|
10
|
+
*/
|
|
11
|
+
const makeTransformer_1 = __importDefault(require("./helpers/makeTransformer"));
|
|
12
|
+
exports.default = () => tree => {
|
|
13
|
+
const transformer = (0, makeTransformer_1.default)({
|
|
14
|
+
defn: node => {
|
|
15
|
+
// get first non blank block
|
|
16
|
+
const content = node.content;
|
|
17
|
+
// skip all blank blocks
|
|
18
|
+
const count = content.length;
|
|
19
|
+
let newContent = [];
|
|
20
|
+
let isFirstParaProcessed = false;
|
|
21
|
+
for (let i = 0; i < count; i++) {
|
|
22
|
+
const item = content[i];
|
|
23
|
+
if (item.type === 'para' && !isFirstParaProcessed) {
|
|
24
|
+
// get text content
|
|
25
|
+
const textNode = item.content[0];
|
|
26
|
+
const text = textNode.value;
|
|
27
|
+
// split text by lines
|
|
28
|
+
// get first line
|
|
29
|
+
const splited = text.split('\n');
|
|
30
|
+
const term = splited.shift();
|
|
31
|
+
const newTermPara = {
|
|
32
|
+
type: 'para',
|
|
33
|
+
name: 'term',
|
|
34
|
+
text: term,
|
|
35
|
+
content: [{ type: 'text', value: term }],
|
|
36
|
+
};
|
|
37
|
+
newContent.push(newTermPara);
|
|
38
|
+
if (!(splited.length == 1 && splited[0] === '')) {
|
|
39
|
+
textNode.value = splited.join('\n');
|
|
40
|
+
item.text = textNode.value;
|
|
41
|
+
newContent.push(item);
|
|
42
|
+
}
|
|
43
|
+
isFirstParaProcessed = true;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
newContent.push(item);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
node.content = newContent;
|
|
50
|
+
return node;
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
return transformer(tree, {});
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=plugin-defn-fill-term.js.map
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const fcparser = __importStar(require("./grammarfc"));
|
|
26
|
+
const makeTransformer_1 = __importDefault(require("./helpers/makeTransformer"));
|
|
27
|
+
const makeTransformer_2 = require("./helpers/makeTransformer");
|
|
28
|
+
const config_1 = __importDefault(require("./helpers/config"));
|
|
29
|
+
const middle = () => tree => {
|
|
30
|
+
const transformerBlocks = (0, makeTransformer_1.default)({
|
|
31
|
+
':para': (n, ctx, visiter) => {
|
|
32
|
+
return (0, makeTransformer_1.default)({
|
|
33
|
+
':text': (n, ctx) => {
|
|
34
|
+
return fcparser.parse(n.value);
|
|
35
|
+
},
|
|
36
|
+
':verbatim': (n, ctx) => {
|
|
37
|
+
return fcparser.parse(n.value);
|
|
38
|
+
},
|
|
39
|
+
})(n, { ...ctx });
|
|
40
|
+
return n;
|
|
41
|
+
},
|
|
42
|
+
':block': (n, ctx, visiter) => {
|
|
43
|
+
// only =pod may have childs blocks
|
|
44
|
+
if ('name' in n && n.name === 'pod')
|
|
45
|
+
return {
|
|
46
|
+
...n,
|
|
47
|
+
content: visiter(n.content, ctx, visiter),
|
|
48
|
+
};
|
|
49
|
+
const conf = (0, config_1.default)(n, ctx);
|
|
50
|
+
const isCodeBlock = 'name' in n && n.name === 'code';
|
|
51
|
+
const isDataBlock = 'name' in n && n.name === 'data';
|
|
52
|
+
const allowValues = conf.getAllValues('allow');
|
|
53
|
+
// for code block not parse content by default
|
|
54
|
+
if ((isCodeBlock || isDataBlock) && allowValues.length == 0)
|
|
55
|
+
return n;
|
|
56
|
+
const allowed = allowValues.sort();
|
|
57
|
+
const transformer = (0, makeTransformer_1.default)({
|
|
58
|
+
':verbatim': (n, ctx) => {
|
|
59
|
+
return fcparser.parse(n.value, { allowed });
|
|
60
|
+
},
|
|
61
|
+
':text': (n, ctx) => {
|
|
62
|
+
return fcparser.parse(n.value, { allowed });
|
|
63
|
+
},
|
|
64
|
+
':block': (n, ctx) => {
|
|
65
|
+
if ((0, makeTransformer_2.isNamedBlock)(n.name))
|
|
66
|
+
return n;
|
|
67
|
+
return { ...n, content: transformer(n.content, { ...ctx }) };
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
return transformer(n, { ...ctx });
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
return transformerBlocks(tree, {});
|
|
74
|
+
};
|
|
75
|
+
exports.default = middle;
|
|
76
|
+
//# sourceMappingURL=plugin-formatting-codes.js.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = () => tree => {
|
|
4
|
+
const isNodesEqual = (n1, n2) =>
|
|
5
|
+
// if nodes items
|
|
6
|
+
(n1.name === 'item' || n1.name === 'defn') &&
|
|
7
|
+
n2.name === n1.name &&
|
|
8
|
+
n1['level'] === n2.level &&
|
|
9
|
+
isNumbered(n1) === isNumbered(n2);
|
|
10
|
+
const isNumbered = node => Boolean(node.config && node.config.numbered);
|
|
11
|
+
const group = a => {
|
|
12
|
+
let lastItem = {};
|
|
13
|
+
let result = a.reduce((a, i) => {
|
|
14
|
+
if (i.name === 'defn') {
|
|
15
|
+
if (isNodesEqual(lastItem, i)) {
|
|
16
|
+
// group items into arrays
|
|
17
|
+
a[a.length - 1].push(i);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
// group items into arrays
|
|
21
|
+
a.push([i]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
// save not 'item' elements as is
|
|
26
|
+
a.push(i);
|
|
27
|
+
}
|
|
28
|
+
lastItem = i;
|
|
29
|
+
return a;
|
|
30
|
+
}, []);
|
|
31
|
+
// convert grouped items into object 'itemlist'
|
|
32
|
+
/**
|
|
33
|
+
* { type = 'list',
|
|
34
|
+
* ordered = [true, false]
|
|
35
|
+
* content = [ .... ]
|
|
36
|
+
* list = ['ordered', 'variable', 'itemized']
|
|
37
|
+
*/
|
|
38
|
+
return result.map(item => {
|
|
39
|
+
if (item instanceof Array) {
|
|
40
|
+
if (item[0].name !== 'defn') {
|
|
41
|
+
return item;
|
|
42
|
+
}
|
|
43
|
+
// get type of list
|
|
44
|
+
const list = item[0].name === 'defn' ? 'variable' : isNumbered(item[0]) ? 'ordered' : 'itemized';
|
|
45
|
+
// create items container
|
|
46
|
+
return {
|
|
47
|
+
type: 'list',
|
|
48
|
+
list,
|
|
49
|
+
level: 1,
|
|
50
|
+
content: [...item],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (item.content && item.type !== 'fcode') {
|
|
54
|
+
item.content = group(item.content);
|
|
55
|
+
}
|
|
56
|
+
return item;
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
const visit = node => {
|
|
60
|
+
if (Array.isArray(node)) {
|
|
61
|
+
return group(node);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
if (node.type === 'block' && node.name !== 'table') {
|
|
65
|
+
node.content = group(node.content);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return node;
|
|
69
|
+
};
|
|
70
|
+
tree = visit(tree);
|
|
71
|
+
return tree;
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=plugin-group-defn.js.map
|