@podlite/to-jsx 0.0.15 → 0.0.17
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 +35 -1
- package/LICENSE +1 -1
- package/README.md +41 -1
- package/index.js +1 -1
- package/jest.config.js +0 -1
- package/jest.tsconfig.json +1 -1
- package/lib/index.d.ts +4 -5
- package/lib/index.js +129 -147
- package/lib/index.js.map +1 -1
- package/package.json +15 -9
- package/src/index.tsx +458 -366
- package/t/fixtures.component.spec.tsx +27 -46
- package/t/index.component.spec.tsx +130 -117
- package/tsconfig.json +6 -2
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,45 +1,79 @@
|
|
|
1
1
|
# @podlite/to-jsx
|
|
2
2
|
|
|
3
3
|
## Upcoming
|
|
4
|
+
|
|
5
|
+
## 0.0.17
|
|
6
|
+
|
|
7
|
+
- refactor
|
|
8
|
+
|
|
9
|
+
## 0.0.16
|
|
10
|
+
|
|
11
|
+
- refactor
|
|
12
|
+
|
|
4
13
|
## 0.0.15
|
|
14
|
+
|
|
5
15
|
- refactor logic for plugins
|
|
16
|
+
|
|
6
17
|
## 0.0.14
|
|
18
|
+
|
|
7
19
|
- add Strikethrough inline element support
|
|
8
20
|
- add toJSX support
|
|
21
|
+
|
|
9
22
|
## 0.0.13
|
|
23
|
+
|
|
10
24
|
- update deps
|
|
25
|
+
|
|
11
26
|
## 0.0.12
|
|
27
|
+
|
|
12
28
|
- fix imports
|
|
13
29
|
- update deps
|
|
30
|
+
|
|
14
31
|
## 0.0.11
|
|
32
|
+
|
|
15
33
|
- use <video> tags for mov/mp4 media
|
|
16
34
|
- update deps
|
|
35
|
+
|
|
17
36
|
## 0.0.10
|
|
37
|
+
|
|
18
38
|
- fix id for =table
|
|
39
|
+
|
|
19
40
|
## 0.0.9
|
|
41
|
+
|
|
20
42
|
- fix npm
|
|
43
|
+
|
|
21
44
|
## 0.0.8
|
|
45
|
+
|
|
22
46
|
- add support for =Image
|
|
23
47
|
- add caption for =Diagram
|
|
24
48
|
- add support for id html attribute
|
|
49
|
+
|
|
25
50
|
## 0.0.7
|
|
51
|
+
|
|
26
52
|
- fix deps
|
|
53
|
+
|
|
27
54
|
## 0.0.6
|
|
55
|
+
|
|
28
56
|
- fix process empty L<>
|
|
29
57
|
|
|
30
58
|
## 0.0.5
|
|
59
|
+
|
|
31
60
|
- update deps
|
|
32
61
|
- declare tree arg
|
|
62
|
+
|
|
33
63
|
## 0.0.4
|
|
64
|
+
|
|
34
65
|
- update deps
|
|
66
|
+
|
|
35
67
|
## 0.0.3
|
|
68
|
+
|
|
36
69
|
- update deps
|
|
37
70
|
|
|
38
71
|
## 0.0.2
|
|
72
|
+
|
|
39
73
|
- implement =defn
|
|
40
74
|
- implemnt =nested
|
|
41
75
|
- fix dependencies
|
|
42
76
|
|
|
43
77
|
## 0.0.1
|
|
44
|
-
- initial version
|
|
45
78
|
|
|
79
|
+
- initial version
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1 +1,41 @@
|
|
|
1
|
-
# @podlite/to-jsx
|
|
1
|
+
# @podlite/to-jsx
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
[](https://podlite.org)
|
|
6
|
+
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
**Podlite is a lightweight block-based markup language designed for flexibility and ease of use.**
|
|
10
|
+
|
|
11
|
+
Unbound by any specific domain, programming language, or concept, Podlite stands out as a universal markup language. It's versatile enough to be successfully implemented across various development fields, from web development to scientific research.
|
|
12
|
+
|
|
13
|
+
Podlite is not limited to any specific application domain, programming language, or concept.
|
|
14
|
+
|
|
15
|
+
In addition, the support for Markdown markup as a standard block adds convenience and allows for the use of familiar syntax for text formatting.
|
|
16
|
+
|
|
17
|
+
One of the key features of Podlite is its extensibility. This allows for defining unique and domain-specific blocks and expanding the language's functionality according to the requirements of your project.
|
|
18
|
+
|
|
19
|
+
Its flexibility makes it an ideal tool for creating documentation, blogs, educational materials, and much more.
|
|
20
|
+
|
|
21
|
+
Podlite aims to provide users with a means for creativity and expressing ideas in a structured form, while ensuring ease of use and high flexibility in content creation.
|
|
22
|
+
|
|
23
|
+
## Useful links
|
|
24
|
+
|
|
25
|
+
📖 _Project site_: [podlite.org](https://podlite.org)
|
|
26
|
+
|
|
27
|
+
📌 _Github_: [github.com/podlite](https://github.com/podlite/) 🤩
|
|
28
|
+
|
|
29
|
+
🖥️ _Online editor_: [pod6.in](https://pod6.in/)
|
|
30
|
+
|
|
31
|
+
🖥️ _Desktop editor/viewer_: [github.com/podlite/podlite-desktop](https://github.com/podlite/podlite-desktop) - the viewer and editor of `.podlite` and `.pod6` files for Windows, Linux and Mac.
|
|
32
|
+
|
|
33
|
+
📚 _Podlite for web_ - static site generator: [github.com/podlite/podlite-web](https://github.com/podlite/podlite-web)
|
|
34
|
+
|
|
35
|
+
## AUTHOR
|
|
36
|
+
|
|
37
|
+
Copyright (c) 2021-2024 Aliaksandr Zahatski
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
|
|
41
|
+
Released under a MIT License.
|
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
-
module.exports = require('./lib')
|
|
2
|
+
module.exports = require('./lib')
|
package/jest.config.js
CHANGED
package/jest.tsconfig.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"extends": "../../jest.tsconfig.json"}
|
|
1
|
+
{ "extends": "../../jest.tsconfig.json" }
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { PodliteExport } from 'podlite';
|
|
3
|
-
import { PodNode } from '@podlite/schema';
|
|
2
|
+
import { PodNode, PodliteExport } from '@podlite/schema';
|
|
4
3
|
export declare type CreateElement = typeof React.createElement;
|
|
5
4
|
export interface WrapElement {
|
|
6
5
|
(node: PodNode, children: React.ReactChild, ctx: any): JSX.Element;
|
|
@@ -16,9 +15,9 @@ export declare const Podlite: React.FC<{
|
|
|
16
15
|
export declare const TestPodlite: ({ children, ...options }: {
|
|
17
16
|
[x: string]: any;
|
|
18
17
|
children: any;
|
|
19
|
-
}) => JSX.Element;
|
|
20
|
-
export declare const makeTestPodlite: (podlite?: import("podlite").Podlite) => ({ children, ...options }: {
|
|
18
|
+
}) => React.JSX.Element;
|
|
19
|
+
export declare const makeTestPodlite: (podlite?: import("@podlite/schema").Podlite) => ({ children, ...options }: {
|
|
21
20
|
[x: string]: any;
|
|
22
21
|
children: any;
|
|
23
|
-
}) => JSX.Element;
|
|
22
|
+
}) => React.JSX.Element;
|
|
24
23
|
export default Podlite;
|
package/lib/index.js
CHANGED
|
@@ -1,32 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.makeTestPodlite = exports.TestPodlite = 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 schema_1 = require("@podlite/schema");
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { createElement } from 'react';
|
|
3
|
+
import { podlite as podlite_core } from 'podlite';
|
|
4
|
+
import { getNodeId, parse, makeAttrs, emptyContent, content as nodeContent, setFn, subUse, toAny, isNamedBlock, isSemanticBlock, Writer, toAnyRules, frozenIds, } from '@podlite/schema';
|
|
5
|
+
import { pluginCleanLocation as clean_plugin } from '@podlite/schema';
|
|
26
6
|
const helperMakeReact = ({ wrapElement }) => {
|
|
27
7
|
let i_key_i = 0;
|
|
28
8
|
let mapByType = {};
|
|
29
|
-
const getIdForNode = ({ type =
|
|
9
|
+
const getIdForNode = ({ type = 'notype', name = 'noname' }) => {
|
|
30
10
|
const type_idx = `${type}_${name}`;
|
|
31
11
|
if (!mapByType[type_idx]) {
|
|
32
12
|
mapByType[type_idx] = 0;
|
|
@@ -39,11 +19,11 @@ const helperMakeReact = ({ wrapElement }) => {
|
|
|
39
19
|
if (typeof node == 'string') {
|
|
40
20
|
return node;
|
|
41
21
|
}
|
|
42
|
-
const attr =
|
|
22
|
+
const { ...attr } = node;
|
|
43
23
|
const key = 'type' in node && node.type ? getIdForNode(node) : ++i_key_i;
|
|
44
24
|
const result = typeof src === 'function'
|
|
45
|
-
? src(
|
|
46
|
-
:
|
|
25
|
+
? src({ ...attr, key, children }, children)
|
|
26
|
+
: createElement(src, { ...extraProps, key }, children);
|
|
47
27
|
// // create react element and pass key
|
|
48
28
|
// if (!isValidElementType(src)) {
|
|
49
29
|
// throw new Error(`Bad React element for ${ruleName} rule `)
|
|
@@ -54,47 +34,45 @@ const helperMakeReact = ({ wrapElement }) => {
|
|
|
54
34
|
return result;
|
|
55
35
|
};
|
|
56
36
|
};
|
|
57
|
-
const Podlite = (
|
|
58
|
-
var { children } = _a, options = __rest(_a, ["children"]);
|
|
37
|
+
export const Podlite = ({ children, ...options }) => {
|
|
59
38
|
const result = podlite(children, options);
|
|
60
39
|
return result;
|
|
61
40
|
};
|
|
62
|
-
exports.Podlite = Podlite;
|
|
63
41
|
const mapToReact = (makeComponent) => {
|
|
64
|
-
const mkComponent =
|
|
42
|
+
const mkComponent = src => (writer, processor) => (node, ctx, interator) => {
|
|
65
43
|
// prepare extraProps for createElement
|
|
66
44
|
// add id attribute if exists
|
|
67
|
-
const id = (
|
|
45
|
+
const id = getNodeId(node, ctx)?.replace(/\s/g, '-');
|
|
68
46
|
// check if node.content defined
|
|
69
|
-
return makeComponent(src, node, 'content' in node ? interator(node.content,
|
|
47
|
+
return makeComponent(src, node, 'content' in node ? interator(node.content, { ...ctx }) : [], { id }, ctx);
|
|
70
48
|
};
|
|
71
49
|
// Handle nested block and :nested block attribute
|
|
72
50
|
const handleNested = (defaultHandler, implicitLevel) => {
|
|
73
51
|
return (writer, processor) => {
|
|
74
52
|
const defaultHandlerInited = defaultHandler(writer, processor);
|
|
75
53
|
return (node, ctx, interator) => {
|
|
76
|
-
const nesting = (
|
|
54
|
+
const nesting = makeAttrs(node, ctx).getFirstValue('nested') || implicitLevel;
|
|
77
55
|
const children = defaultHandlerInited(node, ctx, interator);
|
|
78
56
|
// if no nesting needs - simply return children
|
|
79
57
|
if (!nesting) {
|
|
80
58
|
return children;
|
|
81
59
|
}
|
|
82
60
|
const arr = [...Array(nesting).keys()];
|
|
83
|
-
return arr.reduce(
|
|
61
|
+
return arr.reduce(acc => makeComponent('blockquote', node, acc), children);
|
|
84
62
|
};
|
|
85
63
|
};
|
|
86
64
|
};
|
|
87
65
|
return {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
':ambient':
|
|
92
|
-
':code': mkComponent(({ children, key }) => React.createElement("code", { key: key },
|
|
93
|
-
React.createElement("pre", null, children))),
|
|
94
|
-
|
|
95
|
-
React.createElement("pre", null, children))),
|
|
96
|
-
|
|
97
|
-
':image':
|
|
66
|
+
pod: mkComponent('div'),
|
|
67
|
+
root: nodeContent,
|
|
68
|
+
data: emptyContent(),
|
|
69
|
+
':ambient': emptyContent(),
|
|
70
|
+
':code': mkComponent(({ children, key }) => (React.createElement("code", { key: key },
|
|
71
|
+
React.createElement("pre", null, children)))),
|
|
72
|
+
code: mkComponent(({ children, key }) => (React.createElement("code", { key: key },
|
|
73
|
+
React.createElement("pre", null, children)))),
|
|
74
|
+
image: nodeContent,
|
|
75
|
+
':image': setFn((node, ctx) => {
|
|
98
76
|
return mkComponent(({ children, key }) => React.createElement("img", { key: key, src: node.src, alt: node.alt }));
|
|
99
77
|
}),
|
|
100
78
|
':text': (writer, processor) => (node, ctx, interator) => {
|
|
@@ -103,45 +81,45 @@ const mapToReact = (makeComponent) => {
|
|
|
103
81
|
':verbatim': (writer, processor) => (node, ctx, interator) => {
|
|
104
82
|
return node.value;
|
|
105
83
|
},
|
|
106
|
-
'head:block':
|
|
84
|
+
'head:block': subUse({
|
|
107
85
|
// inside head don't wrap into <p>
|
|
108
|
-
':para':
|
|
109
|
-
},
|
|
86
|
+
':para': nodeContent,
|
|
87
|
+
}, setFn((node, ctx) => {
|
|
110
88
|
const { level } = node;
|
|
111
|
-
const id = (
|
|
112
|
-
return mkComponent(({ level, children, key }) =>
|
|
89
|
+
const id = getNodeId(node, ctx)?.replace(/\s/g, '-');
|
|
90
|
+
return mkComponent(({ level, children, key }) => createElement(`h${level}`, { key, id }, children));
|
|
113
91
|
})),
|
|
114
|
-
':blankline':
|
|
92
|
+
':blankline': emptyContent(),
|
|
115
93
|
':para': mkComponent('p'),
|
|
116
|
-
|
|
117
|
-
'comment:block':
|
|
118
|
-
|
|
94
|
+
para: mkComponent('div'),
|
|
95
|
+
'comment:block': emptyContent(),
|
|
96
|
+
defn: subUse([
|
|
119
97
|
// to avoid overlap para blocks handlers
|
|
120
98
|
// define general :para at first
|
|
121
99
|
{ ':para': mkComponent('dd') },
|
|
122
100
|
{ 'term:para': mkComponent('dt') },
|
|
123
|
-
],
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
React.createElement("samp", null, children))),
|
|
127
|
-
|
|
128
|
-
React.createElement("kbd", null, children))),
|
|
129
|
-
// Directives
|
|
130
|
-
':config':
|
|
101
|
+
], nodeContent),
|
|
102
|
+
nested: handleNested(nodeContent, 1),
|
|
103
|
+
output: mkComponent(({ children, key }) => (React.createElement("pre", { key: key },
|
|
104
|
+
React.createElement("samp", null, children)))),
|
|
105
|
+
input: mkComponent(({ children, key }) => (React.createElement("pre", { key: key },
|
|
106
|
+
React.createElement("kbd", null, children)))),
|
|
107
|
+
// Directives
|
|
108
|
+
':config': setFn((node, ctx) => {
|
|
131
109
|
// setup context
|
|
132
110
|
if (!ctx.hasOwnProperty('config'))
|
|
133
111
|
ctx.config = {};
|
|
134
112
|
//collect configs in context
|
|
135
113
|
ctx.config[node.name] = node.config;
|
|
136
|
-
return
|
|
114
|
+
return emptyContent();
|
|
137
115
|
}),
|
|
138
|
-
':alias':
|
|
116
|
+
':alias': setFn((node, ctx) => {
|
|
139
117
|
// set alias
|
|
140
118
|
if (!ctx.hasOwnProperty('alias'))
|
|
141
119
|
ctx.alias = {};
|
|
142
120
|
//collect configs in context
|
|
143
121
|
ctx.alias[node.name] = node.replacement;
|
|
144
|
-
return
|
|
122
|
+
return emptyContent();
|
|
145
123
|
}),
|
|
146
124
|
// Formatting codes
|
|
147
125
|
'A<>': (writer, processor) => (node, ctx, interator) => {
|
|
@@ -160,7 +138,7 @@ const mapToReact = (makeComponent) => {
|
|
|
160
138
|
const src = ctx.alias[term].join('\n');
|
|
161
139
|
const tree_1 = processor(src);
|
|
162
140
|
// now clean locations
|
|
163
|
-
const tree = (
|
|
141
|
+
const tree = clean_plugin()(tree_1);
|
|
164
142
|
if (tree[0].type === 'para') {
|
|
165
143
|
return interator(tree[0].content, ctx);
|
|
166
144
|
}
|
|
@@ -173,24 +151,27 @@ const mapToReact = (makeComponent) => {
|
|
|
173
151
|
'C<>': mkComponent('code'),
|
|
174
152
|
'E<>': (writer, processor) => (node, ctx, interator) => {
|
|
175
153
|
if ('content' in node && Array.isArray(node.content))
|
|
176
|
-
return node.content
|
|
154
|
+
return node.content
|
|
155
|
+
.filter(e => e && e.type == 'number')
|
|
156
|
+
.map(element => {
|
|
177
157
|
return String.fromCharCode(element.value);
|
|
178
|
-
})
|
|
158
|
+
})
|
|
159
|
+
.join('');
|
|
179
160
|
},
|
|
180
161
|
'I<>': mkComponent('i'),
|
|
181
162
|
'K<>': mkComponent('kbd'),
|
|
182
163
|
/**
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
164
|
+
* CSS rules for footnotes
|
|
165
|
+
|
|
166
|
+
.footnote a {
|
|
167
|
+
text-decoration: none;
|
|
168
|
+
}
|
|
169
|
+
.footnotes {
|
|
170
|
+
border-top-style: solid;
|
|
171
|
+
border-top-width: 1px;
|
|
172
|
+
border-top-color: #eee;
|
|
173
|
+
}
|
|
174
|
+
*/
|
|
194
175
|
'N<>': (writer, processor) => {
|
|
195
176
|
writer.addListener('end', () => {
|
|
196
177
|
if (!writer.hasOwnProperty('FOOTNOTES')) {
|
|
@@ -203,15 +184,15 @@ const mapToReact = (makeComponent) => {
|
|
|
203
184
|
if (!writer.hasOwnProperty('postInterator')) {
|
|
204
185
|
writer.postInterator = [];
|
|
205
186
|
}
|
|
206
|
-
const FootNotes = makeComponent(({ children, key }) => React.createElement("div", { key: `${key}_FOOTNOTES`, className: "footnotes" }, footnotes.map((footnote, id) => {
|
|
207
|
-
return React.createElement("p", { key: id },
|
|
187
|
+
const FootNotes = makeComponent(({ children, key }) => (React.createElement("div", { key: `${key}_FOOTNOTES`, className: "footnotes" }, footnotes.map((footnote, id) => {
|
|
188
|
+
return (React.createElement("p", { key: id },
|
|
208
189
|
React.createElement("sup", { id: footnote.fnId, className: "footnote" },
|
|
209
190
|
React.createElement("a", { href: `#${footnote.fnRefId}` },
|
|
210
191
|
"[",
|
|
211
192
|
footnote.gid,
|
|
212
193
|
"]")),
|
|
213
|
-
footnote.make());
|
|
214
|
-
})), {});
|
|
194
|
+
footnote.make()));
|
|
195
|
+
}))), {});
|
|
215
196
|
writer.postInterator.push(FootNotes);
|
|
216
197
|
});
|
|
217
198
|
return (node, ctx, interator) => {
|
|
@@ -234,13 +215,15 @@ const mapToReact = (makeComponent) => {
|
|
|
234
215
|
fnRefId,
|
|
235
216
|
fnId,
|
|
236
217
|
node,
|
|
237
|
-
make: () => {
|
|
218
|
+
make: () => {
|
|
219
|
+
return interator(node.content, ctx);
|
|
220
|
+
},
|
|
238
221
|
});
|
|
239
|
-
return makeComponent(({ children, key }) => React.createElement("sup", { key: key, id: fnRefId, className: "footnote" },
|
|
222
|
+
return makeComponent(({ children, key }) => (React.createElement("sup", { key: key, id: fnRefId, className: "footnote" },
|
|
240
223
|
React.createElement("a", { href: `#${fnId}` },
|
|
241
224
|
"[",
|
|
242
225
|
gid,
|
|
243
|
-
"]")), node);
|
|
226
|
+
"]"))), node);
|
|
244
227
|
};
|
|
245
228
|
},
|
|
246
229
|
'R<>': mkComponent('var'),
|
|
@@ -257,7 +240,7 @@ const mapToReact = (makeComponent) => {
|
|
|
257
240
|
writer.DEFINITIONS.push({ definition });
|
|
258
241
|
return makeComponent('dfn', node, interator(node.content, ctx));
|
|
259
242
|
},
|
|
260
|
-
|
|
243
|
+
'L<>': setFn((node, ctx) => {
|
|
261
244
|
let { meta } = node;
|
|
262
245
|
if (meta === null) {
|
|
263
246
|
meta = node.content;
|
|
@@ -269,7 +252,7 @@ const mapToReact = (makeComponent) => {
|
|
|
269
252
|
if (meta && typeof meta !== 'string' && 'value' in meta) {
|
|
270
253
|
meta = meta.value;
|
|
271
254
|
}
|
|
272
|
-
return mkComponent(({ children, key }) => React.createElement("a", { href: meta, key: key }, children));
|
|
255
|
+
return mkComponent(({ children, key }) => (React.createElement("a", { href: meta, key: key }, children)));
|
|
273
256
|
}),
|
|
274
257
|
'S<>': (writer, processor) => (node, ctx, interator) => {
|
|
275
258
|
let content = node.content || '';
|
|
@@ -278,15 +261,15 @@ const mapToReact = (makeComponent) => {
|
|
|
278
261
|
}
|
|
279
262
|
const Content = content.split('').map((symbol, index) => {
|
|
280
263
|
if (symbol === ' ')
|
|
281
|
-
return
|
|
264
|
+
return '\u00a0';
|
|
282
265
|
if (symbol === '\n')
|
|
283
266
|
return React.createElement("br", { key: index });
|
|
284
267
|
return symbol;
|
|
285
268
|
});
|
|
286
269
|
return makeComponent(({ children, key }) => children, {}, Content);
|
|
287
270
|
},
|
|
288
|
-
'V<>':
|
|
289
|
-
'Z<>':
|
|
271
|
+
'V<>': nodeContent,
|
|
272
|
+
'Z<>': emptyContent(),
|
|
290
273
|
'U<>': mkComponent('u'),
|
|
291
274
|
'X<>': (writer, processor) => (node, ctx, interator) => {
|
|
292
275
|
let { entry } = node;
|
|
@@ -299,14 +282,14 @@ const mapToReact = (makeComponent) => {
|
|
|
299
282
|
writer.INDEXTERMS = [];
|
|
300
283
|
}
|
|
301
284
|
writer.INDEXTERMS.push({
|
|
302
|
-
entry
|
|
285
|
+
entry,
|
|
303
286
|
});
|
|
304
287
|
return interator(node.content, ctx);
|
|
305
288
|
},
|
|
306
289
|
'Delete<>': mkComponent('del'),
|
|
307
290
|
// table section
|
|
308
|
-
|
|
309
|
-
const conf = (
|
|
291
|
+
table: (writer, processor) => (node, ctx, interator) => {
|
|
292
|
+
const conf = makeAttrs(node, ctx);
|
|
310
293
|
let attr = { caption: '' };
|
|
311
294
|
if (conf.exists('caption')) {
|
|
312
295
|
const caption = conf.getFirstValue('caption');
|
|
@@ -319,22 +302,20 @@ const mapToReact = (makeComponent) => {
|
|
|
319
302
|
console.warn('[jsx] no content in node');
|
|
320
303
|
return '';
|
|
321
304
|
}
|
|
322
|
-
const id = (
|
|
305
|
+
const id = getNodeId(node, ctx)?.replace(/\s/g, '-');
|
|
323
306
|
return makeComponent(({ key, children }) => {
|
|
324
|
-
return React.createElement("table", { key: key, id: id },
|
|
307
|
+
return (React.createElement("table", { key: key, id: id },
|
|
325
308
|
React.createElement("caption", { className: "caption" }, attr.caption),
|
|
326
|
-
React.createElement("tbody", null, children));
|
|
327
|
-
}, node, interator(node.content,
|
|
309
|
+
React.createElement("tbody", null, children)));
|
|
310
|
+
}, node, interator(node.content, { ...ctx }));
|
|
328
311
|
},
|
|
329
|
-
':separator':
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
312
|
+
':separator': emptyContent(),
|
|
313
|
+
table_row: mkComponent('tr'),
|
|
314
|
+
table_cell: mkComponent('td'),
|
|
315
|
+
table_head: subUse({
|
|
316
|
+
table_cell: mkComponent('th'),
|
|
334
317
|
}, mkComponent('tr')),
|
|
335
|
-
':list':
|
|
336
|
-
: node.list === 'variable' ? mkComponent('dl')
|
|
337
|
-
: mkComponent('ul')),
|
|
318
|
+
':list': setFn((node, ctx) => node.list === 'ordered' ? mkComponent('ol') : node.list === 'variable' ? mkComponent('dl') : mkComponent('ul')),
|
|
338
319
|
'item:block': (writer, processor) => (node, ctx, interator) => {
|
|
339
320
|
if (typeof node === 'string') {
|
|
340
321
|
return node;
|
|
@@ -347,83 +328,84 @@ const mapToReact = (makeComponent) => {
|
|
|
347
328
|
if (!(node.content instanceof Array)) {
|
|
348
329
|
console.error(node);
|
|
349
330
|
}
|
|
350
|
-
const id = (
|
|
351
|
-
return makeComponent('li', node, interator(node.content,
|
|
331
|
+
const id = getNodeId(node, ctx)?.replace(/\s/g, '-');
|
|
332
|
+
return makeComponent('li', node, interator(node.content, { ...ctx }), { id });
|
|
352
333
|
},
|
|
353
334
|
// table of content
|
|
354
|
-
':toc':
|
|
335
|
+
':toc': setFn((node, ctx) => {
|
|
355
336
|
const tocTitle = node.title;
|
|
356
|
-
return mkComponent(({ children, key }) => React.createElement("div", { className: "toc", key: key },
|
|
337
|
+
return mkComponent(({ children, key }) => (React.createElement("div", { className: "toc", key: key },
|
|
357
338
|
tocTitle ? React.createElement("div", { className: "toctitle" }, tocTitle) : '',
|
|
358
|
-
children));
|
|
339
|
+
children)));
|
|
359
340
|
}),
|
|
360
|
-
':toc-list':
|
|
341
|
+
':toc-list': setFn((node, ctx) => {
|
|
361
342
|
const { level } = node;
|
|
362
|
-
return mkComponent(({ children, key }) => React.createElement("ul", { className: `toc-list listlevel${level}`, key: key }, children));
|
|
343
|
+
return mkComponent(({ children, key }) => (React.createElement("ul", { className: `toc-list listlevel${level}`, key: key }, children)));
|
|
363
344
|
}),
|
|
364
|
-
':toc-item':
|
|
345
|
+
':toc-item': subUse({
|
|
365
346
|
// inside head don't wrap into <p>
|
|
366
|
-
':para':
|
|
367
|
-
},
|
|
368
|
-
return mkComponent(({ children, key }) => React.createElement("li", { className: "toc-item", key: key }, children));
|
|
347
|
+
':para': nodeContent,
|
|
348
|
+
}, setFn((node, ctx) => {
|
|
349
|
+
return mkComponent(({ children, key }) => (React.createElement("li", { className: "toc-item", key: key }, children)));
|
|
369
350
|
})),
|
|
370
351
|
};
|
|
371
352
|
};
|
|
372
|
-
function podlite(children, { file, plugins = () => { }, wrapElement, tree }, ...args) {
|
|
373
|
-
const ast = (
|
|
353
|
+
function podlite(children, { file, plugins = () => { }, wrapElement, tree, }, ...args) {
|
|
354
|
+
const ast = (tree => {
|
|
374
355
|
if (tree)
|
|
375
356
|
return tree.interator;
|
|
376
|
-
let podlite = (
|
|
357
|
+
let podlite = podlite_core({ importPlugins: true });
|
|
377
358
|
let treeAfterParsed = podlite.parse(children || file);
|
|
378
359
|
return podlite.toAst(treeAfterParsed);
|
|
379
360
|
})(tree);
|
|
380
361
|
// const ast = parse( children || content )
|
|
381
362
|
let i_key_i = 10000;
|
|
382
363
|
const makeComponent = helperMakeReact({ wrapElement });
|
|
383
|
-
const jsxPlugins =
|
|
364
|
+
const jsxPlugins = toAnyRules('toJSX', podlite_core({ importPlugins: true }).getPlugins());
|
|
384
365
|
// initialize each plugin
|
|
385
366
|
const jsxPluginInited = Object.fromEntries(Object.entries(jsxPlugins).map(([key, value]) => [key, value(makeComponent)]));
|
|
386
|
-
const rules =
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
367
|
+
const rules = {
|
|
368
|
+
...mapToReact(makeComponent),
|
|
369
|
+
...plugins(makeComponent),
|
|
370
|
+
...jsxPluginInited,
|
|
371
|
+
};
|
|
372
|
+
const writer = new Writer(s => { });
|
|
373
|
+
const res = toAny({ processor: parse })
|
|
374
|
+
.use({
|
|
375
|
+
'*:*': () => (node, ctx, interator) => {
|
|
391
376
|
// skip named blocks
|
|
392
|
-
if (
|
|
377
|
+
if (isNamedBlock(node.name)) {
|
|
393
378
|
return null;
|
|
394
379
|
}
|
|
395
|
-
if (
|
|
380
|
+
if (isSemanticBlock(node)) {
|
|
396
381
|
return makeComponent(({ key, children }) => {
|
|
397
|
-
return React.createElement("div", { key: key },
|
|
382
|
+
return (React.createElement("div", { key: key },
|
|
398
383
|
React.createElement("h1", { className: node.name, key: key }, node.name),
|
|
399
|
-
interator(node.content,
|
|
400
|
-
}, node, interator(node.content,
|
|
384
|
+
interator(node.content, { ...ctx })));
|
|
385
|
+
}, node, interator(node.content, { ...ctx }));
|
|
401
386
|
}
|
|
402
387
|
console.warn('[podlite] Not supported: ' + JSON.stringify(node, null, 2));
|
|
403
|
-
return
|
|
404
|
-
}
|
|
388
|
+
return createElement('code', { key: ++i_key_i }, `not supported node:${JSON.stringify(node, null, 2)}`);
|
|
389
|
+
},
|
|
390
|
+
})
|
|
405
391
|
.use(rules)
|
|
406
392
|
.run(ast, writer);
|
|
407
393
|
// union main react elements and post processed via onEnd event
|
|
408
394
|
return new Array().concat(res.interator, writer.postInterator);
|
|
409
395
|
}
|
|
410
396
|
// this is a helper function for using in unit test
|
|
411
|
-
const TestPodlite = (
|
|
412
|
-
|
|
413
|
-
let podlite = (0, podlite_1.podlite)({ importPlugins: true });
|
|
397
|
+
export const TestPodlite = ({ children, ...options }) => {
|
|
398
|
+
let podlite = podlite_core({ importPlugins: true });
|
|
414
399
|
// its replace all ids with "id"
|
|
415
|
-
let treeAfterParsed =
|
|
400
|
+
let treeAfterParsed = frozenIds()(podlite.parse(children));
|
|
416
401
|
const tree = podlite.toAst(treeAfterParsed);
|
|
417
|
-
return
|
|
402
|
+
return React.createElement(Podlite, { ...{ children, ...options, tree: { interator: tree } } });
|
|
418
403
|
};
|
|
419
|
-
|
|
420
|
-
const makeTestPodlite = (podlite = (0, podlite_1.podlite)({ importPlugins: true })) => (_a) => {
|
|
421
|
-
var { children } = _a, options = __rest(_a, ["children"]);
|
|
404
|
+
export const makeTestPodlite = (podlite = podlite_core({ importPlugins: true })) => ({ children, ...options }) => {
|
|
422
405
|
let treeAfterParsed = podlite.parse(children);
|
|
423
406
|
// its replace all ids with "id"
|
|
424
|
-
const tree =
|
|
425
|
-
return
|
|
407
|
+
const tree = frozenIds()(podlite.toAst(treeAfterParsed));
|
|
408
|
+
return React.createElement(Podlite, { ...{ children, ...options, tree: { interator: tree } } });
|
|
426
409
|
};
|
|
427
|
-
|
|
428
|
-
exports.default = exports.Podlite;
|
|
410
|
+
export default Podlite;
|
|
429
411
|
//# sourceMappingURL=index.js.map
|