@podlite/to-jsx 0.0.8 → 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 +10 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +218 -306
- package/lib/index.js.map +1 -0
- package/package.json +8 -17
- package/src/index.tsx +11 -7
- package/t/index.component.spec.tsx +1 -1
- package/tsconfig.json +10 -19
- package/tsconfig.tsbuildinfo +1 -1
- package/yarn-error.log +0 -8944
package/lib/index.js
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
1
|
+
"use strict";
|
|
12
2
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
3
|
var t = {};
|
|
14
4
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -20,66 +10,41 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
10
|
}
|
|
21
11
|
return t;
|
|
22
12
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
43
|
-
ar[i] = from[i];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
47
|
-
};
|
|
48
|
-
import React from 'react';
|
|
49
|
-
import toAny from 'pod6/built/exportAny';
|
|
50
|
-
import { subUse, emptyContent, content as nodeContent, setFn } from 'pod6/built/helpers/handlers';
|
|
51
|
-
import clean_plugin from 'pod6/built/plugin-clean-location';
|
|
52
|
-
import makeAttrs from 'pod6/built/helpers/config';
|
|
53
|
-
import { isNamedBlock, isSemanticBlock } from 'pod6/built/helpers/makeTransformer';
|
|
54
|
-
import { parse } from 'pod6';
|
|
55
|
-
import Writer from 'pod6/built/writer';
|
|
56
|
-
import { podlite as podlite_core } from 'podlite';
|
|
57
|
-
import Diagram from '@podlite/diagram';
|
|
58
|
-
import { getNodeId } from '@podlite/schema';
|
|
59
|
-
var helperMakeReact = function (_a) {
|
|
60
|
-
var wrapElement = _a.wrapElement;
|
|
61
|
-
var i_key_i = 0;
|
|
62
|
-
var mapByType = {};
|
|
63
|
-
var getIdForNode = function (_a) {
|
|
64
|
-
var _b = _a.type, type = _b === void 0 ? "notype" : _b, _c = _a.name, name = _c === void 0 ? "noname" : _c;
|
|
65
|
-
var type_idx = "".concat(type, "_").concat(name);
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.Podlite = void 0;
|
|
15
|
+
const React = require("react");
|
|
16
|
+
const react_1 = require("react");
|
|
17
|
+
const exportAny_1 = require("pod6/built/exportAny");
|
|
18
|
+
const handlers_1 = require("pod6/built/helpers/handlers");
|
|
19
|
+
const plugin_clean_location_1 = require("pod6/built/plugin-clean-location");
|
|
20
|
+
const config_1 = require("pod6/built/helpers/config");
|
|
21
|
+
const makeTransformer_1 = require("pod6/built/helpers/makeTransformer");
|
|
22
|
+
const pod6_1 = require("pod6");
|
|
23
|
+
const writer_1 = require("pod6/built/writer");
|
|
24
|
+
const podlite_1 = require("podlite");
|
|
25
|
+
const diagram_1 = require("@podlite/diagram");
|
|
26
|
+
const schema_1 = require("@podlite/schema");
|
|
27
|
+
const helperMakeReact = ({ wrapElement }) => {
|
|
28
|
+
let i_key_i = 0;
|
|
29
|
+
let mapByType = {};
|
|
30
|
+
const getIdForNode = ({ type = "notype", name = "noname" }) => {
|
|
31
|
+
const type_idx = `${type}_${name}`;
|
|
66
32
|
if (!mapByType[type_idx]) {
|
|
67
33
|
mapByType[type_idx] = 0;
|
|
68
34
|
}
|
|
69
35
|
++mapByType[type_idx];
|
|
70
|
-
return
|
|
36
|
+
return `${type_idx}_${mapByType[type_idx]}`;
|
|
71
37
|
};
|
|
72
|
-
return function (src, node, children, extraProps) {
|
|
73
|
-
if (extraProps === void 0) { extraProps = {}; }
|
|
38
|
+
return function (src, node, children, extraProps = {}) {
|
|
74
39
|
// for string return it
|
|
75
40
|
if (typeof node == 'string') {
|
|
76
41
|
return node;
|
|
77
42
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
? src(
|
|
82
|
-
:
|
|
43
|
+
const attr = __rest(node, []);
|
|
44
|
+
const key = 'type' in node && node.type ? getIdForNode(node) : ++i_key_i;
|
|
45
|
+
const result = typeof src === 'function'
|
|
46
|
+
? src(Object.assign(Object.assign({}, attr), { key, children }), children)
|
|
47
|
+
: (0, react_1.createElement)(src, Object.assign(Object.assign({}, extraProps), { key }), children);
|
|
83
48
|
// // create react element and pass key
|
|
84
49
|
// if (!isValidElementType(src)) {
|
|
85
50
|
// throw new Error(`Bad React element for ${ruleName} rule `)
|
|
@@ -90,167 +55,144 @@ var helperMakeReact = function (_a) {
|
|
|
90
55
|
return result;
|
|
91
56
|
};
|
|
92
57
|
};
|
|
93
|
-
|
|
94
|
-
var children = _a
|
|
95
|
-
|
|
58
|
+
const Podlite = (_a) => {
|
|
59
|
+
var { children } = _a, options = __rest(_a, ["children"]);
|
|
60
|
+
const result = podlite(children, options);
|
|
96
61
|
return result;
|
|
97
62
|
};
|
|
98
|
-
|
|
99
|
-
|
|
63
|
+
exports.Podlite = Podlite;
|
|
64
|
+
const mapToReact = (makeComponent) => {
|
|
65
|
+
const mkComponent = (src) => (writer, processor) => (node, ctx, interator) => {
|
|
100
66
|
// check if node.content defined
|
|
101
|
-
return makeComponent(src, node, 'content' in node ? interator(node.content,
|
|
102
|
-
};
|
|
67
|
+
return makeComponent(src, node, 'content' in node ? interator(node.content, Object.assign({}, ctx)) : []);
|
|
68
|
+
};
|
|
103
69
|
// Handle nested block and :nested block attribute
|
|
104
|
-
|
|
105
|
-
return
|
|
106
|
-
|
|
107
|
-
return
|
|
108
|
-
|
|
109
|
-
|
|
70
|
+
const handleNested = (defaultHandler, implicitLevel) => {
|
|
71
|
+
return (writer, processor) => {
|
|
72
|
+
const defaultHandlerInited = defaultHandler(writer, processor);
|
|
73
|
+
return (node, ctx, interator) => {
|
|
74
|
+
const nesting = (0, config_1.default)(node, ctx).getFirstValue('nested') || implicitLevel;
|
|
75
|
+
const children = defaultHandlerInited(node, ctx, interator);
|
|
110
76
|
// if no nesting needs - simply return children
|
|
111
77
|
if (!nesting) {
|
|
112
78
|
return children;
|
|
113
79
|
}
|
|
114
|
-
|
|
115
|
-
return arr.reduce(
|
|
80
|
+
const arr = [...Array(nesting).keys()];
|
|
81
|
+
return arr.reduce((acc) => makeComponent('blockquote', node, acc), children);
|
|
116
82
|
};
|
|
117
83
|
};
|
|
118
84
|
};
|
|
119
85
|
return {
|
|
120
86
|
'pod': mkComponent('div'),
|
|
121
|
-
'root':
|
|
122
|
-
'data': emptyContent(),
|
|
123
|
-
':ambient': emptyContent(),
|
|
124
|
-
':code': mkComponent(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
'code': mkComponent(function (_a) {
|
|
130
|
-
var children = _a.children, key = _a.key;
|
|
131
|
-
return React.createElement("code", { key: key },
|
|
132
|
-
React.createElement("pre", null, children));
|
|
133
|
-
}),
|
|
134
|
-
'Image': subUse({
|
|
87
|
+
'root': handlers_1.content,
|
|
88
|
+
'data': (0, handlers_1.emptyContent)(),
|
|
89
|
+
':ambient': (0, handlers_1.emptyContent)(),
|
|
90
|
+
':code': mkComponent(({ children, key }) => React.createElement("code", { key: key },
|
|
91
|
+
React.createElement("pre", null, children))),
|
|
92
|
+
'code': mkComponent(({ children, key }) => React.createElement("code", { key: key },
|
|
93
|
+
React.createElement("pre", null, children))),
|
|
94
|
+
'Image': (0, handlers_1.subUse)({
|
|
135
95
|
// inside head don't wrap into <p>
|
|
136
|
-
':image':
|
|
137
|
-
|
|
138
|
-
return mkComponent(
|
|
139
|
-
|
|
140
|
-
|
|
96
|
+
':image': (0, handlers_1.setFn)((node, ctx) => {
|
|
97
|
+
const linkTo = ctx.link;
|
|
98
|
+
return mkComponent(({ children, key }) => {
|
|
99
|
+
const Img = node.src.match(/(mp4|mov)$/)
|
|
100
|
+
? React.createElement("video", { controls: true, key: key },
|
|
101
|
+
" ",
|
|
102
|
+
React.createElement("source", { src: node.src, type: "video/mp4" }),
|
|
103
|
+
" ")
|
|
104
|
+
: React.createElement("img", { key: key, src: node.src, alt: node.alt });
|
|
141
105
|
return linkTo ? React.createElement("a", { key: key, href: linkTo }, Img) : Img;
|
|
142
106
|
});
|
|
143
107
|
}),
|
|
144
|
-
'caption': mkComponent(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
var level = node.level;
|
|
150
|
-
var id = getNodeId(node, ctx);
|
|
151
|
-
var conf = makeAttrs(node, ctx);
|
|
108
|
+
'caption': mkComponent(({ children, key }) => React.createElement("div", { className: "caption", key: key }, children))
|
|
109
|
+
}, (0, handlers_1.setFn)((node, ctx) => {
|
|
110
|
+
const { level } = node;
|
|
111
|
+
const id = (0, schema_1.getNodeId)(node, ctx);
|
|
112
|
+
const conf = (0, config_1.default)(node, ctx);
|
|
152
113
|
if (conf.exists('link')) {
|
|
153
114
|
ctx.link = conf.getFirstValue('link');
|
|
154
115
|
}
|
|
155
|
-
return mkComponent(
|
|
156
|
-
var children = _a.children, key = _a.key;
|
|
157
|
-
return React.createElement("div", { className: "image_block", key: key, id: id }, children);
|
|
158
|
-
});
|
|
116
|
+
return mkComponent(({ children, key }) => React.createElement("div", { className: "image_block", key: key, id: id }, children));
|
|
159
117
|
})),
|
|
160
|
-
'image':
|
|
161
|
-
':image':
|
|
162
|
-
return mkComponent(
|
|
163
|
-
var children = _a.children, key = _a.key;
|
|
164
|
-
return React.createElement("img", { key: key, src: node.src, alt: node.alt });
|
|
165
|
-
});
|
|
118
|
+
'image': handlers_1.content,
|
|
119
|
+
':image': (0, handlers_1.setFn)((node, ctx) => {
|
|
120
|
+
return mkComponent(({ children, key }) => React.createElement("img", { key: key, src: node.src, alt: node.alt }));
|
|
166
121
|
}),
|
|
167
|
-
'Diagram':
|
|
168
|
-
|
|
169
|
-
|
|
122
|
+
'Diagram': () => (node, ctx, interator) => {
|
|
123
|
+
const conf = (0, config_1.default)(node, ctx);
|
|
124
|
+
const caption = conf.exists("caption")
|
|
170
125
|
? conf.getFirstValue("caption")
|
|
171
126
|
: null;
|
|
172
|
-
|
|
173
|
-
return makeComponent(
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
':text': function (writer, processor) { return function (node, ctx, interator) {
|
|
127
|
+
const id = (0, schema_1.getNodeId)(node, ctx);
|
|
128
|
+
return makeComponent(({ children, key }) => {
|
|
129
|
+
return React.createElement(diagram_1.default, { id: id, isError: node.custom, caption: caption, chart: node.content[0].value });
|
|
130
|
+
}, node, interator(node.content, Object.assign({}, ctx)));
|
|
131
|
+
},
|
|
132
|
+
':text': (writer, processor) => (node, ctx, interator) => {
|
|
179
133
|
return node.value;
|
|
180
|
-
}
|
|
181
|
-
':verbatim':
|
|
134
|
+
},
|
|
135
|
+
':verbatim': (writer, processor) => (node, ctx, interator) => {
|
|
182
136
|
return node.value;
|
|
183
|
-
}
|
|
184
|
-
'head:block': subUse({
|
|
137
|
+
},
|
|
138
|
+
'head:block': (0, handlers_1.subUse)({
|
|
185
139
|
// inside head don't wrap into <p>
|
|
186
|
-
':para':
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return mkComponent(
|
|
191
|
-
var level = _a.level, children = _a.children, key = _a.key;
|
|
192
|
-
return React.createElement("h".concat(level), { key: key, id: id }, children);
|
|
193
|
-
});
|
|
140
|
+
':para': handlers_1.content,
|
|
141
|
+
}, (0, handlers_1.setFn)((node, ctx) => {
|
|
142
|
+
const { level } = node;
|
|
143
|
+
const id = (0, schema_1.getNodeId)(node, ctx);
|
|
144
|
+
return mkComponent(({ level, children, key }) => (0, react_1.createElement)(`h${level}`, { key, id }, children));
|
|
194
145
|
})),
|
|
195
|
-
':blankline': emptyContent(),
|
|
146
|
+
':blankline': (0, handlers_1.emptyContent)(),
|
|
196
147
|
':para': mkComponent('p'),
|
|
197
148
|
'para': mkComponent('div'),
|
|
198
|
-
'comment:block': emptyContent(),
|
|
199
|
-
'defn': subUse([
|
|
149
|
+
'comment:block': (0, handlers_1.emptyContent)(),
|
|
150
|
+
'defn': (0, handlers_1.subUse)([
|
|
200
151
|
// to avoid overlap para blocks handlers
|
|
201
152
|
// define general :para at first
|
|
202
153
|
{ ':para': mkComponent('dd') },
|
|
203
154
|
{ 'term:para': mkComponent('dt') },
|
|
204
|
-
],
|
|
205
|
-
"nested": handleNested(
|
|
206
|
-
'output': mkComponent(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}),
|
|
211
|
-
'input': mkComponent(function (_a) {
|
|
212
|
-
var children = _a.children, key = _a.key;
|
|
213
|
-
return React.createElement("pre", { key: key },
|
|
214
|
-
React.createElement("kbd", null, children));
|
|
215
|
-
}),
|
|
155
|
+
], handlers_1.content),
|
|
156
|
+
"nested": handleNested(handlers_1.content, 1),
|
|
157
|
+
'output': mkComponent(({ children, key }) => React.createElement("pre", { key: key },
|
|
158
|
+
React.createElement("samp", null, children))),
|
|
159
|
+
'input': mkComponent(({ children, key }) => React.createElement("pre", { key: key },
|
|
160
|
+
React.createElement("kbd", null, children))),
|
|
216
161
|
// Directives
|
|
217
|
-
':config':
|
|
162
|
+
':config': (0, handlers_1.setFn)((node, ctx) => {
|
|
218
163
|
// setup context
|
|
219
164
|
if (!ctx.hasOwnProperty('config'))
|
|
220
165
|
ctx.config = {};
|
|
221
166
|
//collect configs in context
|
|
222
167
|
ctx.config[node.name] = node.config;
|
|
223
|
-
return emptyContent();
|
|
168
|
+
return (0, handlers_1.emptyContent)();
|
|
224
169
|
}),
|
|
225
|
-
':alias':
|
|
170
|
+
':alias': (0, handlers_1.setFn)((node, ctx) => {
|
|
226
171
|
// set alias
|
|
227
172
|
if (!ctx.hasOwnProperty('alias'))
|
|
228
173
|
ctx.alias = {};
|
|
229
174
|
//collect configs in context
|
|
230
175
|
ctx.alias[node.name] = node.replacement;
|
|
231
|
-
return emptyContent();
|
|
176
|
+
return (0, handlers_1.emptyContent)();
|
|
232
177
|
}),
|
|
233
178
|
// Formatting codes
|
|
234
|
-
'A<>':
|
|
235
|
-
|
|
179
|
+
'A<>': (writer, processor) => (node, ctx, interator) => {
|
|
180
|
+
let term = node.content;
|
|
236
181
|
if (typeof term !== 'string' && 'value' in term) {
|
|
237
182
|
term = term.value;
|
|
238
183
|
}
|
|
239
184
|
//get replacement text
|
|
240
185
|
if (!(ctx.alias && ctx.alias.hasOwnProperty(term))) {
|
|
241
|
-
return makeComponent(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
children,
|
|
246
|
-
">");
|
|
247
|
-
}, node, interator(node.content, ctx));
|
|
186
|
+
return makeComponent(({ children, key }) => React.createElement("code", { key: key },
|
|
187
|
+
"A<",
|
|
188
|
+
children,
|
|
189
|
+
">"), node, interator(node.content, ctx));
|
|
248
190
|
}
|
|
249
191
|
else {
|
|
250
|
-
|
|
251
|
-
|
|
192
|
+
const src = ctx.alias[term].join('\n');
|
|
193
|
+
const tree_1 = processor(src);
|
|
252
194
|
// now clean locations
|
|
253
|
-
|
|
195
|
+
const tree = (0, plugin_clean_location_1.default)()(tree_1);
|
|
254
196
|
if (tree[0].type === 'para') {
|
|
255
197
|
return interator(tree[0].content, ctx);
|
|
256
198
|
}
|
|
@@ -258,15 +200,15 @@ var mapToReact = function (makeComponent) {
|
|
|
258
200
|
return interator(tree, ctx);
|
|
259
201
|
}
|
|
260
202
|
}
|
|
261
|
-
}
|
|
203
|
+
},
|
|
262
204
|
'B<>': mkComponent('strong'),
|
|
263
205
|
'C<>': mkComponent('code'),
|
|
264
|
-
'E<>':
|
|
206
|
+
'E<>': (writer, processor) => (node, ctx, interator) => {
|
|
265
207
|
if ('content' in node && Array.isArray(node.content))
|
|
266
|
-
return node.content.filter(
|
|
208
|
+
return node.content.filter(e => e && e.type == 'number').map(element => {
|
|
267
209
|
return String.fromCharCode(element.value);
|
|
268
210
|
}).join('');
|
|
269
|
-
}
|
|
211
|
+
},
|
|
270
212
|
'I<>': mkComponent('i'),
|
|
271
213
|
'K<>': mkComponent('kbd'),
|
|
272
214
|
/**
|
|
@@ -281,33 +223,30 @@ var mapToReact = function (makeComponent) {
|
|
|
281
223
|
border-top-color: #eee;
|
|
282
224
|
}
|
|
283
225
|
*/
|
|
284
|
-
'N<>':
|
|
285
|
-
writer.addListener('end',
|
|
226
|
+
'N<>': (writer, processor) => {
|
|
227
|
+
writer.addListener('end', () => {
|
|
286
228
|
if (!writer.hasOwnProperty('FOOTNOTES')) {
|
|
287
229
|
return;
|
|
288
230
|
}
|
|
289
|
-
|
|
231
|
+
const footnotes = writer.FOOTNOTES;
|
|
290
232
|
if (footnotes.length < 1) {
|
|
291
233
|
return;
|
|
292
234
|
} // if empty footnotes
|
|
293
235
|
if (!writer.hasOwnProperty('postInterator')) {
|
|
294
236
|
writer.postInterator = [];
|
|
295
237
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
footnote.make());
|
|
306
|
-
}));
|
|
307
|
-
}, {});
|
|
238
|
+
const FootNotes = makeComponent(({ children, key }) => React.createElement("div", { key: `${key}_FOOTNOTES`, className: "footnotes" }, footnotes.map((footnote, id) => {
|
|
239
|
+
return React.createElement("p", { key: id },
|
|
240
|
+
React.createElement("sup", { id: footnote.fnId, className: "footnote" },
|
|
241
|
+
React.createElement("a", { href: `#${footnote.fnRefId}` },
|
|
242
|
+
"[",
|
|
243
|
+
footnote.gid,
|
|
244
|
+
"]")),
|
|
245
|
+
footnote.make());
|
|
246
|
+
})), {});
|
|
308
247
|
writer.postInterator.push(FootNotes);
|
|
309
248
|
});
|
|
310
|
-
return
|
|
249
|
+
return (node, ctx, interator) => {
|
|
311
250
|
// skip empty notes
|
|
312
251
|
if (node.content.length < 1) {
|
|
313
252
|
return;
|
|
@@ -316,45 +255,42 @@ var mapToReact = function (makeComponent) {
|
|
|
316
255
|
writer.gid = 1;
|
|
317
256
|
}
|
|
318
257
|
// get foot note id
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
258
|
+
const gid = writer.gid++;
|
|
259
|
+
const fnRefId = `fnref:${gid}`;
|
|
260
|
+
const fnId = `fn:${gid}`;
|
|
322
261
|
if (!writer.hasOwnProperty('FOOTNOTES')) {
|
|
323
262
|
writer.FOOTNOTES = [];
|
|
324
263
|
}
|
|
325
264
|
writer.FOOTNOTES.push({
|
|
326
|
-
gid
|
|
327
|
-
fnRefId
|
|
328
|
-
fnId
|
|
329
|
-
node
|
|
330
|
-
make:
|
|
265
|
+
gid,
|
|
266
|
+
fnRefId,
|
|
267
|
+
fnId,
|
|
268
|
+
node,
|
|
269
|
+
make: () => { return interator(node.content, ctx); }
|
|
331
270
|
});
|
|
332
|
-
return makeComponent(
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
gid,
|
|
338
|
-
"]"));
|
|
339
|
-
}, node);
|
|
271
|
+
return makeComponent(({ children, key }) => React.createElement("sup", { key: key, id: fnRefId, className: "footnote" },
|
|
272
|
+
React.createElement("a", { href: `#${fnId}` },
|
|
273
|
+
"[",
|
|
274
|
+
gid,
|
|
275
|
+
"]")), node);
|
|
340
276
|
};
|
|
341
277
|
},
|
|
342
278
|
'R<>': mkComponent('var'),
|
|
343
279
|
'T<>': mkComponent('samp'),
|
|
344
|
-
'D<>':
|
|
345
|
-
|
|
346
|
-
|
|
280
|
+
'D<>': (writer, processor) => (node, ctx, interator) => {
|
|
281
|
+
let { synonyms } = node;
|
|
282
|
+
let definition = [node.content[0]];
|
|
347
283
|
if (synonyms) {
|
|
348
284
|
definition = synonyms;
|
|
349
285
|
}
|
|
350
286
|
if (!writer.hasOwnProperty('DEFINITIONS')) {
|
|
351
287
|
writer.DEFINITIONS = [];
|
|
352
288
|
}
|
|
353
|
-
writer.DEFINITIONS.push({ definition
|
|
289
|
+
writer.DEFINITIONS.push({ definition });
|
|
354
290
|
return makeComponent('dfn', node, interator(node.content, ctx));
|
|
355
|
-
}
|
|
356
|
-
"L<>":
|
|
357
|
-
|
|
291
|
+
},
|
|
292
|
+
"L<>": (0, handlers_1.setFn)((node, ctx) => {
|
|
293
|
+
let { meta } = node;
|
|
358
294
|
if (meta === null) {
|
|
359
295
|
meta = node.content;
|
|
360
296
|
}
|
|
@@ -365,33 +301,27 @@ var mapToReact = function (makeComponent) {
|
|
|
365
301
|
if (meta && typeof meta !== 'string' && 'value' in meta) {
|
|
366
302
|
meta = meta.value;
|
|
367
303
|
}
|
|
368
|
-
return mkComponent(
|
|
369
|
-
var children = _a.children, key = _a.key;
|
|
370
|
-
return React.createElement("a", { href: meta, key: key }, children);
|
|
371
|
-
});
|
|
304
|
+
return mkComponent(({ children, key }) => React.createElement("a", { href: meta, key: key }, children));
|
|
372
305
|
}),
|
|
373
|
-
'S<>':
|
|
374
|
-
|
|
306
|
+
'S<>': (writer, processor) => (node, ctx, interator) => {
|
|
307
|
+
let content = node.content || '';
|
|
375
308
|
if (typeof content !== 'string' && 'value' in content) {
|
|
376
309
|
content = content.value;
|
|
377
310
|
}
|
|
378
|
-
|
|
311
|
+
const Content = content.split('').map((symbol, index) => {
|
|
379
312
|
if (symbol === ' ')
|
|
380
313
|
return "\u00a0";
|
|
381
314
|
if (symbol === '\n')
|
|
382
315
|
return React.createElement("br", { key: index });
|
|
383
316
|
return symbol;
|
|
384
317
|
});
|
|
385
|
-
return makeComponent(
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}; },
|
|
390
|
-
'V<>': nodeContent,
|
|
391
|
-
'Z<>': emptyContent(),
|
|
318
|
+
return makeComponent(({ children, key }) => children, {}, Content);
|
|
319
|
+
},
|
|
320
|
+
'V<>': handlers_1.content,
|
|
321
|
+
'Z<>': (0, handlers_1.emptyContent)(),
|
|
392
322
|
'U<>': mkComponent('u'),
|
|
393
|
-
'X<>':
|
|
394
|
-
|
|
323
|
+
'X<>': (writer, processor) => (node, ctx, interator) => {
|
|
324
|
+
let { entry } = node;
|
|
395
325
|
if (entry === null && node.content.length > 0) {
|
|
396
326
|
//@ts-ignore
|
|
397
327
|
entry = [node.content[0]];
|
|
@@ -401,46 +331,42 @@ var mapToReact = function (makeComponent) {
|
|
|
401
331
|
writer.INDEXTERMS = [];
|
|
402
332
|
}
|
|
403
333
|
writer.INDEXTERMS.push({
|
|
404
|
-
entry
|
|
334
|
+
entry
|
|
405
335
|
});
|
|
406
336
|
return interator(node.content, ctx);
|
|
407
|
-
}
|
|
337
|
+
},
|
|
408
338
|
// table section
|
|
409
|
-
'table':
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
}, node, interator(node.content, __assign({}, ctx)));
|
|
430
|
-
};
|
|
339
|
+
'table': (writer, processor) => (node, ctx, interator) => {
|
|
340
|
+
const conf = (0, config_1.default)(node, ctx);
|
|
341
|
+
let attr = { caption: '' };
|
|
342
|
+
if (conf.exists('caption')) {
|
|
343
|
+
const caption = conf.getFirstValue('caption');
|
|
344
|
+
attr.caption = caption;
|
|
345
|
+
}
|
|
346
|
+
if (typeof node === 'string') {
|
|
347
|
+
return node;
|
|
348
|
+
}
|
|
349
|
+
if (!('content' in node)) {
|
|
350
|
+
console.warn('[jsx] no content in node');
|
|
351
|
+
return '';
|
|
352
|
+
}
|
|
353
|
+
const id = (0, schema_1.getNodeId)(node, ctx);
|
|
354
|
+
return makeComponent(({ key, children }) => {
|
|
355
|
+
return React.createElement("table", { key: key, id: id },
|
|
356
|
+
React.createElement("caption", { className: "caption" }, attr.caption),
|
|
357
|
+
React.createElement("tbody", null, children));
|
|
358
|
+
}, node, interator(node.content, Object.assign({}, ctx)));
|
|
431
359
|
},
|
|
432
|
-
':separator': emptyContent(),
|
|
360
|
+
':separator': (0, handlers_1.emptyContent)(),
|
|
433
361
|
'table_row': mkComponent('tr'),
|
|
434
362
|
'table_cell': mkComponent('td'),
|
|
435
|
-
'table_head': subUse({
|
|
363
|
+
'table_head': (0, handlers_1.subUse)({
|
|
436
364
|
'table_cell': mkComponent('th')
|
|
437
365
|
}, mkComponent('tr')),
|
|
438
|
-
':list':
|
|
439
|
-
|
|
440
|
-
:
|
|
441
|
-
|
|
442
|
-
}),
|
|
443
|
-
'item:block': function (writer, processor) { return function (node, ctx, interator) {
|
|
366
|
+
':list': (0, handlers_1.setFn)((node, ctx) => node.list === 'ordered' ? mkComponent('ol')
|
|
367
|
+
: node.list === 'variable' ? mkComponent('dl')
|
|
368
|
+
: mkComponent('ul')),
|
|
369
|
+
'item:block': (writer, processor) => (node, ctx, interator) => {
|
|
444
370
|
if (typeof node === 'string') {
|
|
445
371
|
return node;
|
|
446
372
|
}
|
|
@@ -452,78 +378,64 @@ var mapToReact = function (makeComponent) {
|
|
|
452
378
|
if (!(node.content instanceof Array)) {
|
|
453
379
|
console.error(node);
|
|
454
380
|
}
|
|
455
|
-
|
|
456
|
-
return makeComponent('li', node, interator(node.content,
|
|
457
|
-
}
|
|
381
|
+
const id = (0, schema_1.getNodeId)(node, ctx);
|
|
382
|
+
return makeComponent('li', node, interator(node.content, Object.assign({}, ctx)), { id });
|
|
383
|
+
},
|
|
458
384
|
// table of content
|
|
459
|
-
':toc':
|
|
460
|
-
|
|
461
|
-
return mkComponent(
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
tocTitle ? React.createElement("div", { className: "toctitle" }, tocTitle) : '',
|
|
465
|
-
children);
|
|
466
|
-
});
|
|
385
|
+
':toc': (0, handlers_1.setFn)((node, ctx) => {
|
|
386
|
+
const tocTitle = node.title;
|
|
387
|
+
return mkComponent(({ children, key }) => React.createElement("div", { className: "toc", key: key },
|
|
388
|
+
tocTitle ? React.createElement("div", { className: "toctitle" }, tocTitle) : '',
|
|
389
|
+
children));
|
|
467
390
|
}),
|
|
468
|
-
':toc-list':
|
|
469
|
-
|
|
470
|
-
return mkComponent(
|
|
471
|
-
var children = _a.children, key = _a.key;
|
|
472
|
-
return React.createElement("ul", { className: "toc-list listlevel".concat(level), key: key }, children);
|
|
473
|
-
});
|
|
391
|
+
':toc-list': (0, handlers_1.setFn)((node, ctx) => {
|
|
392
|
+
const { level } = node;
|
|
393
|
+
return mkComponent(({ children, key }) => React.createElement("ul", { className: `toc-list listlevel${level}`, key: key }, children));
|
|
474
394
|
}),
|
|
475
|
-
':toc-item': subUse({
|
|
395
|
+
':toc-item': (0, handlers_1.subUse)({
|
|
476
396
|
// inside head don't wrap into <p>
|
|
477
|
-
':para':
|
|
478
|
-
},
|
|
479
|
-
return mkComponent(
|
|
480
|
-
var children = _a.children, key = _a.key;
|
|
481
|
-
return React.createElement("li", { className: "toc-item", key: key }, children);
|
|
482
|
-
});
|
|
397
|
+
':para': handlers_1.content,
|
|
398
|
+
}, (0, handlers_1.setFn)((node, ctx) => {
|
|
399
|
+
return mkComponent(({ children, key }) => React.createElement("li", { className: "toc-item", key: key }, children));
|
|
483
400
|
})),
|
|
484
401
|
};
|
|
485
402
|
};
|
|
486
|
-
function podlite(children,
|
|
487
|
-
|
|
488
|
-
var args = [];
|
|
489
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
490
|
-
args[_i - 2] = arguments[_i];
|
|
491
|
-
}
|
|
492
|
-
var ast = (function (tree) {
|
|
403
|
+
function podlite(children, { file, plugins = () => { }, wrapElement, tree }, ...args) {
|
|
404
|
+
const ast = ((tree) => {
|
|
493
405
|
if (tree)
|
|
494
406
|
return tree.interator;
|
|
495
|
-
|
|
496
|
-
|
|
407
|
+
let podlite = (0, podlite_1.podlite)({ importPlugins: true });
|
|
408
|
+
let treeAfterParsed = podlite.parse(children || file);
|
|
497
409
|
return podlite.toAst(treeAfterParsed);
|
|
498
410
|
})(tree);
|
|
499
411
|
// const ast = parse( children || content )
|
|
500
|
-
|
|
501
|
-
|
|
412
|
+
let i_key_i = 10000;
|
|
413
|
+
const makeComponent = helperMakeReact({ wrapElement });
|
|
502
414
|
// TODO: move toJSX to podlite/core
|
|
503
415
|
// const toJSXPlugins= toAnyRules('toJSX', instance.getPlugins())
|
|
504
|
-
|
|
505
|
-
|
|
416
|
+
const rules = Object.assign(Object.assign({}, mapToReact(makeComponent)), plugins(makeComponent));
|
|
417
|
+
const writer = new writer_1.default((s) => {
|
|
506
418
|
});
|
|
507
|
-
|
|
508
|
-
.use({ '*:*':
|
|
419
|
+
const res = (0, exportAny_1.default)({ processor: pod6_1.parse })
|
|
420
|
+
.use({ '*:*': () => (node, ctx, interator) => {
|
|
509
421
|
// skip named blocks
|
|
510
|
-
if (isNamedBlock(node.name)) {
|
|
422
|
+
if ((0, makeTransformer_1.isNamedBlock)(node.name)) {
|
|
511
423
|
return null;
|
|
512
424
|
}
|
|
513
|
-
if (isSemanticBlock(node)) {
|
|
514
|
-
return makeComponent(
|
|
515
|
-
var key = _a.key, children = _a.children;
|
|
425
|
+
if ((0, makeTransformer_1.isSemanticBlock)(node)) {
|
|
426
|
+
return makeComponent(({ key, children }) => {
|
|
516
427
|
return React.createElement("div", { key: key },
|
|
517
428
|
React.createElement("h1", { className: node.name, key: key }, node.name),
|
|
518
|
-
interator(node.content,
|
|
519
|
-
}, node, interator(node.content,
|
|
429
|
+
interator(node.content, Object.assign({}, ctx)));
|
|
430
|
+
}, node, interator(node.content, Object.assign({}, ctx)));
|
|
520
431
|
}
|
|
521
432
|
console.warn('[podlite] Not supported: ' + JSON.stringify(node, null, 2));
|
|
522
|
-
return
|
|
523
|
-
}
|
|
433
|
+
return (0, react_1.createElement)('code', { key: ++i_key_i }, `not supported node:${JSON.stringify(node, null, 2)}`);
|
|
434
|
+
} })
|
|
524
435
|
.use(rules)
|
|
525
436
|
.run(ast, writer);
|
|
526
437
|
// union main react elements and post processed via onEnd event
|
|
527
438
|
return new Array().concat(res.interator, writer.postInterator);
|
|
528
439
|
}
|
|
529
|
-
|
|
440
|
+
exports.default = exports.Podlite;
|
|
441
|
+
//# sourceMappingURL=index.js.map
|