comark-solid 0.0.2 → 0.1.0
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/LICENSE +21 -0
- package/README.md +8 -6
- package/dist/index.d.ts +3 -3
- package/dist/index.js +36 -32
- package/package.json +5 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 shiguri
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Solid renderer for [Comark](https://comark.dev).
|
|
4
4
|
|
|
5
|
-
> [!WARNING]
|
|
6
|
-
> **Pre-release: Solid 2.0 RC**
|
|
7
|
-
>
|
|
8
|
-
> This package targets the Solid 2.0 RC versions of `solid-js` and `@solidjs/web`. Solid 2.0 is not stable yet, so bugs and compatibility issues may occur. Test before using it in production. See the [official RC announcement](https://github.com/solidjs/solid/discussions/2995).
|
|
9
|
-
|
|
10
5
|
## Installation
|
|
11
6
|
|
|
12
7
|
```bash
|
|
@@ -17,13 +12,20 @@ npm install comark-solid comark
|
|
|
17
12
|
|
|
18
13
|
Parses Markdown strings and renders them directly.
|
|
19
14
|
|
|
15
|
+
String input is parsed asynchronously. Wrap the component in Solid's `Suspense` to show a fallback while parsing.
|
|
16
|
+
|
|
20
17
|
```tsx
|
|
21
18
|
import { Markdown } from "comark-solid";
|
|
19
|
+
import { Suspense } from "solid-js";
|
|
22
20
|
|
|
23
21
|
const markdown = "# Hello World";
|
|
24
22
|
|
|
25
23
|
export default function App() {
|
|
26
|
-
return
|
|
24
|
+
return (
|
|
25
|
+
<Suspense fallback={<div>Loading...</div>}>
|
|
26
|
+
<Markdown value={markdown} />
|
|
27
|
+
</Suspense>
|
|
28
|
+
);
|
|
27
29
|
}
|
|
28
30
|
```
|
|
29
31
|
|
package/dist/index.d.ts
CHANGED
|
@@ -104,7 +104,7 @@ interface MarkdownProps extends Omit<MarkdownDocumentProps, "value"> {
|
|
|
104
104
|
* @example
|
|
105
105
|
* ```tsx
|
|
106
106
|
* import { Markdown } from "comark-solid";
|
|
107
|
-
* import {
|
|
107
|
+
* import { Suspense } from "solid-js";
|
|
108
108
|
* import { CustomHeading } from "./CustomHeading";
|
|
109
109
|
*
|
|
110
110
|
* const components = {
|
|
@@ -113,12 +113,12 @@ interface MarkdownProps extends Omit<MarkdownDocumentProps, "value"> {
|
|
|
113
113
|
*
|
|
114
114
|
* export default function App() {
|
|
115
115
|
* return (
|
|
116
|
-
* <
|
|
116
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
117
117
|
* <Markdown
|
|
118
118
|
* value={source}
|
|
119
119
|
* components={components}
|
|
120
120
|
* />
|
|
121
|
-
* </
|
|
121
|
+
* </Suspense>
|
|
122
122
|
* );
|
|
123
123
|
* }
|
|
124
124
|
* ```
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { className, createComponent,
|
|
1
|
+
import { Dynamic, className, createComponent, effect, insert, mergeProps, template } from "solid-js/web";
|
|
2
2
|
import { parseMarkdown } from "comark";
|
|
3
3
|
import { isMarkdownDocument, resolveAttributes } from "comark/utils";
|
|
4
|
-
import {
|
|
4
|
+
import { Show, Suspense, createMemo, createResource, mergeProps as mergeProps$1 } from "solid-js";
|
|
5
5
|
//#region src/utils/ast.ts
|
|
6
6
|
function getTag(node) {
|
|
7
7
|
if (Array.isArray(node) && node.length >= 1 && typeof node[0] === "string") return node[0];
|
|
@@ -17,7 +17,7 @@ function getChildren(node) {
|
|
|
17
17
|
}
|
|
18
18
|
//#endregion
|
|
19
19
|
//#region src/components/MarkdownDocument.tsx
|
|
20
|
-
var _tmpl$ =
|
|
20
|
+
var _tmpl$ = /*#__PURE__*/ template(`<div>`);
|
|
21
21
|
const DEFAULT_LOCAL_CONTEXT = {
|
|
22
22
|
parent: void 0,
|
|
23
23
|
renderData: {
|
|
@@ -81,24 +81,22 @@ function createNodeRenderer(components) {
|
|
|
81
81
|
...context.renderData,
|
|
82
82
|
props
|
|
83
83
|
} : context.renderData);
|
|
84
|
-
|
|
85
|
-
return createComponent(Loading, {
|
|
84
|
+
return createComponent(Suspense, {
|
|
86
85
|
fallback: null,
|
|
87
86
|
get children() {
|
|
88
|
-
return createComponent(
|
|
87
|
+
return createComponent(Dynamic, mergeProps({ component }, props, slots));
|
|
89
88
|
}
|
|
90
89
|
});
|
|
91
90
|
}
|
|
92
91
|
function renderNativeElement(element, context) {
|
|
93
92
|
const { tag, node } = element;
|
|
94
93
|
const props = resolveProps(node, context.renderData);
|
|
95
|
-
|
|
96
|
-
if (VOID_ELEMENTS.has(tag)) return createComponent(Component, props);
|
|
94
|
+
if (VOID_ELEMENTS.has(tag)) return createComponent(Dynamic, mergeProps({ component: tag }, props));
|
|
97
95
|
const children = getChildren(node).map((child) => renderNode(child, {
|
|
98
96
|
...context,
|
|
99
97
|
parent: node
|
|
100
98
|
})).filter(Boolean);
|
|
101
|
-
return createComponent(
|
|
99
|
+
return createComponent(Dynamic, mergeProps({ component: tag }, props, { children }));
|
|
102
100
|
}
|
|
103
101
|
function partitionIntoSlots(node, childRenderData) {
|
|
104
102
|
const defaultSlot = [];
|
|
@@ -152,7 +150,7 @@ function createNodeRenderer(components) {
|
|
|
152
150
|
* ```
|
|
153
151
|
*/
|
|
154
152
|
const MarkdownDocument = (_props) => {
|
|
155
|
-
const props =
|
|
153
|
+
const props = mergeProps$1({
|
|
156
154
|
components: {},
|
|
157
155
|
data: {},
|
|
158
156
|
class: void 0
|
|
@@ -172,12 +170,12 @@ const MarkdownDocument = (_props) => {
|
|
|
172
170
|
})).filter(Boolean);
|
|
173
171
|
});
|
|
174
172
|
const wrapperClass = createMemo(() => ["comark-content", props.class].map((cls) => cls?.trim()).filter(Boolean).join(" "));
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
className(_el$,
|
|
179
|
-
|
|
180
|
-
|
|
173
|
+
return (() => {
|
|
174
|
+
var _el$ = _tmpl$();
|
|
175
|
+
insert(_el$, renderedNodes);
|
|
176
|
+
effect(() => className(_el$, wrapperClass()));
|
|
177
|
+
return _el$;
|
|
178
|
+
})();
|
|
181
179
|
};
|
|
182
180
|
//#endregion
|
|
183
181
|
//#region src/components/Markdown.tsx
|
|
@@ -192,7 +190,7 @@ const MarkdownDocument = (_props) => {
|
|
|
192
190
|
* @example
|
|
193
191
|
* ```tsx
|
|
194
192
|
* import { Markdown } from "comark-solid";
|
|
195
|
-
* import {
|
|
193
|
+
* import { Suspense } from "solid-js";
|
|
196
194
|
* import { CustomHeading } from "./CustomHeading";
|
|
197
195
|
*
|
|
198
196
|
* const components = {
|
|
@@ -201,38 +199,44 @@ const MarkdownDocument = (_props) => {
|
|
|
201
199
|
*
|
|
202
200
|
* export default function App() {
|
|
203
201
|
* return (
|
|
204
|
-
* <
|
|
202
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
205
203
|
* <Markdown
|
|
206
204
|
* value={source}
|
|
207
205
|
* components={components}
|
|
208
206
|
* />
|
|
209
|
-
* </
|
|
207
|
+
* </Suspense>
|
|
210
208
|
* );
|
|
211
209
|
* }
|
|
212
210
|
* ```
|
|
213
211
|
*/
|
|
214
212
|
const Markdown = (_props) => {
|
|
215
|
-
const props =
|
|
213
|
+
const props = mergeProps$1({
|
|
216
214
|
components: {},
|
|
217
215
|
data: {}
|
|
218
216
|
}, _props);
|
|
217
|
+
const [parsed] = createResource(() => typeof props.value === "string" ? [props.value, props.options] : null, ([value, options]) => parseMarkdown(value, options));
|
|
219
218
|
const document = createMemo(() => {
|
|
220
219
|
const value = props.value;
|
|
221
|
-
return isMarkdownDocument(value) ? value :
|
|
220
|
+
return isMarkdownDocument(value) ? value : parsed();
|
|
222
221
|
});
|
|
223
|
-
return createComponent(
|
|
224
|
-
get
|
|
222
|
+
return createComponent(Show, {
|
|
223
|
+
get when() {
|
|
225
224
|
return document();
|
|
226
225
|
},
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
226
|
+
children: (value) => createComponent(MarkdownDocument, {
|
|
227
|
+
get value() {
|
|
228
|
+
return value();
|
|
229
|
+
},
|
|
230
|
+
get components() {
|
|
231
|
+
return props.components;
|
|
232
|
+
},
|
|
233
|
+
get data() {
|
|
234
|
+
return props.data;
|
|
235
|
+
},
|
|
236
|
+
get ["class"]() {
|
|
237
|
+
return props.class;
|
|
238
|
+
}
|
|
239
|
+
})
|
|
236
240
|
});
|
|
237
241
|
};
|
|
238
242
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comark-solid",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Solid renderer for Comark.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"comark",
|
|
@@ -34,23 +34,21 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@solidjs/testing-library": "^
|
|
38
|
-
"@solidjs/vite-plugin": "^3.0.0-next.39",
|
|
39
|
-
"@solidjs/web": "2.0.0-rc.6",
|
|
37
|
+
"@solidjs/testing-library": "^0.8.10",
|
|
40
38
|
"@testing-library/jest-dom": "^7.0.1",
|
|
41
39
|
"bumpp": "^11.1.0",
|
|
42
40
|
"comark": "^0.6.2",
|
|
43
41
|
"eslint-plugin-solid": "~0.18.0",
|
|
44
42
|
"jsdom": "^30.0.1",
|
|
45
|
-
"solid-js": "^
|
|
43
|
+
"solid-js": "^1.9.15",
|
|
46
44
|
"typescript": "^7.0.2",
|
|
47
45
|
"vite": "npm:@voidzero-dev/vite-plus-core@0.3.0",
|
|
46
|
+
"vite-plugin-solid": "^2.11.14",
|
|
48
47
|
"vite-plus": "0.3.0"
|
|
49
48
|
},
|
|
50
49
|
"peerDependencies": {
|
|
51
|
-
"@solidjs/web": "^2.0.0-rc.6",
|
|
52
50
|
"comark": "^0.6.2",
|
|
53
|
-
"solid-js": "^
|
|
51
|
+
"solid-js": "^1.9.0"
|
|
54
52
|
},
|
|
55
53
|
"devEngines": {
|
|
56
54
|
"packageManager": {
|