@podlite/schema 0.0.17 → 0.0.19
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 +10 -0
- package/esm/blocks-helpers.d.ts +6 -1
- package/esm/blocks-helpers.js +8 -4
- package/esm/blocks-helpers.js.map +1 -1
- package/esm/exportHtml.js +1 -1
- package/esm/exportHtml.js.map +1 -1
- package/esm/grammar.js +4 -3
- package/esm/grammar.js.map +1 -1
- package/esm/grammarfc.js +4705 -1586
- package/esm/grammarfc.js.map +1 -1
- package/esm/helpers/ids.d.ts +1 -1
- package/esm/helpers/ids.js +3 -7
- package/esm/helpers/ids.js.map +1 -1
- package/esm/helpers/makeInterator.js +1 -1
- package/esm/helpers/makeInterator.js.map +1 -1
- package/esm/helpers/makeQuery.js +2 -2
- package/esm/helpers/makeQuery.js.map +1 -1
- package/esm/helpers/makeTransformer.js +1 -1
- package/esm/helpers/makeTransformer.js.map +1 -1
- package/esm/plugin-formatting-codes.js +12 -6
- package/esm/plugin-formatting-codes.js.map +1 -1
- package/esm/types.d.ts +34 -7
- package/lib/blocks-helpers.d.ts +6 -1
- package/lib/blocks-helpers.js +11 -5
- package/lib/exportHtml.js +1 -1
- package/lib/grammar.js +4 -3
- package/lib/grammarfc.js +4705 -1586
- package/lib/helpers/ids.d.ts +1 -1
- package/lib/helpers/ids.js +8 -9
- package/lib/helpers/makeInterator.js +1 -1
- package/lib/helpers/makeQuery.js +2 -2
- package/lib/helpers/makeTransformer.js +1 -1
- package/lib/plugin-formatting-codes.js +12 -6
- package/lib/types.d.ts +34 -7
- package/package.json +3 -3
- package/schema/AstTree.json +1236 -1073
- package/schema/PodliteDocument.json +1236 -1073
package/lib/helpers/ids.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const frozenIds: (src?: {
|
|
|
15
15
|
skipChain: number;
|
|
16
16
|
podMode: number;
|
|
17
17
|
}) => (tree: any) => any;
|
|
18
|
-
export declare const
|
|
18
|
+
export declare const setAllLinksToAnchor: (src?: {
|
|
19
19
|
skipChain: number;
|
|
20
20
|
podMode: number;
|
|
21
21
|
}) => (tree: any) => any;
|
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.
|
|
6
|
+
exports.setAllLinksToAnchor = 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
|
|
@@ -25,12 +29,7 @@ const cleanIds = (src = { skipChain: 0, podMode: 1 }) => tree => {
|
|
|
25
29
|
exports.cleanIds = cleanIds;
|
|
26
30
|
// TODO: refactor linking for blocks
|
|
27
31
|
const slugifyText = (text) => {
|
|
28
|
-
|
|
29
|
-
return text.trim()
|
|
30
|
-
// .toLowerCase()
|
|
31
|
-
.replace(/\s+/g, '-')
|
|
32
|
-
.replace(/[\]\[\!\/\'\"\#\$\%\&\(\)\*\+\,\.\/\:\;\<\=\>\?\@\\\^\{\|\}\~\`。,、;:?!…—·ˉ¨‘’“”々~‖∶"'`|〃〔〕〈〉《》「」『』.〖〗【】()[]{}]/g, '')
|
|
33
|
-
.replace(/^\-+/, '');
|
|
32
|
+
return (0, slugify_1.default)(text.trim(), {});
|
|
34
33
|
};
|
|
35
34
|
exports.slugifyText = slugifyText;
|
|
36
35
|
/**
|
|
@@ -52,7 +51,7 @@ const frozenIds = (src = { skipChain: 0, podMode: 1 }) => tree => {
|
|
|
52
51
|
return transformerBlocks(tree, {});
|
|
53
52
|
};
|
|
54
53
|
exports.frozenIds = frozenIds;
|
|
55
|
-
const
|
|
54
|
+
const setAllLinksToAnchor = (src = { skipChain: 0, podMode: 1 }) => tree => {
|
|
56
55
|
const transformerBlocks = (0, __1.makeTransformer)({
|
|
57
56
|
'L<>': (node, ctx, visiter) => {
|
|
58
57
|
if ('meta' in node) {
|
|
@@ -67,7 +66,7 @@ const cleanLocalHrefs = (src = { skipChain: 0, podMode: 1 }) => tree => {
|
|
|
67
66
|
});
|
|
68
67
|
return transformerBlocks(tree, {});
|
|
69
68
|
};
|
|
70
|
-
exports.
|
|
69
|
+
exports.setAllLinksToAnchor = setAllLinksToAnchor;
|
|
71
70
|
const middleware = () => tree => {
|
|
72
71
|
const transformerBlocks = (0, __1.makeTransformer)({
|
|
73
72
|
'*': (node, ctx, visiter) => {
|
|
@@ -35,7 +35,7 @@ function thisFunc(rules) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
if (typeof reversed[ruleIndex].fn !== 'function') {
|
|
38
|
-
console.warn('[
|
|
38
|
+
console.warn('[podlite] bad fn for ' + JSON.stringify(node, null, 2));
|
|
39
39
|
}
|
|
40
40
|
return reversed[ruleIndex].fn(node, context, interator, defaultFn);
|
|
41
41
|
}
|
package/lib/helpers/makeQuery.js
CHANGED
|
@@ -53,11 +53,11 @@ function is(query, node) {
|
|
|
53
53
|
return true;
|
|
54
54
|
for (var prop in query) {
|
|
55
55
|
if (query === undefined) {
|
|
56
|
-
console.warn('[
|
|
56
|
+
console.warn('[podlite] undefined key!!!');
|
|
57
57
|
}
|
|
58
58
|
if (query.hasOwnProperty(prop)) {
|
|
59
59
|
if (node === undefined) {
|
|
60
|
-
console.warn('[
|
|
60
|
+
console.warn('[podlite] undefined node!!!');
|
|
61
61
|
}
|
|
62
62
|
if (node && node.hasOwnProperty(prop)) {
|
|
63
63
|
if (query[prop] !== node[prop]) {
|
|
@@ -21,7 +21,7 @@ const makeTransformer = rule => {
|
|
|
21
21
|
let rules = [];
|
|
22
22
|
function use(key, fn) {
|
|
23
23
|
if (key instanceof Array) {
|
|
24
|
-
console.warn(`[
|
|
24
|
+
console.warn(`[podlite] Unsupported param for ${key}`);
|
|
25
25
|
}
|
|
26
26
|
if (key instanceof Object) {
|
|
27
27
|
for (var prop in key) {
|
|
@@ -51,25 +51,31 @@ 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
|
|
54
|
+
const isFormulaBlock = 'name' in n && n.name === 'formula';
|
|
55
|
+
const allowValues = [...conf.getAllValues('allow'), ...(isCodeBlock ? ['NONE'] : [])];
|
|
56
|
+
if ((0, makeTransformer_2.isNamedBlock)(n.name))
|
|
57
|
+
return n;
|
|
55
58
|
// for code block not parse content by default
|
|
56
|
-
if ((isCodeBlock || isDataBlock || isMarkdownBlock || isPictureBlock) &&
|
|
59
|
+
if ((isCodeBlock || isDataBlock || isMarkdownBlock || isPictureBlock || isFormulaBlock) &&
|
|
60
|
+
allowValues.length == 0)
|
|
57
61
|
return n;
|
|
58
62
|
const allowed = allowValues.sort();
|
|
59
63
|
const transformer = (0, makeTransformer_1.default)({
|
|
60
64
|
':verbatim': (n, ctx) => {
|
|
65
|
+
// special case for code block, 'NONE' - flag disabled all markup codes
|
|
66
|
+
// do not parse content by default
|
|
67
|
+
if (allowed.length == 1 && allowed.includes('NONE'))
|
|
68
|
+
return n;
|
|
61
69
|
return fcparser.parse(n.value, { allowed });
|
|
62
70
|
},
|
|
63
71
|
':text': (n, ctx) => {
|
|
64
72
|
return fcparser.parse(n.value, { allowed });
|
|
65
73
|
},
|
|
66
74
|
':block': (n, ctx) => {
|
|
67
|
-
|
|
68
|
-
return n;
|
|
69
|
-
return { ...n, content: transformer(n.content, { ...ctx }) };
|
|
75
|
+
return transformerBlocks(n, { ...ctx });
|
|
70
76
|
},
|
|
71
77
|
});
|
|
72
|
-
return transformer(n, { ...ctx });
|
|
78
|
+
return { ...n, content: transformer(n.content, { ...ctx }) };
|
|
73
79
|
},
|
|
74
80
|
});
|
|
75
81
|
return transformerBlocks(tree, {});
|
package/lib/types.d.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
export interface RuleHandler<T = any> {
|
|
2
3
|
(writer: any, processor: any, tree: PodliteDocument): (node: T, ctx: any, interator: any) => void | AstTree | PodNode;
|
|
3
4
|
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
declare type createComponentParams = PodNode & {
|
|
6
|
+
children: React.ReactNode[];
|
|
7
|
+
} & {
|
|
8
|
+
key: string | number;
|
|
9
|
+
};
|
|
10
|
+
export declare type JSXHelper = (src: string | (({}: createComponentParams, children: React.ReactNode[]) => React.ReactNode[] | React.ReactNode), node: PodNode | {}, children: React.ReactNode[], extraProps?: {}, ctx?: {}) => any;
|
|
11
|
+
export interface Plugin<T = any> {
|
|
12
|
+
toAst?: RuleHandler<T>;
|
|
13
|
+
toAstAfter?: RuleHandler<T>;
|
|
14
|
+
toHtml?: RuleHandler<T>;
|
|
15
|
+
toJSX?: (helper: JSXHelper) => RuleHandler<T>;
|
|
9
16
|
}
|
|
10
17
|
export interface Plugins {
|
|
11
18
|
[name: string]: Plugin;
|
|
@@ -16,6 +23,7 @@ export interface RulesStrict {
|
|
|
16
23
|
'C<>': RuleHandler<FormattingCodeC>;
|
|
17
24
|
'D<>': RuleHandler<FormattingCodeD>;
|
|
18
25
|
'E<>': RuleHandler<FormattingCodeE>;
|
|
26
|
+
'F<>': RuleHandler<FormattingCodeF>;
|
|
19
27
|
'I<>': RuleHandler<FormattingCodeI>;
|
|
20
28
|
'K<>': RuleHandler<FormattingCodeAny>;
|
|
21
29
|
'R<>': RuleHandler<FormattingCodeAny>;
|
|
@@ -139,6 +147,20 @@ export interface FormattingCodeE {
|
|
|
139
147
|
content: Array<{
|
|
140
148
|
type: 'number';
|
|
141
149
|
value: number;
|
|
150
|
+
} | {
|
|
151
|
+
type: 'unicode_name';
|
|
152
|
+
value: string;
|
|
153
|
+
} | {
|
|
154
|
+
type: 'html_named';
|
|
155
|
+
value: string;
|
|
156
|
+
}>;
|
|
157
|
+
}
|
|
158
|
+
export interface FormattingCodeF {
|
|
159
|
+
type: 'fcode';
|
|
160
|
+
name: 'F';
|
|
161
|
+
content: Array<{
|
|
162
|
+
type: 'text';
|
|
163
|
+
value: string;
|
|
142
164
|
}>;
|
|
143
165
|
}
|
|
144
166
|
export interface FormattingCodeN {
|
|
@@ -350,8 +372,13 @@ export interface BlockMermaid extends Omit<BlockNamed, 'content'> {
|
|
|
350
372
|
location: Location;
|
|
351
373
|
};
|
|
352
374
|
}
|
|
353
|
-
export
|
|
354
|
-
|
|
375
|
+
export interface BlockFormula extends Omit<BlockNamed, 'content'> {
|
|
376
|
+
name: 'formula';
|
|
377
|
+
content: [Verbatim];
|
|
378
|
+
}
|
|
379
|
+
export declare type FormattingCodes = FormattingCodeA | FormattingCodeC | FormattingCodeB | FormattingCodeD | FormattingCodeE | FormattingCodeF | FormattingCodeI | FormattingCodeL | FormattingCodeN | FormattingCodeX | FormattingCodeZ | FormattingCodeV | FormattingCodeS | FormattingCodeAny;
|
|
380
|
+
export declare type PodNode = Ambient | BlockPod | BlockData | BlockFormula | BlockCode | BlankLine | BlockNested | BlockMarkdown | BlockOutput | BlockInput | BlockPara | BlockHead | BlockComment | BlockDefn | string | Para | Text | Code | BlockNamed | BlockAny | Verbatim | BlockTable | List | BlockConfig | BlockItem | Alias | BlockToc | BlockPicture | BlockImage | Image | RootBlock | Separator | BlockCaption | FormattingCodes | Toc;
|
|
355
381
|
export declare type Node = PodNode;
|
|
356
382
|
export declare type AstTree = Array<PodNode>;
|
|
357
383
|
export declare type PodliteDocument = RootBlock;
|
|
384
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@podlite/schema",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"description": "AST tools for Podlite markup language",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
|
-
"types": "./lib/index.d.ts",
|
|
7
6
|
"license": "MIT",
|
|
8
7
|
"files": [
|
|
9
8
|
"lib/**/*.js",
|
|
@@ -43,7 +42,8 @@
|
|
|
43
42
|
"ajv": "^7.2.3",
|
|
44
43
|
"events": "^3.1.0",
|
|
45
44
|
"json-pointer": "^0.6.1",
|
|
46
|
-
"nanoid": "3.1.30"
|
|
45
|
+
"nanoid": "3.1.30",
|
|
46
|
+
"slugify": "^1.6.6"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/node": "^17.0.7",
|