podlite 0.0.24 → 0.0.26
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 +44 -1
- package/LICENSE +22 -0
- package/README.md +39 -0
- package/jest.config.js +0 -1
- package/jest.tsconfig.json +1 -1
- package/lib/ids.d.ts +2 -2
- package/lib/ids.js +21 -15
- package/lib/ids.js.map +1 -0
- package/lib/index.d.ts +3 -25
- package/lib/index.js +8 -90
- package/lib/index.js.map +1 -0
- package/lib/plugins/extrnal.js +1 -0
- package/lib/plugins/extrnal.js.map +1 -0
- package/package.json +16 -14
- package/src/ids.ts +51 -44
- package/src/index.ts +10 -122
- package/src/plugins/extrnal.ts +11 -11
- package/t/fill-fixtures-md-to-pod6.ts +21 -28
- package/t/process.ts +10 -16
- package/t/test-api.ts +28 -30
- package/tsconfig.json +14 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/index.js +0 -2
- package/lib/plugins/index.d.ts +0 -12
- package/lib/plugins/index.js +0 -25
- package/src/plugins/index.ts +0 -22
- package/t/ids.test.ts +0 -32
- package/t/plugin.test.ts +0 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,46 +1,89 @@
|
|
|
1
1
|
# @podlite
|
|
2
2
|
|
|
3
3
|
## Upcoming
|
|
4
|
+
|
|
5
|
+
## 0.0.26
|
|
6
|
+
|
|
7
|
+
- move plugins object to @podlite/schema package
|
|
8
|
+
|
|
9
|
+
## 0.0.25
|
|
10
|
+
|
|
11
|
+
- improve blocks linking
|
|
12
|
+
|
|
4
13
|
## 0.0.24
|
|
14
|
+
|
|
5
15
|
- clean source
|
|
16
|
+
|
|
6
17
|
## 0.0.23
|
|
18
|
+
|
|
7
19
|
- update deps
|
|
20
|
+
|
|
8
21
|
## 0.0.22
|
|
22
|
+
|
|
9
23
|
- update deps
|
|
24
|
+
|
|
10
25
|
## 0.0.21
|
|
26
|
+
|
|
11
27
|
- add =Markdown plugin
|
|
28
|
+
|
|
12
29
|
## 0.0.20
|
|
30
|
+
|
|
13
31
|
- update deps
|
|
32
|
+
|
|
14
33
|
## 0.0.19
|
|
34
|
+
|
|
15
35
|
- update depends
|
|
36
|
+
|
|
16
37
|
## 0.0.18
|
|
38
|
+
|
|
17
39
|
- update depends
|
|
40
|
+
|
|
18
41
|
## 0.0.17
|
|
42
|
+
|
|
19
43
|
- update depends
|
|
44
|
+
|
|
20
45
|
## 0.0.16
|
|
46
|
+
|
|
21
47
|
- update depends
|
|
48
|
+
|
|
22
49
|
## 0.0.15
|
|
50
|
+
|
|
23
51
|
- update depends
|
|
52
|
+
|
|
24
53
|
## 0.0.14
|
|
54
|
+
|
|
25
55
|
- update depends
|
|
56
|
+
|
|
26
57
|
## 0.0.13
|
|
58
|
+
|
|
27
59
|
- fix npm
|
|
60
|
+
|
|
28
61
|
## 0.0.12
|
|
62
|
+
|
|
29
63
|
- add id prop to AST Schema
|
|
30
64
|
- add =Toc plugin
|
|
65
|
+
|
|
31
66
|
## 0.0.10
|
|
67
|
+
|
|
32
68
|
- update deps
|
|
69
|
+
|
|
33
70
|
## 0.0.9
|
|
71
|
+
|
|
34
72
|
- fix md transforms
|
|
73
|
+
|
|
35
74
|
## 0.0.8
|
|
75
|
+
|
|
36
76
|
- update deps
|
|
37
77
|
|
|
38
78
|
## 0.0.7
|
|
79
|
+
|
|
39
80
|
- update deps
|
|
40
81
|
|
|
41
82
|
## 0.0.6
|
|
83
|
+
|
|
42
84
|
- enable tests
|
|
43
85
|
- update deps
|
|
44
86
|
|
|
45
87
|
## 0.0.5
|
|
46
|
-
|
|
88
|
+
|
|
89
|
+
- import from original repo
|
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2021-2024 Aliaksandr Zahatski
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
[](https://podlite.org)
|
|
4
|
+
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
**Podlite is a lightweight block-based markup language designed for flexibility and ease of use.**
|
|
8
|
+
|
|
9
|
+
Unbound by any specific domain, programming language, or concept, Podlite stands out as a universal markup language. It's versatile enough to be successfully implemented across various development fields, from web development to scientific research.
|
|
10
|
+
|
|
11
|
+
Podlite is not limited to any specific application domain, programming language, or concept.
|
|
12
|
+
|
|
13
|
+
In addition, the support for Markdown markup as a standard block adds convenience and allows for the use of familiar syntax for text formatting.
|
|
14
|
+
|
|
15
|
+
One of the key features of Podlite is its extensibility. This allows for defining unique and domain-specific blocks and expanding the language's functionality according to the requirements of your project.
|
|
16
|
+
|
|
17
|
+
Its flexibility makes it an ideal tool for creating documentation, blogs, educational materials, and much more.
|
|
18
|
+
|
|
19
|
+
Podlite aims to provide users with a means for creativity and expressing ideas in a structured form, while ensuring ease of use and high flexibility in content creation.
|
|
20
|
+
|
|
21
|
+
## Useful links
|
|
22
|
+
|
|
23
|
+
📖 _Project site_: [podlite.org](https://podlite.org)
|
|
24
|
+
|
|
25
|
+
📌 _Github_: [github.com/podlite](https://github.com/podlite/) 🤩
|
|
26
|
+
|
|
27
|
+
🖥️ _Online editor_: [pod6.in](https://pod6.in/)
|
|
28
|
+
|
|
29
|
+
🖥️ _Desktop editor/viewer_: [github.com/podlite/podlite-desktop](https://github.com/podlite/podlite-desktop) - the viewer and editor of `.podlite` and `.pod6` files for Windows, Linux and Mac.
|
|
30
|
+
|
|
31
|
+
📚 _Podlite for web_ - static site generator: [github.com/podlite/podlite-web](https://github.com/podlite/podlite-web)
|
|
32
|
+
|
|
33
|
+
## AUTHOR
|
|
34
|
+
|
|
35
|
+
Copyright (c) 2021-2024 Aliaksandr Zahatski
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
Released under a MIT License.
|
package/jest.config.js
CHANGED
package/jest.tsconfig.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"extends": "../../jest.tsconfig.json"}
|
|
1
|
+
{ "extends": "../../jest.tsconfig.json" }
|
package/lib/ids.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParserPlugin } from '@podlite/schema';
|
|
2
2
|
/**
|
|
3
3
|
* Clean ids from tree
|
|
4
4
|
* @returns
|
|
@@ -14,5 +14,5 @@ export declare const frozenIds: (src?: {
|
|
|
14
14
|
skipChain: number;
|
|
15
15
|
podMode: number;
|
|
16
16
|
}) => (tree: any) => any;
|
|
17
|
-
declare const middleware:
|
|
17
|
+
declare const middleware: ParserPlugin;
|
|
18
18
|
export default middleware;
|
package/lib/ids.js
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.frozenIds = exports.cleanIds = void 0;
|
|
7
|
-
const
|
|
4
|
+
const schema_1 = require("@podlite/schema");
|
|
8
5
|
const nanoid_1 = require("nanoid");
|
|
9
6
|
/**
|
|
10
7
|
* Clean ids from tree
|
|
11
8
|
* @returns
|
|
12
9
|
*/
|
|
13
|
-
const cleanIds = (src = { skipChain: 0, podMode: 1 }) =>
|
|
14
|
-
const transformerBlocks = (0,
|
|
10
|
+
const cleanIds = (src = { skipChain: 0, podMode: 1 }) => tree => {
|
|
11
|
+
const transformerBlocks = (0, schema_1.makeTransformer)({
|
|
15
12
|
'*': (node, ctx, visiter) => {
|
|
16
13
|
if ('id' in node) {
|
|
17
14
|
if ('content' in node) {
|
|
18
15
|
node.content = visiter(node.content, ctx);
|
|
19
16
|
}
|
|
20
17
|
const { id, ...rest } = node;
|
|
21
|
-
return { ...rest
|
|
18
|
+
return { ...rest };
|
|
22
19
|
}
|
|
23
20
|
return node;
|
|
24
|
-
}
|
|
21
|
+
},
|
|
25
22
|
});
|
|
26
23
|
return transformerBlocks(tree, {});
|
|
27
24
|
};
|
|
@@ -29,8 +26,8 @@ exports.cleanIds = cleanIds;
|
|
|
29
26
|
/**
|
|
30
27
|
* Add set id to 'id' to each blocks
|
|
31
28
|
*/
|
|
32
|
-
const frozenIds = (src = { skipChain: 0, podMode: 1 }) =>
|
|
33
|
-
const transformerBlocks = (0,
|
|
29
|
+
const frozenIds = (src = { skipChain: 0, podMode: 1 }) => tree => {
|
|
30
|
+
const transformerBlocks = (0, schema_1.makeTransformer)({
|
|
34
31
|
'*': (node, ctx, visiter) => {
|
|
35
32
|
if ('id' in node) {
|
|
36
33
|
if ('content' in node) {
|
|
@@ -40,17 +37,25 @@ const frozenIds = (src = { skipChain: 0, podMode: 1 }) => (tree) => {
|
|
|
40
37
|
return { ...rest, id: 'id' };
|
|
41
38
|
}
|
|
42
39
|
return node;
|
|
43
|
-
}
|
|
40
|
+
},
|
|
44
41
|
});
|
|
45
42
|
return transformerBlocks(tree, {});
|
|
46
43
|
};
|
|
47
44
|
exports.frozenIds = frozenIds;
|
|
48
|
-
const middleware = () =>
|
|
49
|
-
const transformerBlocks = (0,
|
|
45
|
+
const middleware = () => tree => {
|
|
46
|
+
const transformerBlocks = (0, schema_1.makeTransformer)({
|
|
50
47
|
'*': (node, ctx, visiter) => {
|
|
51
48
|
const addIdField = (node) => {
|
|
52
49
|
if (typeof node === 'object' && 'type' in node && node.type == 'block') {
|
|
53
|
-
|
|
50
|
+
if (node.name == 'caption') {
|
|
51
|
+
return node;
|
|
52
|
+
}
|
|
53
|
+
else if (node.name == 'head') {
|
|
54
|
+
return { ...node, id: (0, schema_1.getTextContentFromNode)(node).trim() };
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return { ...node, id: (0, nanoid_1.nanoid)() };
|
|
58
|
+
}
|
|
54
59
|
}
|
|
55
60
|
return node;
|
|
56
61
|
};
|
|
@@ -61,8 +66,9 @@ const middleware = () => (tree) => {
|
|
|
61
66
|
return node;
|
|
62
67
|
};
|
|
63
68
|
return processContent(addIdField(node));
|
|
64
|
-
}
|
|
69
|
+
},
|
|
65
70
|
});
|
|
66
71
|
return transformerBlocks(tree, {});
|
|
67
72
|
};
|
|
68
73
|
exports.default = middleware;
|
|
74
|
+
//# sourceMappingURL=ids.js.map
|
package/lib/ids.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.js","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":";;;AAAA,4CAAoF;AAEpF,mCAA+B;AAG/B;;;GAGG;AAEI,MAAM,QAAQ,GACnB,CAAC,GAAG,GAAG,EAAE,SAAS,EAAE,CA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AAC,CAAA;AACpC,CAAC,CAAA;AACD,kBAAe,UAAU,CAAA"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,29 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { cleanIds, frozenIds } from './ids';
|
|
3
|
-
export { cleanIds, frozenIds };
|
|
1
|
+
import { Podlite } from '@podlite/schema';
|
|
4
2
|
export interface PodliteOpt {
|
|
5
3
|
importPlugins: boolean;
|
|
6
4
|
}
|
|
7
|
-
export interface PodliteExport {
|
|
8
|
-
errors: any;
|
|
9
|
-
toString: () => string;
|
|
10
|
-
valueOf: () => string;
|
|
11
|
-
indexingTerms: any;
|
|
12
|
-
annotations: any;
|
|
13
|
-
defenitions: any;
|
|
14
|
-
interator: any;
|
|
15
|
-
}
|
|
16
|
-
export interface Podlite {
|
|
17
|
-
toAstResult: (ast: PodliteDocument) => PodliteExport;
|
|
18
|
-
(): any;
|
|
19
|
-
use: (plugin: Plugins) => Podlite;
|
|
20
|
-
parse: (text: string, opt?: {
|
|
21
|
-
skipChain: number;
|
|
22
|
-
podMode: number;
|
|
23
|
-
}) => PodliteDocument;
|
|
24
|
-
toHtml: (ast: PodliteDocument) => string;
|
|
25
|
-
toAst: (ast: PodliteDocument) => PodliteDocument;
|
|
26
|
-
getPlugins: () => Array<Plugins>;
|
|
27
|
-
}
|
|
28
|
-
export declare const toAnyRules: (method: any, allplugins: Plugins[]) => {};
|
|
29
5
|
export declare const podlite: ({ importPlugins }: PodliteOpt) => Podlite;
|
|
6
|
+
declare const VERSION: any;
|
|
7
|
+
export { VERSION as version };
|
package/lib/index.js
CHANGED
|
@@ -3,98 +3,16 @@ 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
|
-
exports.
|
|
7
|
-
const pod6_1 = require("pod6");
|
|
8
|
-
const exportAny_1 = __importDefault(require("pod6/built/exportAny"));
|
|
6
|
+
exports.version = exports.podlite = void 0;
|
|
9
7
|
const schema_1 = require("@podlite/schema");
|
|
10
|
-
const plugins_1 = __importDefault(require("./plugins"));
|
|
11
8
|
const extrnal_1 = __importDefault(require("./plugins/extrnal"));
|
|
12
|
-
const ids_1 = __importDefault(require("./ids"));
|
|
13
|
-
const ids_2 = require("./ids");
|
|
14
|
-
Object.defineProperty(exports, "cleanIds", { enumerable: true, get: function () { return ids_2.cleanIds; } });
|
|
15
|
-
Object.defineProperty(exports, "frozenIds", { enumerable: true, get: function () { return ids_2.frozenIds; } });
|
|
16
|
-
const toAnyRules = (method, allplugins) => {
|
|
17
|
-
// make uniq plugins
|
|
18
|
-
const resultMap = allplugins.reverse().reduce((result, plugins) => {
|
|
19
|
-
for (const plugin of Object.entries(plugins)) {
|
|
20
|
-
const [key, val] = plugin;
|
|
21
|
-
if (!(key in result)) {
|
|
22
|
-
result[key] = val;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return result;
|
|
26
|
-
}, {});
|
|
27
|
-
let result = {};
|
|
28
|
-
// prepare plugins for export <method>
|
|
29
|
-
for (const plugin of Object.entries(resultMap)) {
|
|
30
|
-
const [key, val = {}] = plugin;
|
|
31
|
-
//@ts-ignore
|
|
32
|
-
if (method in val) {
|
|
33
|
-
result[key] = val[method];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
exports.toAnyRules = toAnyRules;
|
|
39
9
|
const podlite = ({ importPlugins = true }) => {
|
|
40
|
-
let
|
|
41
|
-
|
|
42
|
-
instance.use = (onj) => {
|
|
43
|
-
for (const plugin of Object.entries(onj)) {
|
|
44
|
-
const [key, val] = plugin;
|
|
45
|
-
if (typeof val === 'function') {
|
|
46
|
-
plugins.push({ [key]: { toAst: val } });
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
plugins.push({ [key]: val });
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return instance;
|
|
53
|
-
};
|
|
54
|
-
instance.parse = (text, opt = { skipChain: 0, podMode: 1 }) => {
|
|
55
|
-
const rawTree = (0, pod6_1.toTree)().use(ids_1.default).parse(text, opt);
|
|
56
|
-
const root = (0, schema_1.mkRootBlock)({ margin: "" }, rawTree);
|
|
57
|
-
return root;
|
|
58
|
-
};
|
|
59
|
-
instance.toAst = (ast) => {
|
|
60
|
-
return instance.toAstResult(ast).interator;
|
|
61
|
-
};
|
|
62
|
-
instance.toAstResult = (ast) => {
|
|
63
|
-
// get plugins for Ast
|
|
64
|
-
const toAstPlugins = (0, exports.toAnyRules)('toAst', instance.getPlugins());
|
|
65
|
-
const result = (0, exportAny_1.default)().use({
|
|
66
|
-
'*': () => (node, ctx, interator) => {
|
|
67
|
-
if ('content' in node) {
|
|
68
|
-
node.content = interator(node.content, ctx);
|
|
69
|
-
}
|
|
70
|
-
return node;
|
|
71
|
-
}
|
|
72
|
-
}).use(toAstPlugins).run(ast);
|
|
73
|
-
// add second pass
|
|
74
|
-
const toAstAfterPlugins = (0, exports.toAnyRules)('toAstAfter', instance.getPlugins());
|
|
75
|
-
if (Object.keys(toAstAfterPlugins).length) {
|
|
76
|
-
const resultAfter = (0, exportAny_1.default)().use({
|
|
77
|
-
'*': () => (node, ctx, interator) => {
|
|
78
|
-
if ('content' in node) {
|
|
79
|
-
node.content = interator(node.content, ctx);
|
|
80
|
-
}
|
|
81
|
-
return node;
|
|
82
|
-
}
|
|
83
|
-
}).use(toAstAfterPlugins).run(ast);
|
|
84
|
-
return resultAfter;
|
|
85
|
-
}
|
|
86
|
-
return result;
|
|
87
|
-
};
|
|
88
|
-
instance.toHtml = (ast) => {
|
|
89
|
-
const toHtmlPlugins = (0, exports.toAnyRules)('toHtml', instance.getPlugins());
|
|
90
|
-
return (0, pod6_1.toHtml)({}).use(toHtmlPlugins).run(ast, null);
|
|
91
|
-
};
|
|
92
|
-
instance.getPlugins = () => plugins;
|
|
93
|
-
// init core plugins
|
|
94
|
-
instance.use(plugins_1.default);
|
|
95
|
-
if (importPlugins) {
|
|
96
|
-
instance.use(extrnal_1.default);
|
|
97
|
-
}
|
|
98
|
-
return instance;
|
|
10
|
+
let plugins = importPlugins ? extrnal_1.default : {};
|
|
11
|
+
return (0, schema_1.podlitePluggable)({ plugins });
|
|
99
12
|
};
|
|
100
13
|
exports.podlite = podlite;
|
|
14
|
+
// Cannot be `import` as it's not under TS root dir
|
|
15
|
+
// https://stackoverflow.com/questions/51070138/how-to-import-package-json-into-typescript-file-without-including-it-in-the-comp
|
|
16
|
+
const { version: VERSION } = require('../package.json');
|
|
17
|
+
exports.version = VERSION;
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA2D;AAC3D,gEAA+C;AAKxC,MAAM,OAAO,GAAG,CAAC,EAAE,aAAa,GAAG,IAAI,EAAc,EAAW,EAAE;IACvE,IAAI,OAAO,GAAG,aAAa,CAAC,CAAC,CAAC,iBAAe,CAAC,CAAC,CAAC,EAAE,CAAA;IAClD,OAAO,IAAA,yBAAgB,EAAC,EAAE,OAAO,EAAE,CAAC,CAAA;AACtC,CAAC,CAAA;AAHY,QAAA,OAAO,WAGnB;AAED,mDAAmD;AACnD,gIAAgI;AAEhI,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;AACnC,0BAAO"}
|
package/lib/plugins/extrnal.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extrnal.js","sourceRoot":"","sources":["../../src/plugins/extrnal.ts"],"names":[],"mappings":";;AACA,0CAA+C;AAC/C,8CAAoE;AACpE,gDAAsE;AACtE,sCAA4D;AAC5D,MAAM,QAAQ,GAAY;IACxB,GAAG,wBAAe;IAClB,GAAG,yBAAgB;IACnB,GAAG,sBAAc;IACjB,GAAG,oBAAW;CACf,CAAA;AAED,kBAAe,QAAQ,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "podlite",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "index.js",
|
|
3
|
+
"version": "0.0.26",
|
|
4
|
+
"description": "Podlite - a lightweight block-based markup language",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "yarn g:jest --passWithNoTests",
|
|
@@ -14,18 +14,19 @@
|
|
|
14
14
|
"keywords": [
|
|
15
15
|
"markdown",
|
|
16
16
|
"pod6",
|
|
17
|
-
"
|
|
17
|
+
"podlite",
|
|
18
|
+
"markup",
|
|
19
|
+
"markup-language"
|
|
18
20
|
],
|
|
19
|
-
"author": "
|
|
21
|
+
"author": "Aliaksandr Zahatski",
|
|
20
22
|
"license": "MIT",
|
|
21
23
|
"dependencies": {
|
|
22
|
-
"@podlite/diagram": "^0.0.
|
|
23
|
-
"@podlite/image": "^0.0.
|
|
24
|
-
"@podlite/markdown": "0.0.
|
|
25
|
-
"@podlite/schema": "^0.0.
|
|
26
|
-
"@podlite/toc": "0.0.
|
|
27
|
-
"nanoid": "3.1.30"
|
|
28
|
-
"pod6": "^0.0.48"
|
|
24
|
+
"@podlite/diagram": "^0.0.17",
|
|
25
|
+
"@podlite/image": "^0.0.12",
|
|
26
|
+
"@podlite/markdown": "0.0.6",
|
|
27
|
+
"@podlite/schema": "^0.0.13",
|
|
28
|
+
"@podlite/toc": "0.0.6",
|
|
29
|
+
"nanoid": "3.1.30"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@types/jest": "^26.0.21",
|
|
@@ -34,10 +35,11 @@
|
|
|
34
35
|
"typescript": "4.5.5"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
37
|
-
"
|
|
38
|
+
"react": "^16.0.0 || ^17.0.0",
|
|
39
|
+
"react-dom": "^16.0.0 || ^17.0.0"
|
|
38
40
|
},
|
|
39
41
|
"publishConfig": {
|
|
40
42
|
"access": "public",
|
|
41
|
-
"main": "index.js"
|
|
43
|
+
"main": "./lib/index.js"
|
|
42
44
|
}
|
|
43
45
|
}
|
package/src/ids.ts
CHANGED
|
@@ -1,69 +1,76 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { BlockHead, getTextContentFromNode, makeTransformer } from '@podlite/schema'
|
|
2
|
+
import { ParserPlugin } from '@podlite/schema'
|
|
3
3
|
import { nanoid } from 'nanoid'
|
|
4
|
-
import {
|
|
4
|
+
import { PodNode } from '@podlite/schema'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Clean ids from tree
|
|
8
|
-
* @returns
|
|
7
|
+
* Clean ids from tree
|
|
8
|
+
* @returns
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
export const cleanIds =
|
|
11
|
+
export const cleanIds =
|
|
12
|
+
(src = { skipChain: 0, podMode: 1 }) =>
|
|
13
|
+
tree => {
|
|
12
14
|
const transformerBlocks = makeTransformer({
|
|
13
15
|
'*': (node, ctx, visiter) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
const {id, ...rest} = node
|
|
19
|
-
return { ...rest, }
|
|
16
|
+
if ('id' in node) {
|
|
17
|
+
if ('content' in node) {
|
|
18
|
+
node.content = visiter(node.content, ctx)
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const { id, ...rest } = node
|
|
21
|
+
return { ...rest }
|
|
22
|
+
}
|
|
23
|
+
return node
|
|
24
|
+
},
|
|
23
25
|
})
|
|
24
|
-
return transformerBlocks(tree,{})
|
|
26
|
+
return transformerBlocks(tree, {})
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
30
|
* Add set id to 'id' to each blocks
|
|
29
31
|
*/
|
|
30
|
-
export const frozenIds =
|
|
32
|
+
export const frozenIds =
|
|
33
|
+
(src = { skipChain: 0, podMode: 1 }) =>
|
|
34
|
+
tree => {
|
|
31
35
|
const transformerBlocks = makeTransformer({
|
|
32
36
|
'*': (node, ctx, visiter) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
const {id, ...rest} = node
|
|
38
|
-
return { ...rest, id: 'id' }
|
|
37
|
+
if ('id' in node) {
|
|
38
|
+
if ('content' in node) {
|
|
39
|
+
node.content = visiter(node.content, ctx)
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
const { id, ...rest } = node
|
|
42
|
+
return { ...rest, id: 'id' }
|
|
43
|
+
}
|
|
44
|
+
return node
|
|
45
|
+
},
|
|
42
46
|
})
|
|
43
|
-
return transformerBlocks(tree,{})
|
|
44
|
-
}
|
|
45
|
-
|
|
47
|
+
return transformerBlocks(tree, {})
|
|
48
|
+
}
|
|
46
49
|
|
|
47
|
-
const middleware:
|
|
48
|
-
|
|
50
|
+
const middleware: ParserPlugin = () => tree => {
|
|
49
51
|
const transformerBlocks = makeTransformer({
|
|
50
52
|
'*': (node, ctx, visiter) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
const addIdField = (node: PodNode): PodNode => {
|
|
54
|
+
if (typeof node === 'object' && 'type' in node && node.type == 'block') {
|
|
55
|
+
if (node.name == 'caption') {
|
|
56
|
+
return node
|
|
57
|
+
} else if (node.name == 'head') {
|
|
58
|
+
return { ...node, id: getTextContentFromNode(node).trim() } as BlockHead
|
|
59
|
+
} else {
|
|
60
|
+
return { ...node, id: nanoid() } as PodNode
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return node
|
|
64
|
+
}
|
|
65
|
+
const processContent = (node: PodNode): PodNode => {
|
|
66
|
+
if (typeof node === 'object' && 'content' in node) {
|
|
67
|
+
return { ...node, content: visiter(node.content, ctx) }
|
|
64
68
|
}
|
|
69
|
+
return node
|
|
70
|
+
}
|
|
71
|
+
return processContent(addIdField(node))
|
|
72
|
+
},
|
|
65
73
|
})
|
|
66
|
-
return transformerBlocks(tree,{})
|
|
74
|
+
return transformerBlocks(tree, {})
|
|
67
75
|
}
|
|
68
76
|
export default middleware
|
|
69
|
-
|