podlite 0.0.9 → 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/built/index.js DELETED
@@ -1,109 +0,0 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- var __importDefault = (this && this.__importDefault) || function (mod) {
13
- return (mod && mod.__esModule) ? mod : { "default": mod };
14
- };
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.podlite = exports.toAnyRules = void 0;
17
- var pod6_1 = require("pod6");
18
- var exportAny_1 = __importDefault(require("pod6/built/exportAny"));
19
- var schema_1 = require("@podlite/schema");
20
- __exportStar(require("./mdtopod6"), exports);
21
- __exportStar(require("./tools"), exports);
22
- var plugins_1 = __importDefault(require("./plugins"));
23
- var extrnal_1 = __importDefault(require("./plugins/extrnal"));
24
- var toAnyRules = function (method, allplugins) {
25
- // make uniq plugins
26
- var resultMap = allplugins.reverse().reduce(function (result, plugins) {
27
- for (var _i = 0, _a = Object.entries(plugins); _i < _a.length; _i++) {
28
- var plugin = _a[_i];
29
- var key = plugin[0], val = plugin[1];
30
- if (!(key in result)) {
31
- result[key] = val;
32
- }
33
- }
34
- return result;
35
- }, {});
36
- var result = {};
37
- // prepare plugins for export <method>
38
- for (var _i = 0, _a = Object.entries(resultMap); _i < _a.length; _i++) {
39
- var plugin = _a[_i];
40
- var key = plugin[0], val = plugin[1];
41
- if (method in val) {
42
- result[key] = val[method];
43
- }
44
- }
45
- return result;
46
- };
47
- exports.toAnyRules = toAnyRules;
48
- var podlite = function (_a) {
49
- var _b = _a.importPlugins, importPlugins = _b === void 0 ? true : _b;
50
- var instance = function () { };
51
- var plugins = [];
52
- instance.use = function (onj) {
53
- var _a, _b;
54
- for (var _i = 0, _c = Object.entries(onj); _i < _c.length; _i++) {
55
- var plugin = _c[_i];
56
- var key = plugin[0], val = plugin[1];
57
- if (typeof val === 'function') {
58
- plugins.push((_a = {}, _a[key] = { toAst: val }, _a));
59
- }
60
- else {
61
- plugins.push((_b = {}, _b[key] = val, _b));
62
- }
63
- }
64
- return instance;
65
- };
66
- instance.parse = function (text, opt) {
67
- var rawTree = pod6_1.toTree().parse(text, opt = { skipChain: 0, podMode: 1 });
68
- var root = schema_1.mkRootBlock({ margin: "" }, rawTree);
69
- return root;
70
- };
71
- instance.toAst = function (ast) {
72
- // get plugins for Ast
73
- var toAstPlugins = exports.toAnyRules('toAst', instance.getPlugins());
74
- var result = exportAny_1.default().use({
75
- '*': function () { return function (node, ctx, interator) {
76
- if ('content' in node) {
77
- node.content = interator(node.content, ctx);
78
- }
79
- return node;
80
- }; }
81
- }).use(toAstPlugins).run(ast);
82
- return result.interator;
83
- };
84
- instance.toAstResult = function (ast) {
85
- // get plugins for Ast
86
- var toAstPlugins = exports.toAnyRules('toAst', instance.getPlugins());
87
- var result = exportAny_1.default().use({
88
- '*': function () { return function (node, ctx, interator) {
89
- if ('content' in node) {
90
- node.content = interator(node.content, ctx);
91
- }
92
- return node;
93
- }; }
94
- }).use(toAstPlugins).run(ast);
95
- return result;
96
- };
97
- instance.toHtml = function (ast) {
98
- var toHtmlPlugins = exports.toAnyRules('toHtml', instance.getPlugins());
99
- return pod6_1.toHtml({}).use(toHtmlPlugins).run(ast, null);
100
- };
101
- instance.getPlugins = function () { return plugins; };
102
- // init core plugins
103
- instance.use(plugins_1.default);
104
- if (importPlugins) {
105
- instance.use(extrnal_1.default);
106
- }
107
- return instance;
108
- };
109
- exports.podlite = podlite;
@@ -1 +0,0 @@
1
- export declare const mdToPod6: (src: any, extraRules?: any) => any;
package/built/mdtopod6.js DELETED
@@ -1,138 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __rest = (this && this.__rest) || function (s, e) {
14
- var t = {};
15
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
- t[p] = s[p];
17
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
- t[p[i]] = s[p[i]];
21
- }
22
- return t;
23
- };
24
- var __importDefault = (this && this.__importDefault) || function (mod) {
25
- return (mod && mod.__esModule) ? mod : { "default": mod };
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.mdToPod6 = void 0;
29
- var unified_1 = __importDefault(require("unified"));
30
- var remark_parse_1 = __importDefault(require("remark-parse"));
31
- var exportAny_1 = __importDefault(require("pod6/built/exportAny"));
32
- var mdToPod6 = function (src, extraRules) {
33
- var md_tree = unified_1.default().use(remark_parse_1.default).parse(src);
34
- var definitionMap = {};
35
- exportAny_1.default({ processor: 1 })
36
- .use({ '*:*': function (writer, processor) { return function (node, ctx, interator) {
37
- if (node.children)
38
- interator(node.children, __assign({}, ctx));
39
- }; } })
40
- .use({ ':definition': function (writer, processor) { return function (node, ctx, interator) {
41
- definitionMap[node.identifier] = node;
42
- }; } }).run(md_tree);
43
- var res = exportAny_1.default({ processor: 1 })
44
- .use({ '*:*': function (writer, processor) { return function (node, ctx, interator) {
45
- console.warn(node);
46
- if (node.children)
47
- interator(node.children, __assign({}, ctx));
48
- }; } })
49
- .use(__assign({ ':root': function (writer, processor) { return function (node, ctx, interator) {
50
- // handle text with content
51
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
52
- writer.write("=begin pod\n");
53
- interator(children, ctx);
54
- writer.write("=end pod\n");
55
- }; }, ':heading': function (writer, processor) { return function (node, ctx, interator) {
56
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
57
- writer.write("=head" + node.depth + " ");
58
- if (children)
59
- interator(children, ctx);
60
- writer.write("\n");
61
- }; }, ':text': function (writer, processor) { return function (node, ctx, interator) {
62
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
63
- writer.writeRaw(node.value);
64
- if (children)
65
- interator(children, ctx);
66
- }; }, ':list': function (writer, processor) { return function (node, ctx, interator) {
67
- // console.error(node)
68
- var savedListLevel = ctx['listLevel'] || 0;
69
- var newctx = __assign(__assign({}, ctx), { listLevel: savedListLevel + 1, ordered: node.ordered ? 'ordered' : 'itemized' });
70
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
71
- if (children)
72
- interator(children, newctx);
73
- }; }, ':listItem': function (writer, processor) { return function (node, ctx, interator) {
74
- var children = node.children, position = node.position, attr = __rest(node
75
- // console.error(node)
76
- , ["children", "position"]);
77
- // console.error(node)
78
- writer.write("=begin item" + ctx['listLevel'] + " " + (ctx.ordered ? ":numbered" : '') + " \n");
79
- if (children) {
80
- interator(children, ctx);
81
- }
82
- writer.write("=end item" + ctx['listLevel'] + "\n");
83
- }; }, ':paragraph': function (writer, processor) { return function (node, ctx, interator) {
84
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
85
- writer.write("=begin para\n");
86
- if (children) {
87
- interator(children, ctx);
88
- }
89
- writer.write("\n=end para\n");
90
- }; }, ':linkReference': function (writer, processor) { return function (node, ctx, interator) {
91
- // console.log(log(node))
92
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
93
- var definition = definitionMap[attr.identifier];
94
- var meta = (definition === null || definition === void 0 ? void 0 : definition.url) || '';
95
- writer.write("L<");
96
- if (children) {
97
- interator(children, ctx);
98
- }
99
- writer.write("|" + meta + ">");
100
- }; }, ':definition': function (writer, processor) { return function (node, ctx, interator) {
101
- return null;
102
- }; }, ':inlineCode': function (writer, processor) { return function (node, ctx, interator) {
103
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
104
- writer.write("C<" + node.value + ">");
105
- }; }, ':strong': function (writer, processor) { return function (node, ctx, interator) {
106
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
107
- writer.write("B<");
108
- if (children) {
109
- interator(children, ctx);
110
- }
111
- writer.write(">");
112
- }; }, ':link': function (writer, processor) { return function (node, ctx, interator) {
113
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
114
- writer.write("L<");
115
- if (children) {
116
- interator(children, ctx);
117
- }
118
- writer.write("|" + node.url + ">");
119
- }; }, ':image': function (writer, processor) { return function (node, ctx, interator) {
120
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
121
- writer.write("=begin Image :title('" + node.title + "') :alt('" + node.alt + "')\n");
122
- writer.write(node.url);
123
- writer.write("\n=end Image\n");
124
- }; }, ':html': function (writer, processor) { return function (node, ctx, interator) {
125
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
126
- writer.write("=begin Html\n");
127
- writer.write("" + node.value);
128
- writer.write("\n=end Html\n");
129
- }; }, ':code': function (writer, processor) { return function (node, ctx, interator) {
130
- // console.log(JSON.stringify(node,null,2))
131
- var children = node.children, position = node.position, lang = node.lang, attr = __rest(node, ["children", "position", "lang"]);
132
- writer.write("=begin code " + (lang ? ':lang(\'' + lang + '\')' : "") + "\n");
133
- writer.write("" + node.value);
134
- writer.write("\n=end code\n");
135
- }; } }, extraRules)).run(md_tree);
136
- return res.toString();
137
- };
138
- exports.mdToPod6 = mdToPod6;
package/built/tools.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { AstTree } from '@podlite/schema';
2
- export declare const md2ast: (src: any, extraRules?: any) => AstTree;
package/built/tools.js DELETED
@@ -1,138 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __rest = (this && this.__rest) || function (s, e) {
14
- var t = {};
15
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
- t[p] = s[p];
17
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
- t[p[i]] = s[p[i]];
21
- }
22
- return t;
23
- };
24
- var __importDefault = (this && this.__importDefault) || function (mod) {
25
- return (mod && mod.__esModule) ? mod : { "default": mod };
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.md2ast = void 0;
29
- var unified_1 = __importDefault(require("unified"));
30
- var remark_parse_1 = __importDefault(require("remark-parse"));
31
- var exportAny_1 = __importDefault(require("pod6/built/exportAny"));
32
- var schema_1 = require("@podlite/schema");
33
- var md2ast = function (src, extraRules) {
34
- // first convert mardown to ast
35
- var md_tree = unified_1.default().use(remark_parse_1.default).parse(src);
36
- // first pass : collect linkRefs
37
- var definitionMap = {};
38
- exportAny_1.default({ processor: 1 })
39
- .use({ '*:*': function (writer, processor) { return function (node, ctx, interator) {
40
- if (node.children)
41
- interator(node.children, __assign({}, ctx));
42
- }; } })
43
- .use({ ':definition': function (writer, processor) { return function (node, ctx, interator) {
44
- definitionMap[node.identifier] = node;
45
- }; } }).run(md_tree);
46
- // second stage - make Universal AST nodes
47
- var uast = [];
48
- var res = exportAny_1.default({ processor: 1 })
49
- .use({ '*:*': function (writer, processor) { return function (node, ctx, interator) {
50
- console.warn('[Podlite]');
51
- console.warn(JSON.stringify(node, null, 2));
52
- if (node.children)
53
- interator(node.children, __assign({}, ctx));
54
- }; } })
55
- .use(__assign({ ':root': function (writer, processor) { return function (node, ctx, interator) {
56
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
57
- return schema_1.mkBlock({ name: "pod", location: position }, interator(children, ctx));
58
- }; }, ':heading': function (writer, processor) { return function (node, ctx, interator) {
59
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
60
- return schema_1.mkBlock({ type: 'block', level: node.depth, name: 'head', location: position }, interator(children, ctx));
61
- }; }, ':text': function (writer, processor) { return function (node, ctx, interator) {
62
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
63
- return node.value;
64
- // return mkNode({type:"text", value: node.value})
65
- }; }, ':list': function (writer, processor) { return function (node, ctx, interator) {
66
- var savedListLevel = ctx['listLevel'] || 0;
67
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
68
- return schema_1.mkBlock({ type: 'list', level: savedListLevel + 1, list: node.ordered ? 'ordered' : 'itemized' }, interator(children, __assign(__assign({}, ctx), { listLevel: savedListLevel + 1, ordered: node.ordered })));
69
- }; }, ':listItem': function (writer, processor) { return function (node, ctx, interator) {
70
- var savedListLevel = ctx['listLevel'] || 0;
71
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
72
- return schema_1.mkBlock({ name: 'item', type: 'block', level: ctx['listLevel'], location: position }, interator(children, __assign(__assign({}, ctx), { listLevel: savedListLevel, ordered: node.ordered })));
73
- }; }, ':paragraph': function (writer, processor) { return function (node, ctx, interator) {
74
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
75
- return schema_1.mkBlock({ type: 'para', location: position }, interator(children, __assign({}, ctx)));
76
- }; }, ':linkReference': function (writer, processor) { return function (node, ctx, interator) {
77
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
78
- var definition = definitionMap[attr.identifier];
79
- var meta = (definition === null || definition === void 0 ? void 0 : definition.url) || '';
80
- return schema_1.mkFomattingCodeL({ meta: meta }, interator(children, __assign({}, ctx)));
81
- }; }, ':definition': function (writer, processor) { return function (node, ctx, interator) {
82
- return null;
83
- }; }, ':inlineCode': function (writer, processor) { return function (node, ctx, interator) {
84
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
85
- return schema_1.mkFomattingCode({ name: "C", location: position }, [node.value]);
86
- }; }, ':strong': function (writer, processor) { return function (node, ctx, interator) {
87
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
88
- return schema_1.mkFomattingCode({ name: "B", location: position }, interator(children, __assign({}, ctx)));
89
- }; }, ':emphasis': function (writer, processor) { return function (node, ctx, interator) {
90
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
91
- return schema_1.mkFomattingCode({ name: "I", location: position }, interator(children, __assign({}, ctx)));
92
- }; }, ':link': function (writer, processor) { return function (node, ctx, interator) {
93
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
94
- return schema_1.mkFomattingCodeL({ meta: node.url, location: position }, interator(children, __assign({}, ctx)));
95
- }; }, ':html': function (writer, processor) { return function (node, ctx, interator) {
96
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
97
- return schema_1.mkBlock({ type: 'block', name: 'Html', location: position }, [schema_1.mkVerbatim(node.value)]);
98
- }; }, ':code': function (writer, processor) { return function (node, ctx, interator) {
99
- var children = node.children, position = node.position, lang = node.lang, attr = __rest(node, ["children", "position", "lang"]);
100
- var config = {};
101
- if (lang) {
102
- config = { name: 'lang', value: "lang" };
103
- }
104
- return schema_1.mkBlock({ type: 'block', name: 'code', config: config, location: position }, [schema_1.mkVerbatim(node.value)]);
105
- }; }, ':image': function (writer, processor) { return function (node, ctx, interator) {
106
- var title = node.title, alt = node.alt, url = node.url, position = node.position, attr = __rest(node, ["title", "alt", "url", "position"]);
107
- var config = [];
108
- if (!!title) {
109
- config.push({ name: 'title', value: title });
110
- }
111
- if (!!alt) {
112
- config.push({ name: 'alt', value: alt });
113
- }
114
- return schema_1.mkBlock({ type: 'block', name: 'Image', config: config, location: position }, [schema_1.mkVerbatim(url)]);
115
- }; }, ':thematicBreak': function (writer, processor) { return function (node, ctx, interator) {
116
- return null;
117
- }; }, ':blockquote': function (writer, processor) { return function (node, ctx, interator) {
118
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
119
- return schema_1.mkBlock({ type: 'nested' }, interator(children, __assign({}, ctx)));
120
- }; },
121
- //table section
122
- ':table': function (writer, processor) { return function (node, ctx, interator) {
123
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
124
- return schema_1.mkBlock({ name: 'table', location: position }, interator(children, __assign({}, ctx)));
125
- }; }, ':tableRow': function (writer, processor) { return function (node, ctx, interator) {
126
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
127
- return schema_1.mkBlock({ name: 'table_row', location: position }, interator(children, __assign({}, ctx)));
128
- }; }, ':tableCell': function (writer, processor) { return function (node, ctx, interator) {
129
- var children = node.children, position = node.position, attr = __rest(node, ["children", "position"]);
130
- return schema_1.mkBlock({ name: 'table_cell', location: position }, interator(children, __assign({}, ctx)));
131
- }; }, ':delete': function (writer, processor) { return function (node, ctx, interator) {
132
- return null;
133
- }; }, ':break': function (writer, processor) { return function (node, ctx, interator) {
134
- return null;
135
- }; } }, extraRules)).run(md_tree);
136
- return res.interator;
137
- };
138
- exports.md2ast = md2ast;