@podlite/schema 0.0.11 → 0.0.13

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.
Files changed (70) hide show
  1. package/CHANGELOG.md +36 -4
  2. package/LICENSE +1 -1
  3. package/README.md +40 -0
  4. package/lib/ast-helpers.d.ts +1 -1
  5. package/lib/ast-helpers.js +2 -1
  6. package/lib/ast-inerator.d.ts +0 -1
  7. package/lib/ast-inerator.js +7 -15
  8. package/lib/blocks-helpers.d.ts +1 -1
  9. package/lib/blocks-helpers.js +15 -12
  10. package/lib/exportAny.d.ts +19 -0
  11. package/lib/exportAny.js +72 -0
  12. package/lib/exportHtml.d.ts +15 -0
  13. package/lib/exportHtml.js +284 -0
  14. package/lib/grammar.d.ts +14 -0
  15. package/lib/grammar.js +6396 -0
  16. package/lib/grammarfc.d.ts +14 -0
  17. package/lib/grammarfc.js +3363 -0
  18. package/lib/helpers/config.d.ts +12 -0
  19. package/lib/helpers/config.js +56 -0
  20. package/lib/helpers/corePlugins.d.ts +12 -0
  21. package/lib/helpers/corePlugins.js +26 -0
  22. package/lib/helpers/handlers.d.ts +47 -0
  23. package/lib/helpers/handlers.js +120 -0
  24. package/lib/helpers/ids.d.ts +18 -0
  25. package/lib/helpers/ids.js +74 -0
  26. package/lib/helpers/makeInterator.d.ts +5 -0
  27. package/lib/helpers/makeInterator.js +54 -0
  28. package/lib/helpers/makeQuery.d.ts +47 -0
  29. package/lib/helpers/makeQuery.js +107 -0
  30. package/lib/helpers/makeQuery.test.d.ts +1 -0
  31. package/lib/helpers/makeQuery.test.js +51 -0
  32. package/lib/helpers/makeTransformer.d.ts +7 -0
  33. package/lib/helpers/makeTransformer.js +67 -0
  34. package/lib/helpers/plugins.d.ts +2 -0
  35. package/lib/helpers/plugins.js +27 -0
  36. package/lib/index.d.ts +64 -0
  37. package/lib/index.js +85 -5
  38. package/lib/pluggableParser.d.ts +27 -0
  39. package/lib/pluggableParser.js +80 -0
  40. package/lib/plugin-clean-location.d.ts +2 -0
  41. package/lib/plugin-clean-location.js +26 -0
  42. package/lib/plugin-defn-fill-term.d.ts +2 -0
  43. package/lib/plugin-defn-fill-term.js +55 -0
  44. package/lib/plugin-formatting-codes.d.ts +3 -0
  45. package/lib/plugin-formatting-codes.js +76 -0
  46. package/lib/plugin-group-defn.d.ts +2 -0
  47. package/lib/plugin-group-defn.js +73 -0
  48. package/lib/plugin-group-items.d.ts +2 -0
  49. package/lib/plugin-group-items.js +84 -0
  50. package/lib/plugin-heading.d.ts +2 -0
  51. package/lib/plugin-heading.js +35 -0
  52. package/lib/plugin-items.d.ts +2 -0
  53. package/lib/plugin-items.js +43 -0
  54. package/lib/plugin-tables.d.ts +5 -0
  55. package/lib/plugin-tables.js +146 -0
  56. package/lib/plugin-vmargin.d.ts +3 -0
  57. package/lib/plugin-vmargin.js +31 -0
  58. package/lib/query-helpers.d.ts +2 -1
  59. package/lib/query-helpers.js +10 -10
  60. package/lib/types.d.ts +69 -69
  61. package/lib/types.js +1 -0
  62. package/lib/writer.d.ts +30 -0
  63. package/lib/writer.js +106 -0
  64. package/lib/writerHtml.d.ts +11 -0
  65. package/lib/writerHtml.js +34 -0
  66. package/package.json +18 -10
  67. package/schema/index.d.ts +3 -3
  68. package/index.js +0 -2
  69. package/lib/helpers.d.ts +0 -1
  70. package/lib/helpers.js +0 -5
