podlite 0.0.8 → 0.0.12
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 +7 -1
- package/jest.config.js +2 -30
- package/jest.tsconfig.json +1 -0
- package/lib/ids.d.ts +18 -0
- package/lib/ids.js +68 -0
- package/{built → lib}/index.d.ts +2 -2
- package/lib/index.js +102 -0
- package/lib/mdtopod6.d.ts +0 -0
- package/lib/mdtopod6.js +109 -0
- package/{built → lib}/plugins/extrnal.d.ts +0 -0
- package/{built → lib}/plugins/extrnal.js +6 -4
- package/{built → lib}/plugins/index.d.ts +2 -2
- package/{built → lib}/plugins/index.js +7 -7
- package/lib/tools.d.ts +0 -0
- package/lib/tools.js +124 -0
- package/package.json +16 -21
- package/src/ids.ts +69 -0
- package/src/index.ts +23 -16
- package/src/mdtopod6.ts +109 -109
- package/src/plugins/extrnal.ts +3 -1
- package/src/tools.ts +124 -124
- package/t/fill-fixtures.ts +4 -2
- package/t/fixtures/04-tables_table.txt +20 -10
- package/t/ids.test.ts +32 -0
- package/t/md2ast.test.ts +28 -24
- package/t/md2pod6.test.ts +25 -22
- package/t/plugin.test.ts +23 -0
- package/t/process.ts +205 -205
- package/tsconfig.json +7 -5
- package/tsconfig.tsbuildinfo +1 -1987
- package/yarn-error.log +8710 -0
- package/built/index.js +0 -109
- package/built/mdtopod6.d.ts +0 -1
- package/built/mdtopod6.js +0 -138
- package/built/tools.d.ts +0 -1
- package/built/tools.js +0 -138
package/CHANGELOG.md
CHANGED
package/jest.config.js
CHANGED
|
@@ -1,30 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* https://kulshekhar.github.io/ts-jest/user/config/
|
|
4
|
-
*/
|
|
5
|
-
module.exports = {
|
|
6
|
-
globals: {
|
|
7
|
-
'ts-jest': {
|
|
8
|
-
// ts-jest configuration goes here
|
|
9
|
-
diagnostics: {
|
|
10
|
-
// https://github.com/kulshekhar/ts-jest/issues/748
|
|
11
|
-
ignoreCodes: [151001]
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
// Aliases for imports in test files, as 'ts-jest' (and jest) don't use tsconfig.paths!
|
|
16
|
-
// https://github.com/kulshekhar/ts-jest/issues/414
|
|
17
|
-
moduleNameMapper: {
|
|
18
|
-
"^src/(.*)": "<rootDir>/src/$1",
|
|
19
|
-
"^tests/(.*)": "<rootDir>/tests/$1"
|
|
20
|
-
},
|
|
21
|
-
preset: 'ts-jest',
|
|
22
|
-
// setupFilesAfterEnv: ["<rootDir>/tests/setupTests.ts"],
|
|
23
|
-
//testEnvironment: 'node',
|
|
24
|
-
testEnvironment: 'jsdom',
|
|
25
|
-
testMatch: [
|
|
26
|
-
'<rootDir>/tests/**/?(*.)test.[jt]s?(x)',
|
|
27
|
-
"**/?(*.)+(spec|test).[jt]s?(x)"
|
|
28
|
-
],
|
|
29
|
-
verbose: true
|
|
30
|
-
};
|
|
1
|
+
|
|
2
|
+
module.exports = require('../../jest.config')
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"extends": "../../jest.tsconfig.json"}
|
package/lib/ids.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Plugin } from 'pod6/built/';
|
|
2
|
+
/**
|
|
3
|
+
* Clean ids from tree
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
export declare const cleanIds: (src?: {
|
|
7
|
+
skipChain: number;
|
|
8
|
+
podMode: number;
|
|
9
|
+
}) => (tree: any) => any;
|
|
10
|
+
/**
|
|
11
|
+
* Add set id to 'id' to each blocks
|
|
12
|
+
*/
|
|
13
|
+
export declare const frozenIds: (src?: {
|
|
14
|
+
skipChain: number;
|
|
15
|
+
podMode: number;
|
|
16
|
+
}) => (tree: any) => any;
|
|
17
|
+
declare const middleware: Plugin;
|
|
18
|
+
export default middleware;
|
package/lib/ids.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
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.frozenIds = exports.cleanIds = void 0;
|
|
7
|
+
const makeTransformer_1 = __importDefault(require("pod6/built/helpers/makeTransformer"));
|
|
8
|
+
const nanoid_1 = require("nanoid");
|
|
9
|
+
/**
|
|
10
|
+
* Clean ids from tree
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
const cleanIds = (src = { skipChain: 0, podMode: 1 }) => (tree) => {
|
|
14
|
+
const transformerBlocks = (0, makeTransformer_1.default)({
|
|
15
|
+
'*': (node, ctx, visiter) => {
|
|
16
|
+
if ('id' in node) {
|
|
17
|
+
if ('content' in node) {
|
|
18
|
+
node.content = visiter(node.content, ctx);
|
|
19
|
+
}
|
|
20
|
+
const { id, ...rest } = node;
|
|
21
|
+
return { ...rest, };
|
|
22
|
+
}
|
|
23
|
+
return node;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return transformerBlocks(tree, {});
|
|
27
|
+
};
|
|
28
|
+
exports.cleanIds = cleanIds;
|
|
29
|
+
/**
|
|
30
|
+
* Add set id to 'id' to each blocks
|
|
31
|
+
*/
|
|
32
|
+
const frozenIds = (src = { skipChain: 0, podMode: 1 }) => (tree) => {
|
|
33
|
+
const transformerBlocks = (0, makeTransformer_1.default)({
|
|
34
|
+
'*': (node, ctx, visiter) => {
|
|
35
|
+
if ('id' in node) {
|
|
36
|
+
if ('content' in node) {
|
|
37
|
+
node.content = visiter(node.content, ctx);
|
|
38
|
+
}
|
|
39
|
+
const { id, ...rest } = node;
|
|
40
|
+
return { ...rest, id: 'id' };
|
|
41
|
+
}
|
|
42
|
+
return node;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return transformerBlocks(tree, {});
|
|
46
|
+
};
|
|
47
|
+
exports.frozenIds = frozenIds;
|
|
48
|
+
const middleware = () => (tree) => {
|
|
49
|
+
const transformerBlocks = (0, makeTransformer_1.default)({
|
|
50
|
+
'*': (node, ctx, visiter) => {
|
|
51
|
+
const addIdField = (node) => {
|
|
52
|
+
if (typeof node === 'object' && 'type' in node && node.type == 'block') {
|
|
53
|
+
return { ...node, id: (0, nanoid_1.nanoid)() };
|
|
54
|
+
}
|
|
55
|
+
return node;
|
|
56
|
+
};
|
|
57
|
+
const processContent = (node) => {
|
|
58
|
+
if (typeof node === 'object' && 'content' in node) {
|
|
59
|
+
return { ...node, content: visiter(node.content, ctx) };
|
|
60
|
+
}
|
|
61
|
+
return node;
|
|
62
|
+
};
|
|
63
|
+
return processContent(addIdField(node));
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return transformerBlocks(tree, {});
|
|
67
|
+
};
|
|
68
|
+
exports.default = middleware;
|
package/{built → lib}/index.d.ts
RENAMED
package/lib/index.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
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.podlite = exports.toAnyRules = exports.frozenIds = exports.cleanIds = void 0;
|
|
7
|
+
const pod6_1 = require("pod6");
|
|
8
|
+
const exportAny_1 = __importDefault(require("pod6/built/exportAny"));
|
|
9
|
+
const schema_1 = require("@podlite/schema");
|
|
10
|
+
// export * from './mdtopod6';
|
|
11
|
+
// export * from './tools'
|
|
12
|
+
const plugins_1 = __importDefault(require("./plugins"));
|
|
13
|
+
const extrnal_1 = __importDefault(require("./plugins/extrnal"));
|
|
14
|
+
const ids_1 = __importDefault(require("./ids"));
|
|
15
|
+
const ids_2 = require("./ids");
|
|
16
|
+
Object.defineProperty(exports, "cleanIds", { enumerable: true, get: function () { return ids_2.cleanIds; } });
|
|
17
|
+
Object.defineProperty(exports, "frozenIds", { enumerable: true, get: function () { return ids_2.frozenIds; } });
|
|
18
|
+
const toAnyRules = (method, allplugins) => {
|
|
19
|
+
// make uniq plugins
|
|
20
|
+
const resultMap = allplugins.reverse().reduce((result, plugins) => {
|
|
21
|
+
for (const plugin of Object.entries(plugins)) {
|
|
22
|
+
const [key, val] = plugin;
|
|
23
|
+
if (!(key in result)) {
|
|
24
|
+
result[key] = val;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}, {});
|
|
29
|
+
let result = {};
|
|
30
|
+
// prepare plugins for export <method>
|
|
31
|
+
for (const plugin of Object.entries(resultMap)) {
|
|
32
|
+
const [key, val = {}] = plugin;
|
|
33
|
+
//@ts-ignore
|
|
34
|
+
if (method in val) {
|
|
35
|
+
result[key] = val[method];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
exports.toAnyRules = toAnyRules;
|
|
41
|
+
const podlite = ({ importPlugins = true }) => {
|
|
42
|
+
let instance = function () { };
|
|
43
|
+
let plugins = [];
|
|
44
|
+
instance.use = (onj) => {
|
|
45
|
+
for (const plugin of Object.entries(onj)) {
|
|
46
|
+
const [key, val] = plugin;
|
|
47
|
+
if (typeof val === 'function') {
|
|
48
|
+
plugins.push({ [key]: { toAst: val } });
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
plugins.push({ [key]: val });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return instance;
|
|
55
|
+
};
|
|
56
|
+
instance.parse = (text, opt) => {
|
|
57
|
+
const rawTree = (0, pod6_1.toTree)().use(ids_1.default).parse(text, opt = { skipChain: 0, podMode: 1 });
|
|
58
|
+
const root = (0, schema_1.mkRootBlock)({ margin: "" }, rawTree);
|
|
59
|
+
return root;
|
|
60
|
+
};
|
|
61
|
+
instance.toAst = (ast) => {
|
|
62
|
+
return instance.toAstResult(ast).interator;
|
|
63
|
+
};
|
|
64
|
+
instance.toAstResult = (ast) => {
|
|
65
|
+
// get plugins for Ast
|
|
66
|
+
const toAstPlugins = (0, exports.toAnyRules)('toAst', instance.getPlugins());
|
|
67
|
+
const result = (0, exportAny_1.default)().use({
|
|
68
|
+
'*': () => (node, ctx, interator) => {
|
|
69
|
+
if ('content' in node) {
|
|
70
|
+
node.content = interator(node.content, ctx);
|
|
71
|
+
}
|
|
72
|
+
return node;
|
|
73
|
+
}
|
|
74
|
+
}).use(toAstPlugins).run(ast);
|
|
75
|
+
// add second pass
|
|
76
|
+
const toAstAfterPlugins = (0, exports.toAnyRules)('toAstAfter', instance.getPlugins());
|
|
77
|
+
if (Object.keys(toAstAfterPlugins).length) {
|
|
78
|
+
const resultAfter = (0, exportAny_1.default)().use({
|
|
79
|
+
'*': () => (node, ctx, interator) => {
|
|
80
|
+
if ('content' in node) {
|
|
81
|
+
node.content = interator(node.content, ctx);
|
|
82
|
+
}
|
|
83
|
+
return node;
|
|
84
|
+
}
|
|
85
|
+
}).use(toAstAfterPlugins).run(ast);
|
|
86
|
+
return resultAfter;
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
};
|
|
90
|
+
instance.toHtml = (ast) => {
|
|
91
|
+
const toHtmlPlugins = (0, exports.toAnyRules)('toHtml', instance.getPlugins());
|
|
92
|
+
return (0, pod6_1.toHtml)({}).use(toHtmlPlugins).run(ast, null);
|
|
93
|
+
};
|
|
94
|
+
instance.getPlugins = () => plugins;
|
|
95
|
+
// init core plugins
|
|
96
|
+
instance.use(plugins_1.default);
|
|
97
|
+
if (importPlugins) {
|
|
98
|
+
instance.use(extrnal_1.default);
|
|
99
|
+
}
|
|
100
|
+
return instance;
|
|
101
|
+
};
|
|
102
|
+
exports.podlite = podlite;
|
|
File without changes
|
package/lib/mdtopod6.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// import unified from 'unified'
|
|
2
|
+
// import markdown from 'remark-parse'
|
|
3
|
+
// import toAny from 'pod6/built/exportAny'
|
|
4
|
+
// export const mdToPod6 = (src, extraRules? ) => {
|
|
5
|
+
// const md_tree = unified().use(markdown).parse(src)
|
|
6
|
+
// let definitionMap = {}
|
|
7
|
+
// toAny({processor:1})
|
|
8
|
+
// .use({'*:*':( writer, processor )=>( node, ctx, interator )=>{
|
|
9
|
+
// if (node.children) interator(node.children, { ...ctx})
|
|
10
|
+
// }})
|
|
11
|
+
// .use({':definition' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
12
|
+
// definitionMap[node.identifier] = node
|
|
13
|
+
// }}).run(md_tree)
|
|
14
|
+
// const res = toAny({processor:1})
|
|
15
|
+
// .use({'*:*':( writer, processor )=>( node, ctx, interator )=>{
|
|
16
|
+
// console.warn(node)
|
|
17
|
+
// if (node.children) interator(node.children, { ...ctx})
|
|
18
|
+
// }})
|
|
19
|
+
// .use({
|
|
20
|
+
// ':root': ( writer, processor )=>( node, ctx, interator )=>{
|
|
21
|
+
// // handle text with content
|
|
22
|
+
// const { children, position, ...attr} = node
|
|
23
|
+
// writer.write( "=begin pod\n")
|
|
24
|
+
// interator( children, ctx )
|
|
25
|
+
// writer.write( "=end pod\n")
|
|
26
|
+
// },
|
|
27
|
+
// ':heading' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
28
|
+
// const { children, position, ...attr} = node
|
|
29
|
+
// writer.write( `=head${node.depth} `)
|
|
30
|
+
// if (children) interator( children, ctx )
|
|
31
|
+
// writer.write( "\n")
|
|
32
|
+
// },
|
|
33
|
+
// ':text' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
34
|
+
// const { children, position, ...attr} = node
|
|
35
|
+
// writer.writeRaw(node.value)
|
|
36
|
+
// if (children) interator( children, ctx )
|
|
37
|
+
// },
|
|
38
|
+
// ':list' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
39
|
+
// // console.error(node)
|
|
40
|
+
// const savedListLevel = ctx['listLevel'] || 0
|
|
41
|
+
// const newctx = { ...ctx, listLevel:savedListLevel+1, ordered: node.ordered ? 'ordered' : 'itemized'}
|
|
42
|
+
// const { children, position, ...attr} = node
|
|
43
|
+
// if (children) interator( children, newctx )
|
|
44
|
+
// },
|
|
45
|
+
// ':listItem' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
46
|
+
// const { children, position, ...attr} = node
|
|
47
|
+
// // console.error(node)
|
|
48
|
+
// writer.write(`=begin item${ctx['listLevel']} ${ctx.ordered ? ":numbered" : ''} \n`)
|
|
49
|
+
// if (children) { interator( children, ctx ) }
|
|
50
|
+
// writer.write(`=end item${ctx['listLevel']}\n`)
|
|
51
|
+
// },
|
|
52
|
+
// ':paragraph' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
53
|
+
// const { children, position, ...attr} = node
|
|
54
|
+
// writer.write(`=begin para\n`)
|
|
55
|
+
// if (children) { interator( children, ctx ) }
|
|
56
|
+
// writer.write(`\n=end para\n`)
|
|
57
|
+
// },
|
|
58
|
+
// ':linkReference' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
59
|
+
// // console.log(log(node))
|
|
60
|
+
// const { children, position, ...attr} = node
|
|
61
|
+
// const definition = definitionMap[attr.identifier]
|
|
62
|
+
// const meta = definition?.url || ''
|
|
63
|
+
// writer.write(`L<`)
|
|
64
|
+
// if (children) { interator( children, ctx ) }
|
|
65
|
+
// writer.write(`|${meta}>`)
|
|
66
|
+
// },
|
|
67
|
+
// ':definition' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
68
|
+
// return null
|
|
69
|
+
// },
|
|
70
|
+
// ':inlineCode' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
71
|
+
// const { children, position, ...attr} = node
|
|
72
|
+
// writer.write(`C<${node.value}>`)
|
|
73
|
+
// },
|
|
74
|
+
// ':strong' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
75
|
+
// const { children, position, ...attr} = node
|
|
76
|
+
// writer.write(`B<`)
|
|
77
|
+
// if (children) { interator( children, ctx ) }
|
|
78
|
+
// writer.write(`>`)
|
|
79
|
+
// },
|
|
80
|
+
// ':link': ( writer, processor )=>( node, ctx, interator )=>{
|
|
81
|
+
// const { children, position, ...attr} = node
|
|
82
|
+
// writer.write(`L<`)
|
|
83
|
+
// if (children) { interator( children, ctx ) }
|
|
84
|
+
// writer.write(`|${node.url}>`)
|
|
85
|
+
// },
|
|
86
|
+
// ':image': ( writer, processor )=>( node, ctx, interator )=>{
|
|
87
|
+
// const { children, position, ...attr} = node
|
|
88
|
+
// writer.write(`=begin Image :title('${node.title}') :alt('${node.alt}')\n`)
|
|
89
|
+
// writer.write(node.url)
|
|
90
|
+
// writer.write(`\n=end Image\n`)
|
|
91
|
+
// },
|
|
92
|
+
// ':html': ( writer, processor )=>( node, ctx, interator )=>{
|
|
93
|
+
// const { children, position, ...attr} = node
|
|
94
|
+
// writer.write(`=begin Html\n`)
|
|
95
|
+
// writer.write(`${node.value}`)
|
|
96
|
+
// writer.write(`\n=end Html\n`)
|
|
97
|
+
// },
|
|
98
|
+
// ':code' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
99
|
+
// // console.log(JSON.stringify(node,null,2))
|
|
100
|
+
// const { children, position, lang, ...attr} = node
|
|
101
|
+
// writer.write(`=begin code ${lang ? ':lang(\''+lang+'\')' : ""}\n`)
|
|
102
|
+
// writer.write(`${node.value}`)
|
|
103
|
+
// writer.write(`\n=end code\n`)
|
|
104
|
+
// },
|
|
105
|
+
// ...extraRules
|
|
106
|
+
// },
|
|
107
|
+
// ).run(md_tree)
|
|
108
|
+
// return res.toString()
|
|
109
|
+
// }
|
|
File without changes
|
|
@@ -3,10 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const image_1 = __importDefault(require("@podlite/image"));
|
|
7
|
+
const diagram_1 = require("@podlite/diagram");
|
|
8
|
+
const toc_1 = __importDefault(require("@podlite/toc"));
|
|
9
|
+
const external = {
|
|
9
10
|
"Image": image_1.default,
|
|
10
|
-
Diagram: diagram_1.plugin
|
|
11
|
+
Diagram: diagram_1.plugin,
|
|
12
|
+
Toc: toc_1.default
|
|
11
13
|
};
|
|
12
14
|
exports.default = external;
|
|
@@ -3,10 +3,10 @@ export declare const core: {
|
|
|
3
3
|
toHtml: (writer: any) => (node: any) => void;
|
|
4
4
|
};
|
|
5
5
|
image: {
|
|
6
|
-
toHtml: any
|
|
6
|
+
toHtml: import("pod6/built/helpers/makeQuery").RuleHandler<any>;
|
|
7
7
|
};
|
|
8
8
|
root: {
|
|
9
|
-
toHtml: any
|
|
9
|
+
toHtml: import("pod6/built/helpers/makeQuery").RuleHandler<any>;
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
export default core;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.core = void 0;
|
|
4
|
-
|
|
4
|
+
const handlers_1 = require("pod6/built/helpers/handlers");
|
|
5
5
|
exports.core = {
|
|
6
6
|
':image': {
|
|
7
|
-
toHtml:
|
|
7
|
+
toHtml: (writer) => (node) => {
|
|
8
8
|
if (typeof node !== "string" && 'type' in node && node.type === 'image') {
|
|
9
|
-
writer.writeRaw(
|
|
10
|
-
writer.writeRaw(
|
|
9
|
+
writer.writeRaw(`<img`);
|
|
10
|
+
writer.writeRaw(` src="${node.src}"`);
|
|
11
11
|
if (node.alt) {
|
|
12
|
-
writer.writeRaw(
|
|
12
|
+
writer.writeRaw(` alt="${node.alt}"`);
|
|
13
13
|
}
|
|
14
|
-
writer.writeRaw(
|
|
14
|
+
writer.writeRaw(`/>`);
|
|
15
15
|
}
|
|
16
|
-
}
|
|
16
|
+
}
|
|
17
17
|
},
|
|
18
18
|
'image': {
|
|
19
19
|
toHtml: handlers_1.content
|
package/lib/tools.d.ts
ADDED
|
File without changes
|
package/lib/tools.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// import unified from 'unified'
|
|
2
|
+
// import markdown from 'remark-parse'
|
|
3
|
+
// import toAny from 'pod6/built/exportAny'
|
|
4
|
+
// import { AstTree, BlockImage, Location, mkBlock, mkFomattingCode, mkFomattingCodeL, mkVerbatim } from '@podlite/schema'
|
|
5
|
+
// export const md2ast = ( src, extraRules? ) :AstTree => {
|
|
6
|
+
// // first convert mardown to ast
|
|
7
|
+
// const md_tree = unified().use(markdown).parse(src)
|
|
8
|
+
// // first pass : collect linkRefs
|
|
9
|
+
// let definitionMap = {}
|
|
10
|
+
// toAny({processor:1})
|
|
11
|
+
// .use({'*:*':( writer, processor )=>( node, ctx, interator )=>{
|
|
12
|
+
// if (node.children) interator(node.children, { ...ctx})
|
|
13
|
+
// }})
|
|
14
|
+
// .use({':definition' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
15
|
+
// definitionMap[node.identifier] = node
|
|
16
|
+
// }}).run(md_tree)
|
|
17
|
+
// // second stage - make Universal AST nodes
|
|
18
|
+
// const uast = []
|
|
19
|
+
// const res = toAny({processor:1})
|
|
20
|
+
// .use({'*:*':( writer, processor )=>( node, ctx, interator )=>{
|
|
21
|
+
// console.warn('[Podlite]')
|
|
22
|
+
// console.warn(JSON.stringify(node,null,2))
|
|
23
|
+
// if (node.children) interator(node.children, { ...ctx})
|
|
24
|
+
// }})
|
|
25
|
+
// .use({
|
|
26
|
+
// ':root' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
27
|
+
// const { children, position, ...attr} = node
|
|
28
|
+
// return mkBlock({name:"pod", location:position}, interator(children, ctx))
|
|
29
|
+
// },
|
|
30
|
+
// ':heading' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
31
|
+
// const { children, position, ...attr} = node
|
|
32
|
+
// return mkBlock({type:'block', level:node.depth,name:'head', location:position}, interator(children, ctx));
|
|
33
|
+
// },
|
|
34
|
+
// ':text' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
35
|
+
// const { children, position, ...attr} = node
|
|
36
|
+
// return node.value
|
|
37
|
+
// // return mkNode({type:"text", value: node.value})
|
|
38
|
+
// },
|
|
39
|
+
// ':list' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
40
|
+
// const savedListLevel = ctx['listLevel'] || 0
|
|
41
|
+
// const { children, position, ...attr} = node
|
|
42
|
+
// return mkBlock( { type:'list', level:savedListLevel+1, list: node.ordered ? 'ordered' : 'itemized' }, interator(children, { ...ctx, listLevel : savedListLevel + 1, ordered: node.ordered}))
|
|
43
|
+
// },
|
|
44
|
+
// ':listItem' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
45
|
+
// const savedListLevel = ctx['listLevel'] || 0
|
|
46
|
+
// const { children, position, ...attr} = node
|
|
47
|
+
// return mkBlock({name: 'item', type:'block', level:ctx['listLevel'], location:position}, interator(children, { ...ctx, listLevel : savedListLevel , ordered: node.ordered}))
|
|
48
|
+
// },
|
|
49
|
+
// ':paragraph' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
50
|
+
// const { children, position, ...attr} = node
|
|
51
|
+
// return mkBlock({type:'para', location:position}, interator(children, { ...ctx}))
|
|
52
|
+
// },
|
|
53
|
+
// ':linkReference' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
54
|
+
// const { children, position, ...attr} = node
|
|
55
|
+
// const definition = definitionMap[attr.identifier]
|
|
56
|
+
// const meta = definition?.url || ''
|
|
57
|
+
// return mkFomattingCodeL({ meta}, interator(children, { ...ctx}))
|
|
58
|
+
// },
|
|
59
|
+
// ':definition' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
60
|
+
// return null
|
|
61
|
+
// },
|
|
62
|
+
// ':inlineCode' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
63
|
+
// const { children, position, ...attr} = node
|
|
64
|
+
// return mkFomattingCode({name:"C", location:position}, [node.value])
|
|
65
|
+
// },
|
|
66
|
+
// ':strong' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
67
|
+
// const { children, position, ...attr} = node
|
|
68
|
+
// return mkFomattingCode({name:"B", location:position}, interator(children, { ...ctx}))
|
|
69
|
+
// },
|
|
70
|
+
// ':emphasis' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
71
|
+
// const { children, position, ...attr} = node
|
|
72
|
+
// return mkFomattingCode({name:"I", location:position}, interator(children, { ...ctx}))
|
|
73
|
+
// },
|
|
74
|
+
// ':link': ( writer, processor )=>( node, ctx, interator )=>{
|
|
75
|
+
// const { children, position, ...attr} = node
|
|
76
|
+
// return mkFomattingCodeL({ meta:node.url,location:position}, interator(children, { ...ctx}))
|
|
77
|
+
// },
|
|
78
|
+
// ':html': ( writer, processor )=>( node, ctx, interator )=>{
|
|
79
|
+
// const { children, position, ...attr} = node
|
|
80
|
+
// return mkBlock({type:'block', name:'Html', location:position},[mkVerbatim(node.value)]);
|
|
81
|
+
// },
|
|
82
|
+
// ':code' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
83
|
+
// const { children, position, lang, ...attr} = node
|
|
84
|
+
// let config = {}
|
|
85
|
+
// if (lang) { config = { name: 'lang', value:"lang"}}
|
|
86
|
+
// return mkBlock({type:'block', name:'code', config, location:position},[mkVerbatim(node.value)]);
|
|
87
|
+
// },
|
|
88
|
+
// ':image': ( writer, processor )=>( node, ctx, interator )=>{
|
|
89
|
+
// const { title, alt, url, position, ...attr} = node
|
|
90
|
+
// let config = []
|
|
91
|
+
// if (!!title) { config.push({ name: 'title', value:title}) }
|
|
92
|
+
// if (!!alt) { config.push({ name: 'alt', value:alt}) }
|
|
93
|
+
// return mkBlock({type:'block', name:'Image', config, location:position},[mkVerbatim(url)]);
|
|
94
|
+
// },
|
|
95
|
+
// ':thematicBreak': ( writer, processor )=>( node, ctx, interator )=>{
|
|
96
|
+
// return null
|
|
97
|
+
// },
|
|
98
|
+
// ':blockquote' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
99
|
+
// const { children, position, ...attr} = node
|
|
100
|
+
// return mkBlock({type:'nested'}, interator(children, { ...ctx}))
|
|
101
|
+
// },
|
|
102
|
+
// //table section
|
|
103
|
+
// ':table' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
104
|
+
// const { children, position, ...attr} = node
|
|
105
|
+
// return mkBlock({name:'table', location:position}, interator(children, { ...ctx}))
|
|
106
|
+
// },
|
|
107
|
+
// ':tableRow' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
108
|
+
// const { children, position, ...attr} = node
|
|
109
|
+
// return mkBlock({name:'table_row', location:position}, interator(children, { ...ctx}))
|
|
110
|
+
// },
|
|
111
|
+
// ':tableCell' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
112
|
+
// const { children, position, ...attr} = node
|
|
113
|
+
// return mkBlock({name:'table_cell', location:position}, interator(children, { ...ctx}))
|
|
114
|
+
// },
|
|
115
|
+
// ':delete': ( writer, processor )=>( node, ctx, interator )=>{
|
|
116
|
+
// return null
|
|
117
|
+
// },
|
|
118
|
+
// ':break': ( writer, processor )=>( node, ctx, interator )=>{
|
|
119
|
+
// return null
|
|
120
|
+
// },
|
|
121
|
+
// ...extraRules
|
|
122
|
+
// }).run(md_tree)
|
|
123
|
+
// return res.interator
|
|
124
|
+
// }
|
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "podlite",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "Adaptation of pod6 markup language",
|
|
5
5
|
"main": "index.js",
|
|
6
|
-
"types": "./
|
|
6
|
+
"types": "./lib/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"build": "run-s build:ts",
|
|
11
|
-
"build:ts": "tsc",
|
|
8
|
+
"test": "yarn g:jest --passWithNoTests",
|
|
9
|
+
"build": "tsc",
|
|
12
10
|
"watch": "run-p -r watch:*",
|
|
13
11
|
"watch:ts": "tsc -w --pretty",
|
|
14
12
|
"watch:tests": "jest --watch -t \"test\""
|
|
@@ -21,27 +19,24 @@
|
|
|
21
19
|
"author": "Alexandr Zahatski",
|
|
22
20
|
"license": "MIT",
|
|
23
21
|
"dependencies": {
|
|
24
|
-
"@podlite/diagram": "^0.0.
|
|
25
|
-
"@podlite/image": "^0.0.
|
|
26
|
-
"@podlite/schema": "^0.0.
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
22
|
+
"@podlite/diagram": "^0.0.8",
|
|
23
|
+
"@podlite/image": "^0.0.8",
|
|
24
|
+
"@podlite/schema": "^0.0.7",
|
|
25
|
+
"@podlite/toc": "0.0.1",
|
|
26
|
+
"nanoid": "^3.1.30",
|
|
27
|
+
"pod6": "0.0.43"
|
|
30
28
|
},
|
|
31
29
|
"devDependencies": {
|
|
32
|
-
"@podlite/schema": "*",
|
|
33
30
|
"@types/jest": "^26.0.21",
|
|
34
31
|
"@types/node": "^14.11.2",
|
|
35
|
-
"jest": "^26.5.2",
|
|
36
32
|
"npm-run-all": "^4.1.5",
|
|
37
|
-
"
|
|
38
|
-
"typescript": "4.2.3"
|
|
33
|
+
"typescript": "4.5.4"
|
|
39
34
|
},
|
|
40
35
|
"peerDependencies": {
|
|
41
|
-
"@podlite/diagram": "*",
|
|
42
|
-
"@podlite/image": "*",
|
|
43
|
-
"@podlite/schema": "*",
|
|
44
36
|
"pod6": "*"
|
|
45
37
|
},
|
|
46
|
-
"
|
|
47
|
-
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"main": "index.js"
|
|
41
|
+
}
|
|
42
|
+
}
|