@podlite/schema 0.0.16 → 0.0.18
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 +11 -0
- package/esm/blocks-helpers.d.ts +2 -2
- package/esm/blocks-helpers.js.map +1 -1
- package/esm/grammarfc.js +4411 -1479
- package/esm/grammarfc.js.map +1 -1
- package/esm/helpers/ids.d.ts +5 -0
- package/esm/helpers/ids.js +22 -2
- package/esm/helpers/ids.js.map +1 -1
- package/esm/plugin-formatting-codes.js +9 -5
- package/esm/plugin-formatting-codes.js.map +1 -1
- package/esm/types.d.ts +1 -1
- package/lib/blocks-helpers.d.ts +2 -2
- package/lib/grammarfc.js +4411 -1479
- package/lib/helpers/ids.d.ts +5 -0
- package/lib/helpers/ids.js +29 -4
- package/lib/plugin-formatting-codes.js +9 -5
- package/lib/types.d.ts +1 -1
- package/package.json +3 -2
package/lib/helpers/ids.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare const cleanIds: (src?: {
|
|
|
7
7
|
skipChain: number;
|
|
8
8
|
podMode: number;
|
|
9
9
|
}) => (tree: any) => any;
|
|
10
|
+
export declare const slugifyText: (text: string) => string;
|
|
10
11
|
/**
|
|
11
12
|
* Add set id to 'id' to each blocks
|
|
12
13
|
*/
|
|
@@ -14,5 +15,9 @@ export declare const frozenIds: (src?: {
|
|
|
14
15
|
skipChain: number;
|
|
15
16
|
podMode: number;
|
|
16
17
|
}) => (tree: any) => any;
|
|
18
|
+
export declare const cleanLocalHrefs: (src?: {
|
|
19
|
+
skipChain: number;
|
|
20
|
+
podMode: number;
|
|
21
|
+
}) => (tree: any) => any;
|
|
17
22
|
declare const middleware: ParserPlugin;
|
|
18
23
|
export default middleware;
|
package/lib/helpers/ids.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.frozenIds = exports.cleanIds = void 0;
|
|
6
|
+
exports.cleanLocalHrefs = exports.frozenIds = exports.slugifyText = exports.cleanIds = void 0;
|
|
4
7
|
const __1 = require("..");
|
|
5
8
|
const nanoid_1 = require("nanoid");
|
|
9
|
+
const slugify_1 = __importDefault(require("slugify"));
|
|
6
10
|
/**
|
|
7
11
|
* Clean ids from tree
|
|
8
12
|
* @returns
|
|
@@ -23,25 +27,46 @@ const cleanIds = (src = { skipChain: 0, podMode: 1 }) => tree => {
|
|
|
23
27
|
return transformerBlocks(tree, {});
|
|
24
28
|
};
|
|
25
29
|
exports.cleanIds = cleanIds;
|
|
30
|
+
// TODO: refactor linking for blocks
|
|
31
|
+
const slugifyText = (text) => {
|
|
32
|
+
return (0, slugify_1.default)(text.trim(), {});
|
|
33
|
+
};
|
|
34
|
+
exports.slugifyText = slugifyText;
|
|
26
35
|
/**
|
|
27
36
|
* Add set id to 'id' to each blocks
|
|
28
37
|
*/
|
|
29
38
|
const frozenIds = (src = { skipChain: 0, podMode: 1 }) => tree => {
|
|
30
39
|
const transformerBlocks = (0, __1.makeTransformer)({
|
|
31
40
|
'*': (node, ctx, visiter) => {
|
|
41
|
+
if ('content' in node) {
|
|
42
|
+
node.content = visiter(node.content, ctx);
|
|
43
|
+
}
|
|
32
44
|
if ('id' in node) {
|
|
45
|
+
const { id, ...rest } = node;
|
|
46
|
+
return { ...rest, id: 'id' };
|
|
47
|
+
}
|
|
48
|
+
return node;
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
return transformerBlocks(tree, {});
|
|
52
|
+
};
|
|
53
|
+
exports.frozenIds = frozenIds;
|
|
54
|
+
const cleanLocalHrefs = (src = { skipChain: 0, podMode: 1 }) => tree => {
|
|
55
|
+
const transformerBlocks = (0, __1.makeTransformer)({
|
|
56
|
+
'L<>': (node, ctx, visiter) => {
|
|
57
|
+
if ('meta' in node) {
|
|
33
58
|
if ('content' in node) {
|
|
34
59
|
node.content = visiter(node.content, ctx);
|
|
35
60
|
}
|
|
36
61
|
const { id, ...rest } = node;
|
|
37
|
-
return { ...rest,
|
|
62
|
+
return { ...rest, meta: '#' };
|
|
38
63
|
}
|
|
39
64
|
return node;
|
|
40
65
|
},
|
|
41
66
|
});
|
|
42
67
|
return transformerBlocks(tree, {});
|
|
43
68
|
};
|
|
44
|
-
exports.
|
|
69
|
+
exports.cleanLocalHrefs = cleanLocalHrefs;
|
|
45
70
|
const middleware = () => tree => {
|
|
46
71
|
const transformerBlocks = (0, __1.makeTransformer)({
|
|
47
72
|
'*': (node, ctx, visiter) => {
|
|
@@ -51,7 +76,7 @@ const middleware = () => tree => {
|
|
|
51
76
|
return node;
|
|
52
77
|
}
|
|
53
78
|
else if (node.name == 'head') {
|
|
54
|
-
return { ...node, id: (0, __1.getTextContentFromNode)(node)
|
|
79
|
+
return { ...node, id: (0, exports.slugifyText)((0, __1.getTextContentFromNode)(node)) };
|
|
55
80
|
}
|
|
56
81
|
else {
|
|
57
82
|
return { ...node, id: (0, nanoid_1.nanoid)() };
|
|
@@ -51,25 +51,29 @@ const middle = () => tree => {
|
|
|
51
51
|
const isDataBlock = 'name' in n && n.name === 'data';
|
|
52
52
|
const isMarkdownBlock = 'name' in n && n.name === 'markdown';
|
|
53
53
|
const isPictureBlock = 'name' in n && n.name === 'picture';
|
|
54
|
-
const allowValues = conf.getAllValues('allow');
|
|
54
|
+
const allowValues = [...conf.getAllValues('allow'), ...(isCodeBlock ? ['NONE'] : [])];
|
|
55
|
+
if ((0, makeTransformer_2.isNamedBlock)(n.name))
|
|
56
|
+
return n;
|
|
55
57
|
// for code block not parse content by default
|
|
56
58
|
if ((isCodeBlock || isDataBlock || isMarkdownBlock || isPictureBlock) && allowValues.length == 0)
|
|
57
59
|
return n;
|
|
58
60
|
const allowed = allowValues.sort();
|
|
59
61
|
const transformer = (0, makeTransformer_1.default)({
|
|
60
62
|
':verbatim': (n, ctx) => {
|
|
63
|
+
// special case for code block, 'NONE' - flag disabled all markup codes
|
|
64
|
+
// do not parse content by default
|
|
65
|
+
if (allowed.length == 1 && allowed.includes('NONE'))
|
|
66
|
+
return n;
|
|
61
67
|
return fcparser.parse(n.value, { allowed });
|
|
62
68
|
},
|
|
63
69
|
':text': (n, ctx) => {
|
|
64
70
|
return fcparser.parse(n.value, { allowed });
|
|
65
71
|
},
|
|
66
72
|
':block': (n, ctx) => {
|
|
67
|
-
|
|
68
|
-
return n;
|
|
69
|
-
return { ...n, content: transformer(n.content, { ...ctx }) };
|
|
73
|
+
return transformerBlocks(n, { ...ctx });
|
|
70
74
|
},
|
|
71
75
|
});
|
|
72
|
-
return transformer(n, { ...ctx });
|
|
76
|
+
return { ...n, content: transformer(n.content, { ...ctx }) };
|
|
73
77
|
},
|
|
74
78
|
});
|
|
75
79
|
return transformerBlocks(tree, {});
|
package/lib/types.d.ts
CHANGED
|
@@ -333,7 +333,7 @@ export interface TableSeparator {
|
|
|
333
333
|
}
|
|
334
334
|
export declare type BlockAny = BlockNamed;
|
|
335
335
|
export interface BlockNamed extends Omit<Block, 'content'> {
|
|
336
|
-
name:
|
|
336
|
+
name: string;
|
|
337
337
|
content: [(Verbatim | Para | Code)?] | Array<Image | BlockCaption> | RootBlock;
|
|
338
338
|
}
|
|
339
339
|
export interface BlockDiagram extends Omit<BlockNamed, 'content'> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@podlite/schema",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "AST tools for Podlite markup language",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -43,7 +43,8 @@
|
|
|
43
43
|
"ajv": "^7.2.3",
|
|
44
44
|
"events": "^3.1.0",
|
|
45
45
|
"json-pointer": "^0.6.1",
|
|
46
|
-
"nanoid": "3.1.30"
|
|
46
|
+
"nanoid": "3.1.30",
|
|
47
|
+
"slugify": "^1.6.6"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@types/node": "^17.0.7",
|