@@ -0,0 +1,284 @@
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: () => {
119
+ interator(node.content, ctx);
120
+ },
121
+ });
122
+ };
123
+ },
124
+ 'S<>': (writer, processor) => (node, ctx, interator) => {
125
+ const content = node.content || '';
126
+ const spaces = content.replace(/ /g, '&nbsp;');
127
+ const newFeed = spaces.replace(/\n/g, '</br>');
128
+ writer.writeRaw(newFeed);
129
+ },
130
+ 'T<>': (0, handlers_1.wrapContent)('<samp>', '</samp>'),
131
+ 'U<>': (0, handlers_1.wrapContent)('<u>', '</u>'),
132
+ 'V<>': handlers_1.content,
133
+ 'X<>': (writer, processor) => (node, ctx, interator) => {
134
+ interator(node.content, ctx);
135
+ let { entry } = node;
136
+ if (entry === null && node.content.length > 0) {
137
+ //@ts-ignore
138
+ entry = [node.content[0]];
139
+ }
140
+ else {
141
+ return;
142
+ }
143
+ if (!writer.hasOwnProperty('INDEXTERMS')) {
144
+ writer.INDEXTERMS = [];
145
+ }
146
+ writer.INDEXTERMS.push({
147
+ entry,
148
+ });
149
+ },
150
+ 'Z<>': handlers_1.emptyContent,
151
+ pod: handlers_1.content,
152
+ ':code': (0, handlers_1.wrapContent)('<pre><code>', '</code></pre>'),
153
+ code: (0, handlers_1.handleNested)((0, handlers_1.wrapContent)('<pre><code>', '</code></pre>')),
154
+ data: handlers_1.emptyContent,
155
+ ':verbatim': (writer, processor) => (node, ctx, interator) => {
156
+ if (node.error) {
157
+ writer.emit('errors', node.location);
158
+ }
159
+ interator(node.value);
160
+ },
161
+ ':blankline': handlers_1.emptyContent,
162
+ ':ambient': handlers_1.emptyContent,
163
+ // Directives
164
+ ':config': (0, handlers_1.setFn)((node, ctx) => {
165
+ // setup context
166
+ if (!ctx.hasOwnProperty('config'))
167
+ ctx.config = {};
168
+ //collect configs in context
169
+ ctx.config[node.name] = node.config;
170
+ return handlers_1.emptyContent;
171
+ }),
172
+ ':alias': (0, handlers_1.setFn)((node, ctx) => {
173
+ // set alias
174
+ if (!ctx.hasOwnProperty('alias'))
175
+ ctx.alias = {};
176
+ //collect configs in context
177
+ ctx.alias[node.name] = node.replacement;
178
+ return handlers_1.emptyContent;
179
+ }),
180
+ // block =para
181
+ para: (0, handlers_1.handleNested)(handlers_1.content),
182
+ ':para': (0, handlers_1.wrapContent)('<p>', '</p>'),
183
+ 'head:block': (0, handlers_1.subUse)({
184
+ // inside head don't wrap into <p>
185
+ ':para': handlers_1.content,
186
+ }, (0, handlers_1.setFn)((node, ctx) => {
187
+ const { level } = node;
188
+ const id = (0, ast_helpers_1.getNodeId)(node, ctx);
189
+ return (0, handlers_1.wrapContent)(`<h${level}${id ? ` id="${id}"` : ''}>`, `</h${level}>`);
190
+ })),
191
+ ':list': (0, handlers_1.setFn)((node, ctx) => node.list === 'ordered'
192
+ ? (0, handlers_1.wrapContent)('<ol>', '</ol>')
193
+ : node.list === 'variable'
194
+ ? (0, handlers_1.wrapContent)('<dl>', '</dl>')
195
+ : (0, handlers_1.wrapContent)('<ul>', '</ul>')),
196
+ 'item:block': (writer, processor) => (node, ctx, interator) => {
197
+ // make text from first para
198
+ if (!(node.content instanceof Array)) {
199
+ console.error('[pod6] item:block : Error in content of ' + JSON.stringify(node));
200
+ }
201
+ const [firstPara, ...other] = node.content;
202
+ writer.writeRaw('<li>');
203
+ // TODO: get cases for handle first para in items
204
+ // interator([...firstPara.content, ...other], ctx)
205
+ interator(node.content, ctx);
206
+ writer.writeRaw('</li>');
207
+ },
208
+ 'comment:block': handlers_1.emptyContent,
209
+ defn: (0, handlers_1.wrapContent)('', '</dd>'),
210
+ 'term:para': (0, handlers_1.wrapContent)('<dt>', '</dt><dd>'),
211
+ nested: (0, handlers_1.handleNested)(handlers_1.content, 1),
212
+ output: (0, handlers_1.handleNested)((0, handlers_1.wrapContent)('<pre><samp>', '</samp></pre>'), 1),
213
+ input: (0, handlers_1.handleNested)((0, handlers_1.wrapContent)('<pre><kbd>', '</kbd></pre>'), 1),
214
+ // table section
215
+ 'table:block': (0, handlers_1.handleNested)((writer, processor) => (node, ctx, interator) => {
216
+ const conf = (0, config_1.default)(node, ctx);
217
+ writer.writeRaw('<table>');
218
+ if (conf.exists('caption')) {
219
+ writer.writeRaw('<caption>');
220
+ writer.write(conf.getFirstValue('caption'));
221
+ writer.writeRaw('</caption>');
222
+ }
223
+ interator(node.content, ctx);
224
+ writer.writeRaw('</table>');
225
+ }),
226
+ ':separator': handlers_1.emptyContent,
227
+ table_row: (0, handlers_1.wrapContent)('<tr>', '</tr>'),
228
+ table_cell: (0, handlers_1.wrapContent)('<td>', '</td>'),
229
+ table_head: (0, handlers_1.subUse)({
230
+ table_cell: (0, handlers_1.wrapContent)('<th>', '</th>'),
231
+ }, (0, handlers_1.wrapContent)('<tr>', '</tr>')),
232
+ // Toc
233
+ ':toc': (writer, processor) => (node, ctx, interator) => {
234
+ writer.writeRaw('<div className="toc">');
235
+ // get toc title
236
+ const conf = (0, config_1.default)(node, ctx);
237
+ if (conf.exists('title')) {
238
+ const title = conf.getFirstValue('title');
239
+ writer.writeRaw('<div className="toctitle">');
240
+ writer.write(title);
241
+ writer.writeRaw('</div>');
242
+ }
243
+ interator(node.content, ctx);
244
+ writer.writeRaw('</div>');
245
+ },
246
+ ':toc-list': (0, handlers_1.setFn)((node, ctx) => (0, handlers_1.wrapContent)(`<ul class="toc-list listlevel${node.level}">`, '</ul>')),
247
+ ':toc-item': (0, handlers_1.setFn)((node, ctx) => (0, handlers_1.wrapContent)('<li class="toc-item">', '</li>')),
248
+ ':image': (writer, processor) => (node, ctx, interator) => {
249
+ writer.writeRaw(`<img src="${node.src}" alt="${node.alt}"/>`);
250
+ },
251
+ };
252
+ const toHtml = opt => (0, exportAny_1.default)({ writer: writerHtml_1.default, ...opt })
253
+ .use('*', (writer, processor) => {
254
+ return (node, ctx, interator) => {
255
+ // skip warnings for semantic blocks
256
+ const isSemanticBlock = node => {
257
+ const name = node.name || '';
258
+ const isTypeBlock = (node.type || '') === 'block';
259
+ return isTypeBlock && name === name.toUpperCase();
260
+ };
261
+ //Named blocks for which no explicit class has been defined or loaded are
262
+ //usually not rendered by the standard renderers.
263
+ if ((0, makeTransformer_1.isNamedBlock)(node.name)) {
264
+ return true;
265
+ }
266
+ if (isSemanticBlock(node)) {
267
+ const name = node.name;
268
+ writer.writeRaw('<h1 class="');
269
+ writer.write(name);
270
+ writer.writeRaw('">');
271
+ writer.write(name);
272
+ writer.writeRaw('</h1>');
273
+ }
274
+ else {
275
+ console.warn('[pod6] Unhandled node' + JSON.stringify(node, null, 2));
276
+ }
277
+ if (node.hasOwnProperty('content')) {
278
+ interator(node.content, ctx);
279
+ }
280
+ };
281
+ })
282
+ .use(rules);
283
+ exports.default = toHtml;
284
+ //# sourceMappingURL=exportHtml.js.map
@@ -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 };