@podlite/schema 0.0.37 → 0.0.38
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.podlite +16 -0
- package/README.md +61 -4
- package/esm/blocks-helpers.d.ts +2 -2
- package/esm/blocks-helpers.js +11 -4
- package/esm/blocks-helpers.js.map +1 -1
- package/esm/exportHtml.js +57 -6
- package/esm/exportHtml.js.map +1 -1
- package/esm/exportMarkdown.js +52 -6
- package/esm/exportMarkdown.js.map +1 -1
- package/esm/grammar.js +442 -215
- package/esm/grammar.js.map +1 -1
- package/esm/grammarfc.js +1819 -1459
- package/esm/grammarfc.js.map +1 -1
- package/esm/helpers/config.d.ts +1 -0
- package/esm/helpers/config.js +8 -0
- package/esm/helpers/config.js.map +1 -1
- package/esm/plugin-tables.d.ts +0 -3
- package/esm/plugin-tables.js +37 -8
- package/esm/plugin-tables.js.map +1 -1
- package/esm/types.d.ts +9 -7
- package/lib/blocks-helpers.d.ts +2 -2
- package/lib/blocks-helpers.js +13 -6
- package/lib/exportHtml.js +57 -6
- package/lib/exportMarkdown.js +52 -6
- package/lib/grammar.js +442 -215
- package/lib/grammarfc.js +1819 -1459
- package/lib/helpers/config.d.ts +1 -0
- package/lib/helpers/config.js +8 -0
- package/lib/plugin-tables.d.ts +0 -3
- package/lib/plugin-tables.js +37 -8
- package/lib/types.d.ts +9 -7
- package/package.json +2 -2
- package/schema/AstTree.json +6 -3
- package/schema/PodliteDocument.json +6 -3
package/lib/helpers/config.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare type Context = {
|
|
|
4
4
|
export interface Attr {
|
|
5
5
|
getAllValues: (name: any) => any;
|
|
6
6
|
getFirstValue: (name: any) => any;
|
|
7
|
+
getMapValue: (name: string) => Record<string, string | number | boolean> | undefined;
|
|
7
8
|
asHash: () => {};
|
|
8
9
|
(): {};
|
|
9
10
|
exists(name: string): boolean;
|
package/lib/helpers/config.js
CHANGED
|
@@ -43,6 +43,14 @@ const makeAttrs = (node, ctx = {}) => {
|
|
|
43
43
|
resfn.getFirstValue = name => {
|
|
44
44
|
return resfn.exists(name) ? resfn.getAllValues(name)[0] : undefined;
|
|
45
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* return first map-typed value (from `:attr{ k=>v, ... }` syntax) or
|
|
48
|
+
* undefined when the attribute is absent or not a map value
|
|
49
|
+
*/
|
|
50
|
+
resfn.getMapValue = name => {
|
|
51
|
+
const first = resfn.getFirstValue(name);
|
|
52
|
+
return first && typeof first === 'object' && !Array.isArray(first) ? first : undefined;
|
|
53
|
+
};
|
|
46
54
|
/**
|
|
47
55
|
* return key: val
|
|
48
56
|
*
|
package/lib/plugin-tables.d.ts
CHANGED
package/lib/plugin-tables.js
CHANGED
|
@@ -82,9 +82,35 @@ const extractColumnsByTemplate = (text, template) => {
|
|
|
82
82
|
/**
|
|
83
83
|
* Main transforms
|
|
84
84
|
*/
|
|
85
|
+
const wrapImplicitCells = rowNode => {
|
|
86
|
+
if (!Array.isArray(rowNode.content) || rowNode.content.length === 0)
|
|
87
|
+
return rowNode;
|
|
88
|
+
const hasNonCell = rowNode.content.some(c => c && c.type === 'block' && c.name !== 'cell' && c.name !== 'blankline');
|
|
89
|
+
if (!hasNonCell)
|
|
90
|
+
return rowNode;
|
|
91
|
+
const wrapped = rowNode.content.map(c => {
|
|
92
|
+
if (!c || c.type !== 'block')
|
|
93
|
+
return c;
|
|
94
|
+
if (c.name === 'cell' || c.name === 'blankline')
|
|
95
|
+
return c;
|
|
96
|
+
return { type: 'block', name: 'cell', content: [c], margin: c.margin || '' };
|
|
97
|
+
});
|
|
98
|
+
return { ...rowNode, content: wrapped };
|
|
99
|
+
};
|
|
100
|
+
const isStructured = tableNode => Array.isArray(tableNode.content) &&
|
|
101
|
+
tableNode.content.some(c => c && c.type === 'block' && (c.name === 'row' || c.name === 'cell'));
|
|
85
102
|
exports.default = () => tree => {
|
|
86
103
|
const transformer = (0, makeTransformer_1.default)({
|
|
87
104
|
table: node => {
|
|
105
|
+
// structured mode: transform row children (wrap implicit cells)
|
|
106
|
+
if (isStructured(node)) {
|
|
107
|
+
const transformedContent = (node.content || []).map(c => {
|
|
108
|
+
if (c && c.name === 'row')
|
|
109
|
+
return wrapImplicitCells(c);
|
|
110
|
+
return c;
|
|
111
|
+
});
|
|
112
|
+
return { ...node, content: transformedContent };
|
|
113
|
+
}
|
|
88
114
|
let rows = [];
|
|
89
115
|
const collectValues = row => {
|
|
90
116
|
rows.push(row.value);
|
|
@@ -116,9 +142,12 @@ exports.default = () => tree => {
|
|
|
116
142
|
},
|
|
117
143
|
})(node);
|
|
118
144
|
const columnTemplate = makeMask(lines, separators);
|
|
119
|
-
const makeBlock = (name, content,
|
|
120
|
-
return { ...
|
|
145
|
+
const makeBlock = (name, content, extra = {}) => {
|
|
146
|
+
return { ...extra, name, type: 'block', content: Array.isArray(content) ? content : [content] };
|
|
121
147
|
};
|
|
148
|
+
const makeRow = cells => makeBlock('row', cells);
|
|
149
|
+
const makeHeaderRow = cells => makeBlock('row', cells, { config: [{ name: 'header', value: true, type: 'boolean' }] });
|
|
150
|
+
const makeCell = text => makeBlock('cell', { type: 'text', value: text });
|
|
122
151
|
// make columns
|
|
123
152
|
const res = (0, makeTransformer_1.default)({
|
|
124
153
|
'row:text': row => {
|
|
@@ -126,16 +155,16 @@ exports.default = () => tree => {
|
|
|
126
155
|
// split each text row into lines
|
|
127
156
|
const textRowsLines = flattenDeep([row.value].map(splitToLines));
|
|
128
157
|
return textRowsLines.map(rowValue => {
|
|
129
|
-
const
|
|
130
|
-
return
|
|
158
|
+
const cols = extractColumnsByTemplate(rowValue, columnTemplate);
|
|
159
|
+
return makeRow(cols.map(makeCell));
|
|
131
160
|
});
|
|
132
161
|
}
|
|
133
|
-
const
|
|
134
|
-
return
|
|
162
|
+
const cols = extractColumnsByTemplate(row.value, columnTemplate);
|
|
163
|
+
return makeRow(cols.map(makeCell));
|
|
135
164
|
},
|
|
136
165
|
'head:text': head => {
|
|
137
|
-
const
|
|
138
|
-
return
|
|
166
|
+
const cols = extractColumnsByTemplate(head.value, columnTemplate);
|
|
167
|
+
return makeHeaderRow(cols.map(makeCell));
|
|
139
168
|
},
|
|
140
169
|
})(node);
|
|
141
170
|
return res;
|
package/lib/types.d.ts
CHANGED
|
@@ -24,7 +24,9 @@ export interface RulesStrict {
|
|
|
24
24
|
'D<>': RuleHandler<FormattingCodeD>;
|
|
25
25
|
'E<>': RuleHandler<FormattingCodeE>;
|
|
26
26
|
'F<>': RuleHandler<FormattingCodeF>;
|
|
27
|
+
'H<>': RuleHandler<FormattingCodeAny>;
|
|
27
28
|
'I<>': RuleHandler<FormattingCodeI>;
|
|
29
|
+
'J<>': RuleHandler<FormattingCodeAny>;
|
|
28
30
|
'K<>': RuleHandler<FormattingCodeAny>;
|
|
29
31
|
'R<>': RuleHandler<FormattingCodeAny>;
|
|
30
32
|
'T<>': RuleHandler<FormattingCodeAny>;
|
|
@@ -35,7 +37,7 @@ export interface RulesStrict {
|
|
|
35
37
|
'L<>': RuleHandler<FormattingCodeL>;
|
|
36
38
|
'U<>': RuleHandler<FormattingCodeAny>;
|
|
37
39
|
'Z<>': RuleHandler<FormattingCodeAny>;
|
|
38
|
-
'
|
|
40
|
+
'O<>': RuleHandler<FormattingCodeAny>;
|
|
39
41
|
pod: RuleHandler<Para>;
|
|
40
42
|
root: RuleHandler<RootBlock>;
|
|
41
43
|
':para': RuleHandler<Para>;
|
|
@@ -68,9 +70,8 @@ export interface RulesStrict {
|
|
|
68
70
|
'table:block': RuleHandler<BlockTable>;
|
|
69
71
|
table: RuleHandler<BlockTable>;
|
|
70
72
|
':separator': RuleHandler<Separator>;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
table_head: RuleHandler<TableHead>;
|
|
73
|
+
row: RuleHandler<TableRow>;
|
|
74
|
+
cell: RuleHandler<TableCell>;
|
|
74
75
|
toc: RuleHandler<BlockToc>;
|
|
75
76
|
':toc': RuleHandler<Toc>;
|
|
76
77
|
':toc-list': RuleHandler<TocList>;
|
|
@@ -100,6 +101,7 @@ export interface Image {
|
|
|
100
101
|
export interface Toc {
|
|
101
102
|
type: 'toc';
|
|
102
103
|
title?: string;
|
|
104
|
+
folded?: boolean;
|
|
103
105
|
foldedLevels?: Record<number, boolean>;
|
|
104
106
|
content: TocList;
|
|
105
107
|
}
|
|
@@ -342,17 +344,17 @@ export interface BlockTable extends Omit<Block, 'content'> {
|
|
|
342
344
|
text?: string;
|
|
343
345
|
}
|
|
344
346
|
export interface TableCell {
|
|
345
|
-
name: '
|
|
347
|
+
name: 'cell';
|
|
346
348
|
type: 'block';
|
|
347
349
|
content: Array<string>;
|
|
348
350
|
}
|
|
349
351
|
export interface TableRow {
|
|
350
|
-
name: '
|
|
352
|
+
name: 'row';
|
|
351
353
|
type: 'block';
|
|
352
354
|
content: Array<TableCell>;
|
|
353
355
|
}
|
|
354
356
|
export interface TableHead {
|
|
355
|
-
name: '
|
|
357
|
+
name: 'row';
|
|
356
358
|
type: 'block';
|
|
357
359
|
content: Array<TableCell>;
|
|
358
360
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@podlite/schema",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"description": "AST tools and schema for Podlite markup language — validate, traverse, and transform document trees",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"homepage": "https://podlite.org",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"@types/node": "^17.0.7",
|
|
69
69
|
"glob": "^7.2.0",
|
|
70
70
|
"npm-run-all": "^4.1.5",
|
|
71
|
-
"pegmill": "0.1.
|
|
71
|
+
"pegmill": "0.1.2",
|
|
72
72
|
"ts-node": "^9.1.1",
|
|
73
73
|
"typescript": "4.5.5",
|
|
74
74
|
"typescript-json-schema": "0.53.0"
|
package/schema/AstTree.json
CHANGED
|
@@ -1521,7 +1521,7 @@
|
|
|
1521
1521
|
"name": {
|
|
1522
1522
|
"type": "string",
|
|
1523
1523
|
"enum": [
|
|
1524
|
-
"
|
|
1524
|
+
"row"
|
|
1525
1525
|
]
|
|
1526
1526
|
},
|
|
1527
1527
|
"type": {
|
|
@@ -1549,7 +1549,7 @@
|
|
|
1549
1549
|
"name": {
|
|
1550
1550
|
"type": "string",
|
|
1551
1551
|
"enum": [
|
|
1552
|
-
"
|
|
1552
|
+
"cell"
|
|
1553
1553
|
]
|
|
1554
1554
|
},
|
|
1555
1555
|
"type": {
|
|
@@ -1577,7 +1577,7 @@
|
|
|
1577
1577
|
"name": {
|
|
1578
1578
|
"type": "string",
|
|
1579
1579
|
"enum": [
|
|
1580
|
-
"
|
|
1580
|
+
"row"
|
|
1581
1581
|
]
|
|
1582
1582
|
},
|
|
1583
1583
|
"type": {
|
|
@@ -2688,6 +2688,9 @@
|
|
|
2688
2688
|
"title": {
|
|
2689
2689
|
"type": "string"
|
|
2690
2690
|
},
|
|
2691
|
+
"folded": {
|
|
2692
|
+
"type": "boolean"
|
|
2693
|
+
},
|
|
2691
2694
|
"foldedLevels": {
|
|
2692
2695
|
"type": "object",
|
|
2693
2696
|
"additionalProperties": false,
|
|
@@ -1521,7 +1521,7 @@
|
|
|
1521
1521
|
"name": {
|
|
1522
1522
|
"type": "string",
|
|
1523
1523
|
"enum": [
|
|
1524
|
-
"
|
|
1524
|
+
"row"
|
|
1525
1525
|
]
|
|
1526
1526
|
},
|
|
1527
1527
|
"type": {
|
|
@@ -1549,7 +1549,7 @@
|
|
|
1549
1549
|
"name": {
|
|
1550
1550
|
"type": "string",
|
|
1551
1551
|
"enum": [
|
|
1552
|
-
"
|
|
1552
|
+
"cell"
|
|
1553
1553
|
]
|
|
1554
1554
|
},
|
|
1555
1555
|
"type": {
|
|
@@ -1577,7 +1577,7 @@
|
|
|
1577
1577
|
"name": {
|
|
1578
1578
|
"type": "string",
|
|
1579
1579
|
"enum": [
|
|
1580
|
-
"
|
|
1580
|
+
"row"
|
|
1581
1581
|
]
|
|
1582
1582
|
},
|
|
1583
1583
|
"type": {
|
|
@@ -2688,6 +2688,9 @@
|
|
|
2688
2688
|
"title": {
|
|
2689
2689
|
"type": "string"
|
|
2690
2690
|
},
|
|
2691
|
+
"folded": {
|
|
2692
|
+
"type": "boolean"
|
|
2693
|
+
},
|
|
2691
2694
|
"foldedLevels": {
|
|
2692
2695
|
"type": "object",
|
|
2693
2696
|
"additionalProperties": false,
|