@podlite/schema 0.0.10 → 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 -0
- package/LICENSE +1 -1
- package/lib/ast-helpers.d.ts +1 -0
- package/lib/ast-helpers.js +3 -2
- package/lib/ast-inerator.js +2 -2
- package/lib/exportAny.d.ts +19 -0
- package/lib/exportAny.js +64 -0
- package/lib/exportHtml.d.ts +15 -0
- package/lib/exportHtml.js +277 -0
- package/lib/grammar.d.ts +14 -0
- package/lib/grammar.js +6395 -0
- package/lib/grammarfc.d.ts +14 -0
- package/lib/grammarfc.js +3362 -0
- package/lib/helpers/config.d.ts +12 -0
- package/lib/helpers/config.js +51 -0
- package/lib/helpers/handlers.d.ts +47 -0
- package/lib/helpers/handlers.js +119 -0
- package/lib/helpers/makeInterator.d.ts +5 -0
- package/lib/helpers/makeInterator.js +51 -0
- package/lib/helpers/makeQuery.d.ts +47 -0
- package/lib/helpers/makeQuery.js +103 -0
- package/lib/helpers/makeQuery.test.d.ts +1 -0
- package/lib/helpers/makeQuery.test.js +41 -0
- package/lib/helpers/makeTransformer.d.ts +7 -0
- package/lib/helpers/makeTransformer.js +70 -0
- package/lib/index.d.ts +61 -0
- package/lib/index.js +71 -1
- package/lib/plugin-clean-location.d.ts +2 -0
- package/lib/plugin-clean-location.js +23 -0
- package/lib/plugin-defn-fill-term.d.ts +2 -0
- package/lib/plugin-defn-fill-term.js +52 -0
- package/lib/plugin-formatting-codes.d.ts +3 -0
- package/lib/plugin-formatting-codes.js +48 -0
- package/lib/plugin-group-defn.d.ts +2 -0
- package/lib/plugin-group-defn.js +73 -0
- package/lib/plugin-group-items.d.ts +2 -0
- package/lib/plugin-group-items.js +82 -0
- package/lib/plugin-heading.d.ts +2 -0
- package/lib/plugin-heading.js +32 -0
- package/lib/plugin-items.d.ts +2 -0
- package/lib/plugin-items.js +40 -0
- package/lib/plugin-tables.d.ts +5 -0
- package/lib/plugin-tables.js +131 -0
- package/lib/plugin-vmargin.d.ts +3 -0
- package/lib/plugin-vmargin.js +29 -0
- package/lib/query-helpers.d.ts +2 -1
- package/lib/query-helpers.js +2 -5
- package/lib/writer.d.ts +30 -0
- package/lib/writer.js +91 -0
- package/lib/writerHtml.d.ts +11 -0
- package/lib/writerHtml.js +33 -0
- package/package.json +13 -4
- package/lib/helpers.d.ts +0 -1
- package/lib/helpers.js +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
# @podlite/schema
|
|
2
2
|
|
|
3
3
|
## Upcoming
|
|
4
|
+
## 0.0.12
|
|
5
|
+
- add helpers,
|
|
6
|
+
- fix parser's grammars
|
|
7
|
+
- add tests
|
|
8
|
+
- update deps
|
|
9
|
+
## 0.0.11
|
|
10
|
+
- extend API by context for react component wrap function
|
|
4
11
|
## 0.0.10
|
|
5
12
|
- fix helper for mkBlock
|
|
6
13
|
- add Strikethrough inline element support
|
package/LICENSE
CHANGED
package/lib/ast-helpers.d.ts
CHANGED
package/lib/ast-helpers.js
CHANGED
|
@@ -3,8 +3,8 @@ 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.getNodeId = void 0;
|
|
7
|
-
const config_1 = __importDefault(require("
|
|
6
|
+
exports.makeAttrs = exports.getNodeId = void 0;
|
|
7
|
+
const config_1 = __importDefault(require("./helpers/config"));
|
|
8
8
|
const getNodeId = (node, ctx) => {
|
|
9
9
|
const conf = (0, config_1.default)(node, ctx);
|
|
10
10
|
if (conf.exists('id')) {
|
|
@@ -13,3 +13,4 @@ const getNodeId = (node, ctx) => {
|
|
|
13
13
|
return node.id;
|
|
14
14
|
};
|
|
15
15
|
exports.getNodeId = getNodeId;
|
|
16
|
+
exports.makeAttrs = config_1.default;
|
package/lib/ast-inerator.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeInterator = exports.isSemanticBlock = exports.isNamedBlock = void 0;
|
|
4
|
-
const
|
|
4
|
+
const makeQuery_1 = require("./helpers/makeQuery");
|
|
5
5
|
// the following names: MyBlock, myBlock are use for extending pod6
|
|
6
6
|
function isNamedBlock(name) {
|
|
7
7
|
return (name
|
|
@@ -35,7 +35,7 @@ const makeInterator = (rule) => {
|
|
|
35
35
|
}
|
|
36
36
|
return [];
|
|
37
37
|
}
|
|
38
|
-
rules.push(makeRule(makePlug(key), fn));
|
|
38
|
+
rules.push((0, makeQuery_1.makeRule)((0, makeQuery_1.makePlug)(key), fn));
|
|
39
39
|
}
|
|
40
40
|
function visiter(node, context = {}) {
|
|
41
41
|
if (node instanceof Array) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare type Options = {
|
|
2
|
+
processor?: any;
|
|
3
|
+
writer?: any;
|
|
4
|
+
};
|
|
5
|
+
export declare const toAny: (options?: Options, plugins?: any[]) => {
|
|
6
|
+
(root: any): void;
|
|
7
|
+
use: (key: any, fn?: any) => any;
|
|
8
|
+
run: (src: any, opt_writer?: any) => {
|
|
9
|
+
errors: any;
|
|
10
|
+
toString: () => string;
|
|
11
|
+
valueOf: () => string;
|
|
12
|
+
indexingTerms: any;
|
|
13
|
+
annotations: any;
|
|
14
|
+
defenitions: any;
|
|
15
|
+
interator: any;
|
|
16
|
+
};
|
|
17
|
+
getPlugins(): any[];
|
|
18
|
+
};
|
|
19
|
+
export default toAny;
|
package/lib/exportAny.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
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.toAny = void 0;
|
|
7
|
+
const makeQuery_1 = require("./helpers/makeQuery");
|
|
8
|
+
const makeInterator_1 = __importDefault(require("./helpers/makeInterator"));
|
|
9
|
+
const writer_1 = __importDefault(require("./writer"));
|
|
10
|
+
const _1 = require("./");
|
|
11
|
+
const toAny = (options = {}, plugins = []) => {
|
|
12
|
+
let fns = plugins;
|
|
13
|
+
// setup pod6 processor
|
|
14
|
+
const processor = options.processor || _1.parse;
|
|
15
|
+
const _writer = options.writer;
|
|
16
|
+
chain.use = use;
|
|
17
|
+
chain.run = run;
|
|
18
|
+
chain.getPlugins = () => fns;
|
|
19
|
+
return chain;
|
|
20
|
+
function chain(root) {
|
|
21
|
+
}
|
|
22
|
+
function use(key, fn) {
|
|
23
|
+
if (key instanceof Array) {
|
|
24
|
+
return (0, exports.toAny)(options, [...fns, ...fn]);
|
|
25
|
+
}
|
|
26
|
+
if (key instanceof Object) {
|
|
27
|
+
for (var prop in key) {
|
|
28
|
+
if (key.hasOwnProperty(prop)) {
|
|
29
|
+
use(prop, key[prop]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return chain;
|
|
33
|
+
}
|
|
34
|
+
fns.push((0, makeQuery_1.makeRule)((0, makeQuery_1.makePlug)(key), fn));
|
|
35
|
+
return chain;
|
|
36
|
+
}
|
|
37
|
+
function run(src, opt_writer) {
|
|
38
|
+
let res = '';
|
|
39
|
+
const _tmp_writer = opt_writer || _writer || new writer_1.default((s) => { res = res + s; });
|
|
40
|
+
const writer = ('function' === typeof _tmp_writer) ? new _tmp_writer((s) => { res = res + s; }) : _tmp_writer;
|
|
41
|
+
// src may be preparsed tree
|
|
42
|
+
const tree = ("string" === typeof src) ? processor(src) : src;
|
|
43
|
+
// make new instance of HTML with initialized plugins
|
|
44
|
+
// reverse init
|
|
45
|
+
let newFns = fns.slice();
|
|
46
|
+
newFns.reverse();
|
|
47
|
+
const interator = (0, makeInterator_1.default)(newFns.map(rule => (0, makeQuery_1.makeRule)(rule.rule, rule.fn(writer, processor, tree))).reverse());
|
|
48
|
+
const context = {};
|
|
49
|
+
writer.startWrite(tree);
|
|
50
|
+
const result = interator(tree, context);
|
|
51
|
+
writer.endWrite();
|
|
52
|
+
return {
|
|
53
|
+
errors: writer.errors,
|
|
54
|
+
toString: () => res,
|
|
55
|
+
valueOf: () => res,
|
|
56
|
+
indexingTerms: writer.INDEXTERMS,
|
|
57
|
+
annotations: writer.FOOTNOTES,
|
|
58
|
+
defenitions: writer.DEFINITIONS,
|
|
59
|
+
interator: result
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
exports.toAny = toAny;
|
|
64
|
+
exports.default = exports.toAny;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const toHtml: (opt: any) => {
|
|
2
|
+
(root: any): void;
|
|
3
|
+
use: (key: any, fn?: any) => any;
|
|
4
|
+
run: (src: any, opt_writer?: any) => {
|
|
5
|
+
errors: any;
|
|
6
|
+
toString: () => string;
|
|
7
|
+
valueOf: () => string;
|
|
8
|
+
indexingTerms: any;
|
|
9
|
+
annotations: any;
|
|
10
|
+
defenitions: any;
|
|
11
|
+
interator: any;
|
|
12
|
+
};
|
|
13
|
+
getPlugins(): any[];
|
|
14
|
+
};
|
|
15
|
+
export default toHtml;
|
|
@@ -0,0 +1,277 @@
|
|
|
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
|
+
const exportAny_1 = __importDefault(require("./exportAny"));
|
|
7
|
+
const handlers_1 = require("./helpers/handlers");
|
|
8
|
+
const makeTransformer_1 = require("./helpers/makeTransformer");
|
|
9
|
+
const config_1 = __importDefault(require("./helpers/config"));
|
|
10
|
+
const writerHtml_1 = __importDefault(require("./writerHtml"));
|
|
11
|
+
const plugin_clean_location_1 = __importDefault(require("./plugin-clean-location"));
|
|
12
|
+
const ast_helpers_1 = require("./ast-helpers");
|
|
13
|
+
const rules = {
|
|
14
|
+
':text': (writer, processor) => (node, ctx, interator) => {
|
|
15
|
+
// handle text with content
|
|
16
|
+
if (node.value) {
|
|
17
|
+
writer.write(node.value);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
interator(node.content, ctx);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
// Formatting codes
|
|
24
|
+
'A<>': (writer, processor) => (node, ctx, interator) => {
|
|
25
|
+
//get replacement text
|
|
26
|
+
if (!(ctx.alias && ctx.alias.hasOwnProperty(node.content))) {
|
|
27
|
+
writer.write(`A<${node.content}>`);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const src = ctx.alias[node.content].join('\n');
|
|
31
|
+
const tree_1 = processor(src);
|
|
32
|
+
// now clean locations
|
|
33
|
+
const tree = (0, plugin_clean_location_1.default)()(tree_1);
|
|
34
|
+
if (tree[0].type === 'para') {
|
|
35
|
+
interator(tree[0].content, ctx);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
interator(tree, ctx);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
'C<>': (0, handlers_1.wrapContent)('<code>', '</code>'),
|
|
43
|
+
'D<>': (writer, processor) => (node, ctx, interator) => {
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
let synonyms = { node };
|
|
46
|
+
let definition = [node.content[0]];
|
|
47
|
+
if (synonyms) {
|
|
48
|
+
definition = synonyms;
|
|
49
|
+
}
|
|
50
|
+
if (!writer.hasOwnProperty('DEFINITIONS')) {
|
|
51
|
+
writer.DEFINITIONS = [];
|
|
52
|
+
}
|
|
53
|
+
writer.DEFINITIONS.push({ definition });
|
|
54
|
+
writer.writeRaw('<dfn>');
|
|
55
|
+
interator(node.content, ctx);
|
|
56
|
+
writer.writeRaw('</dfn>');
|
|
57
|
+
},
|
|
58
|
+
'B<>': (0, handlers_1.wrapContent)('<strong>', '</strong>'),
|
|
59
|
+
'I<>': (0, handlers_1.wrapContent)('<em>', '</em>'),
|
|
60
|
+
'R<>': (0, handlers_1.wrapContent)('<var>', '</var>'),
|
|
61
|
+
'K<>': (0, handlers_1.wrapContent)('<kbd>', '</kbd>'),
|
|
62
|
+
"L<>": (0, handlers_1.setFn)((node, ctx) => {
|
|
63
|
+
let { meta } = node;
|
|
64
|
+
if (meta === null) {
|
|
65
|
+
meta = node.content;
|
|
66
|
+
}
|
|
67
|
+
return (0, handlers_1.wrapContent)(`<a href="${meta}">`, `</a>`);
|
|
68
|
+
}),
|
|
69
|
+
/**
|
|
70
|
+
* CSS rules for footnotes
|
|
71
|
+
|
|
72
|
+
.footnote a {
|
|
73
|
+
text-decoration: none;
|
|
74
|
+
}
|
|
75
|
+
.footnotes {
|
|
76
|
+
border-top-style: solid;
|
|
77
|
+
border-top-width: 1px;
|
|
78
|
+
border-top-color: #eee;
|
|
79
|
+
}
|
|
80
|
+
*/
|
|
81
|
+
'N<>': (writer, processor) => {
|
|
82
|
+
writer.addListener('end', () => {
|
|
83
|
+
if (!writer.hasOwnProperty('FOOTNOTES')) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const footnotes = writer.FOOTNOTES;
|
|
87
|
+
if (footnotes.length < 1) {
|
|
88
|
+
return;
|
|
89
|
+
} // if empty footnotes
|
|
90
|
+
writer.writeRaw(`<div class="footnotes">`);
|
|
91
|
+
footnotes.map((footnote) => {
|
|
92
|
+
writer.writeRaw(`<p><sup id="${footnote.fnId}" class="footnote"><a href="#${footnote.fnRefId}">[${footnote.gid}]</a></sup> `);
|
|
93
|
+
footnote.make();
|
|
94
|
+
writer.writeRaw(`</p>`);
|
|
95
|
+
});
|
|
96
|
+
writer.writeRaw(`</div>`);
|
|
97
|
+
});
|
|
98
|
+
return (node, ctx, interator) => {
|
|
99
|
+
// skip empty notes
|
|
100
|
+
if (node.content.length < 1) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (!writer.hasOwnProperty('gid')) {
|
|
104
|
+
writer.gid = 1;
|
|
105
|
+
}
|
|
106
|
+
// get foot note id
|
|
107
|
+
const gid = writer.gid++;
|
|
108
|
+
const fnRefId = `fnref:${gid}`;
|
|
109
|
+
const fnId = `fn:${gid}`;
|
|
110
|
+
writer.writeRaw(`<sup id="${fnRefId}" class="footnote"><a href="#${fnId}">[${gid}]</a></sup>`);
|
|
111
|
+
if (!writer.hasOwnProperty('FOOTNOTES')) {
|
|
112
|
+
writer.FOOTNOTES = [];
|
|
113
|
+
}
|
|
114
|
+
writer.FOOTNOTES.push({
|
|
115
|
+
gid,
|
|
116
|
+
fnRefId,
|
|
117
|
+
fnId,
|
|
118
|
+
make: () => { interator(node.content, ctx); }
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
'S<>': (writer, processor) => (node, ctx, interator) => {
|
|
123
|
+
const content = node.content || '';
|
|
124
|
+
const spaces = content.replace(/ /g, ' ');
|
|
125
|
+
const newFeed = spaces.replace(/\n/g, '</br>');
|
|
126
|
+
writer.writeRaw(newFeed);
|
|
127
|
+
},
|
|
128
|
+
'T<>': (0, handlers_1.wrapContent)('<samp>', '</samp>'),
|
|
129
|
+
'U<>': (0, handlers_1.wrapContent)('<u>', '</u>'),
|
|
130
|
+
'V<>': handlers_1.content,
|
|
131
|
+
'X<>': (writer, processor) => (node, ctx, interator) => {
|
|
132
|
+
interator(node.content, ctx);
|
|
133
|
+
let { entry } = node;
|
|
134
|
+
if (entry === null && node.content.length > 0) {
|
|
135
|
+
//@ts-ignore
|
|
136
|
+
entry = [node.content[0]];
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (!writer.hasOwnProperty('INDEXTERMS')) {
|
|
142
|
+
writer.INDEXTERMS = [];
|
|
143
|
+
}
|
|
144
|
+
writer.INDEXTERMS.push({
|
|
145
|
+
entry
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
'Z<>': handlers_1.emptyContent,
|
|
149
|
+
'pod': handlers_1.content,
|
|
150
|
+
':code': (0, handlers_1.wrapContent)('<pre><code>', '</code></pre>'),
|
|
151
|
+
'code': (0, handlers_1.handleNested)((0, handlers_1.wrapContent)('<pre><code>', '</code></pre>')),
|
|
152
|
+
'data': handlers_1.emptyContent,
|
|
153
|
+
':verbatim': (writer, processor) => (node, ctx, interator) => {
|
|
154
|
+
if (node.error) {
|
|
155
|
+
writer.emit("errors", node.location);
|
|
156
|
+
}
|
|
157
|
+
interator(node.value);
|
|
158
|
+
},
|
|
159
|
+
':blankline': handlers_1.emptyContent,
|
|
160
|
+
':ambient': handlers_1.emptyContent,
|
|
161
|
+
// Directives
|
|
162
|
+
':config': (0, handlers_1.setFn)((node, ctx) => {
|
|
163
|
+
// setup context
|
|
164
|
+
if (!ctx.hasOwnProperty('config'))
|
|
165
|
+
ctx.config = {};
|
|
166
|
+
//collect configs in context
|
|
167
|
+
ctx.config[node.name] = node.config;
|
|
168
|
+
return handlers_1.emptyContent;
|
|
169
|
+
}),
|
|
170
|
+
':alias': (0, handlers_1.setFn)((node, ctx) => {
|
|
171
|
+
// set alias
|
|
172
|
+
if (!ctx.hasOwnProperty('alias'))
|
|
173
|
+
ctx.alias = {};
|
|
174
|
+
//collect configs in context
|
|
175
|
+
ctx.alias[node.name] = node.replacement;
|
|
176
|
+
return handlers_1.emptyContent;
|
|
177
|
+
}),
|
|
178
|
+
// block =para
|
|
179
|
+
'para': (0, handlers_1.handleNested)(handlers_1.content),
|
|
180
|
+
':para': (0, handlers_1.wrapContent)('<p>', '</p>'),
|
|
181
|
+
'head:block': (0, handlers_1.subUse)({
|
|
182
|
+
// inside head don't wrap into <p>
|
|
183
|
+
':para': handlers_1.content,
|
|
184
|
+
}, (0, handlers_1.setFn)((node, ctx) => {
|
|
185
|
+
const { level } = node;
|
|
186
|
+
const id = (0, ast_helpers_1.getNodeId)(node, ctx);
|
|
187
|
+
return (0, handlers_1.wrapContent)(`<h${level}${id ? ` id="${id}"` : ''}>`, `</h${level}>`);
|
|
188
|
+
})),
|
|
189
|
+
':list': (0, handlers_1.setFn)((node, ctx) => node.list === 'ordered' ? (0, handlers_1.wrapContent)('<ol>', '</ol>')
|
|
190
|
+
: node.list === 'variable' ? (0, handlers_1.wrapContent)('<dl>', '</dl>')
|
|
191
|
+
: (0, handlers_1.wrapContent)('<ul>', '</ul>')),
|
|
192
|
+
'item:block': (writer, processor) => (node, ctx, interator) => {
|
|
193
|
+
// make text from first para
|
|
194
|
+
if (!(node.content instanceof Array)) {
|
|
195
|
+
console.error('[pod6] item:block : Error in content of ' + JSON.stringify(node));
|
|
196
|
+
}
|
|
197
|
+
const [firstPara, ...other] = node.content;
|
|
198
|
+
writer.writeRaw('<li>');
|
|
199
|
+
// TODO: get cases for handle first para in items
|
|
200
|
+
// interator([...firstPara.content, ...other], ctx)
|
|
201
|
+
interator(node.content, ctx);
|
|
202
|
+
writer.writeRaw('</li>');
|
|
203
|
+
},
|
|
204
|
+
'comment:block': handlers_1.emptyContent,
|
|
205
|
+
'defn': (0, handlers_1.wrapContent)('', '</dd>'),
|
|
206
|
+
'term:para': (0, handlers_1.wrapContent)('<dt>', '</dt><dd>'),
|
|
207
|
+
'nested': (0, handlers_1.handleNested)(handlers_1.content, 1),
|
|
208
|
+
'output': (0, handlers_1.handleNested)((0, handlers_1.wrapContent)('<pre><samp>', '</samp></pre>'), 1),
|
|
209
|
+
'input': (0, handlers_1.handleNested)((0, handlers_1.wrapContent)('<pre><kbd>', '</kbd></pre>'), 1),
|
|
210
|
+
// table section
|
|
211
|
+
'table:block': (0, handlers_1.handleNested)((writer, processor) => (node, ctx, interator) => {
|
|
212
|
+
const conf = (0, config_1.default)(node, ctx);
|
|
213
|
+
writer.writeRaw('<table>');
|
|
214
|
+
if (conf.exists('caption')) {
|
|
215
|
+
writer.writeRaw('<caption>');
|
|
216
|
+
writer.write(conf.getFirstValue('caption'));
|
|
217
|
+
writer.writeRaw('</caption>');
|
|
218
|
+
}
|
|
219
|
+
interator(node.content, ctx);
|
|
220
|
+
writer.writeRaw('</table>');
|
|
221
|
+
}),
|
|
222
|
+
':separator': handlers_1.emptyContent,
|
|
223
|
+
'table_row': (0, handlers_1.wrapContent)('<tr>', '</tr>'),
|
|
224
|
+
'table_cell': (0, handlers_1.wrapContent)('<td>', '</td>'),
|
|
225
|
+
'table_head': (0, handlers_1.subUse)({
|
|
226
|
+
'table_cell': (0, handlers_1.wrapContent)('<th>', '</th>')
|
|
227
|
+
}, (0, handlers_1.wrapContent)('<tr>', '</tr>')),
|
|
228
|
+
// Toc
|
|
229
|
+
':toc': (writer, processor) => (node, ctx, interator) => {
|
|
230
|
+
writer.writeRaw('<div className="toc">');
|
|
231
|
+
// get toc title
|
|
232
|
+
const conf = (0, config_1.default)(node, ctx);
|
|
233
|
+
if (conf.exists('title')) {
|
|
234
|
+
const title = conf.getFirstValue('title');
|
|
235
|
+
writer.writeRaw('<div className="toctitle">');
|
|
236
|
+
writer.write(title);
|
|
237
|
+
writer.writeRaw('</div>');
|
|
238
|
+
}
|
|
239
|
+
interator(node.content, ctx);
|
|
240
|
+
writer.writeRaw('</div>');
|
|
241
|
+
},
|
|
242
|
+
':toc-list': (0, handlers_1.setFn)((node, ctx) => (0, handlers_1.wrapContent)(`<ul class="toc-list listlevel${node.level}">`, '</ul>')),
|
|
243
|
+
':toc-item': (0, handlers_1.setFn)((node, ctx) => (0, handlers_1.wrapContent)('<li class="toc-item">', '</li>')),
|
|
244
|
+
':image': (writer, processor) => (node, ctx, interator) => {
|
|
245
|
+
writer.writeRaw(`<img src="${node.src}" alt="${node.alt}"/>`);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
const toHtml = (opt) => (0, exportAny_1.default)({ writer: writerHtml_1.default, ...opt }).use('*', (writer, processor) => {
|
|
249
|
+
return (node, ctx, interator) => {
|
|
250
|
+
// skip warnings for semantic blocks
|
|
251
|
+
const isSemanticBlock = (node) => {
|
|
252
|
+
const name = node.name || '';
|
|
253
|
+
const isTypeBlock = (node.type || '') === 'block';
|
|
254
|
+
return isTypeBlock && name === name.toUpperCase();
|
|
255
|
+
};
|
|
256
|
+
//Named blocks for which no explicit class has been defined or loaded are
|
|
257
|
+
//usually not rendered by the standard renderers.
|
|
258
|
+
if ((0, makeTransformer_1.isNamedBlock)(node.name)) {
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
if (isSemanticBlock(node)) {
|
|
262
|
+
const name = node.name;
|
|
263
|
+
writer.writeRaw('<h1 class="');
|
|
264
|
+
writer.write(name);
|
|
265
|
+
writer.writeRaw('">');
|
|
266
|
+
writer.write(name);
|
|
267
|
+
writer.writeRaw('</h1>');
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
console.warn("[pod6] Unhandled node" + JSON.stringify(node, null, 2));
|
|
271
|
+
}
|
|
272
|
+
if (node.hasOwnProperty('content')) {
|
|
273
|
+
interator(node.content, ctx);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
}).use(rules);
|
|
277
|
+
exports.default = toHtml;
|
package/lib/grammar.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare function peg$SyntaxError(message: any, expected: any, found: any, location: any): void;
|
|
2
|
+
declare class peg$SyntaxError {
|
|
3
|
+
constructor(message: any, expected: any, found: any, location: any);
|
|
4
|
+
message: any;
|
|
5
|
+
expected: any;
|
|
6
|
+
found: any;
|
|
7
|
+
location: any;
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
declare namespace peg$SyntaxError {
|
|
11
|
+
function buildMessage(expected: any, found: any): string;
|
|
12
|
+
}
|
|
13
|
+
declare function peg$parse(input: any, options: any): any;
|
|
14
|
+
export { peg$SyntaxError as SyntaxError, peg$parse as parse };
|