defuss-markdown 1.0.0 → 1.0.2
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/README.md +8 -6
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -15
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# defuss-markdown
|
|
2
2
|
|
|
3
|
-
Incremental Markdown rendering for Defuss, using Incremark as the parser core.
|
|
3
|
+
Incremental Markdown rendering for Defuss, using Incremark as the parser core. It also supports custom JSX / component rendering.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -61,16 +61,18 @@ async function updateWithMarkdown(
|
|
|
61
61
|
|
|
62
62
|
### `FALL_THROUGH`
|
|
63
63
|
|
|
64
|
-
A sentinel symbol exported alongside `updateWithMarkdown`. Return it from a custom `nodeRenderer` to fall back to the built-in renderer for that node
|
|
64
|
+
A sentinel symbol exported alongside `updateWithMarkdown`. Return it from a custom `nodeRenderer` to fall back to the built-in renderer for that node.
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
The second argument `context` exposes `renderChildren(node.children, context)` and `renderNode(node, context)` so you can recursively render a node's children inside your custom wrapper:
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
67
69
|
import { updateWithMarkdown, FALL_THROUGH } from "defuss-markdown";
|
|
68
70
|
|
|
69
71
|
await updateWithMarkdown(target, markdown, {
|
|
70
|
-
nodeRenderer: (node) => {
|
|
72
|
+
nodeRenderer: (node, context) => {
|
|
71
73
|
if (node.type === "paragraph") {
|
|
72
|
-
//
|
|
73
|
-
return
|
|
74
|
+
// Wrap paragraphs in a custom <div>, but still render their children
|
|
75
|
+
return <div class="custom-p">{...context.renderChildren(node.children, context)}</div>;
|
|
74
76
|
}
|
|
75
77
|
return FALL_THROUGH; // default rendering for everything else
|
|
76
78
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ interface MarkdownAstNode {
|
|
|
11
11
|
children?: MarkdownAstNode[];
|
|
12
12
|
value?: string;
|
|
13
13
|
depth?: number;
|
|
14
|
-
ordered?: boolean;
|
|
14
|
+
ordered?: boolean | null;
|
|
15
15
|
start?: number;
|
|
16
16
|
spread?: boolean;
|
|
17
17
|
checked?: boolean | null;
|
|
@@ -30,8 +30,7 @@ interface MarkdownAstNode {
|
|
|
30
30
|
name?: string;
|
|
31
31
|
value?: string;
|
|
32
32
|
}>;
|
|
33
|
-
data?:
|
|
34
|
-
[key: string]: unknown;
|
|
33
|
+
data?: unknown;
|
|
35
34
|
}
|
|
36
35
|
interface ParserLike {
|
|
37
36
|
append?: (chunk: string) => unknown;
|
|
@@ -39,7 +38,6 @@ interface ParserLike {
|
|
|
39
38
|
render?: (content: string) => unknown;
|
|
40
39
|
reset?: () => void;
|
|
41
40
|
blocks?: MarkdownBlockLike[];
|
|
42
|
-
completedBlocks?: MarkdownBlockLike[];
|
|
43
41
|
pendingBlocks?: MarkdownBlockLike[];
|
|
44
42
|
pendingBlock?: MarkdownBlockLike | null;
|
|
45
43
|
getBlocks?: () => MarkdownBlockLike[];
|
|
@@ -60,9 +58,11 @@ interface RenderContext {
|
|
|
60
58
|
allowDangerousHtml: boolean;
|
|
61
59
|
nodeRenderer?: UpdateWithMarkdownOptions["nodeRenderer"];
|
|
62
60
|
cellTag?: "td" | "th";
|
|
61
|
+
renderNode: (node: MarkdownAstNode, context: RenderContext) => VNodeChild;
|
|
62
|
+
renderChildren: (children: MarkdownAstNode[] | undefined, context: RenderContext) => VNodeChild[];
|
|
63
63
|
}
|
|
64
64
|
declare function updateWithMarkdown(target: Element | Ref, input: string | Promise<string> | AsyncIterable<string> | AsyncIterator<string>, options?: UpdateWithMarkdownOptions): Promise<void>;
|
|
65
65
|
|
|
66
66
|
export { FALL_THROUGH, updateWithMarkdown };
|
|
67
|
-
export type { DefussPrimitive, MarkdownAstNode, MarkdownBlockLike, ParserLike, UpdateWithMarkdownOptions };
|
|
67
|
+
export type { DefussPrimitive, MarkdownAstNode, MarkdownBlockLike, ParserLike, RenderContext, UpdateWithMarkdownOptions };
|
|
68
68
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sources":["../../src/index.ts"],"mappings":";;KAEY,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;UAE1D,iBAAiB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sources":["../../src/index.ts"],"mappings":";;KAEY,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;UAE1D,iBAAiB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,eAAe,CAAC;IACtB,MAAM,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,MAAM,CAAC;CAC1C;UAEgB,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,eAAe,EAAE,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,IAAI,CAAC,C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O,CAAC;IAC7B,YAAY,CAAC,EAAE,CACd,KAAK,EAAE,iBAAiB,EACxB,QAAQ,EAAE,UAAU,KAChB,UAAU,CAAC;IAChB,YAAY,CAAC,EAAE,CACd,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,aAAa,KAClB,UAAU,GAAG,OAAO,YAAY,CAAC;CACtC;QAEM,MAAM,YAAY,eAA8C,CAAC;UAEvD,aAAa;IAC7B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,YAAY,CAAC,EAAE,yBAAyB,CAAC,cAAc,CAAC,CAAC;IACzD,OAAO,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACtB,UAAU,EAAE,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,KAAK,UAAU,CAAC;IAC1E,cAAc,EAAE,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,SAAS,EAAE,OAAO,EAAE,aAAa,KAAK,UAAU,EAAE,CAAC;CAClG;iBAcqB,kBAAkB,CACvC,MAAM,EAAE,OAAO,GAAG,GAAG,EACrB,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,EAC/E,OAAO,GAAE,yBAA8B,GACrC,OAAO,CAAC,IAAI,CAAC,CAsBf;;;;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -32,21 +32,14 @@ async function getParser(options) {
|
|
|
32
32
|
if (options.createParser) {
|
|
33
33
|
return await options.createParser();
|
|
34
34
|
}
|
|
35
|
-
const incremark = await
|
|
35
|
+
const incremark = await import('@incremark/core');
|
|
36
36
|
const parserOptions = { ...DEFAULT_PARSER_OPTIONS, ...options.parserOptions ?? {} };
|
|
37
|
-
if (typeof incremark
|
|
37
|
+
if (typeof incremark.createIncremarkParser === "function") {
|
|
38
38
|
return incremark.createIncremarkParser(parserOptions);
|
|
39
39
|
}
|
|
40
|
-
if (typeof incremark
|
|
40
|
+
if (typeof incremark.IncremarkParser === "function") {
|
|
41
41
|
return new incremark.IncremarkParser(parserOptions);
|
|
42
42
|
}
|
|
43
|
-
if (typeof incremark?.default === "function") {
|
|
44
|
-
try {
|
|
45
|
-
return new incremark.default(parserOptions);
|
|
46
|
-
} catch {
|
|
47
|
-
return incremark.default(parserOptions);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
43
|
throw new Error(
|
|
51
44
|
"Could not construct an Incremark parser. Provide options.parser or options.createParser, or install @incremark/core with either createIncremarkParser() or IncremarkParser exported."
|
|
52
45
|
);
|
|
@@ -81,7 +74,7 @@ async function renderIntoElement(target, jsx, options) {
|
|
|
81
74
|
await options.render(jsx, target);
|
|
82
75
|
return;
|
|
83
76
|
}
|
|
84
|
-
const defuss = await
|
|
77
|
+
const defuss = await import('defuss');
|
|
85
78
|
const render = defuss?.render ?? defuss?.default?.render ?? defuss?.default ?? null;
|
|
86
79
|
if (typeof render !== "function") {
|
|
87
80
|
throw new Error(
|
|
@@ -93,7 +86,9 @@ async function renderIntoElement(target, jsx, options) {
|
|
|
93
86
|
function renderBlocks(blocks, options) {
|
|
94
87
|
const context = {
|
|
95
88
|
allowDangerousHtml: Boolean(options.allowDangerousHtml),
|
|
96
|
-
nodeRenderer: options.nodeRenderer
|
|
89
|
+
nodeRenderer: options.nodeRenderer,
|
|
90
|
+
renderNode,
|
|
91
|
+
renderChildren
|
|
97
92
|
};
|
|
98
93
|
return blocks.map((block) => {
|
|
99
94
|
const rendered = applyBlockKey(
|
|
@@ -470,8 +465,5 @@ async function* toAsyncIterable(input) {
|
|
|
470
465
|
yield result.value;
|
|
471
466
|
}
|
|
472
467
|
}
|
|
473
|
-
async function dynamicModuleImport(specifier) {
|
|
474
|
-
return Function("specifier", "return import(specifier)")(specifier);
|
|
475
|
-
}
|
|
476
468
|
|
|
477
469
|
export { FALL_THROUGH, updateWithMarkdown };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "defuss-markdown",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Incremental Markdown -> Defuss JSX bridge built on Incremark core.",
|
|
6
6
|
"keywords": [
|
|
@@ -37,8 +37,10 @@
|
|
|
37
37
|
"README.md",
|
|
38
38
|
"LICENSE"
|
|
39
39
|
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@incremark/core": "^1.0.2"
|
|
42
|
+
},
|
|
40
43
|
"peerDependencies": {
|
|
41
|
-
"@incremark/core": "^1.0.2",
|
|
42
44
|
"defuss": "^3.4.5"
|
|
43
45
|
},
|
|
44
46
|
"scripts": {
|
|
@@ -54,4 +56,4 @@
|
|
|
54
56
|
"typescript": "^6.0.2",
|
|
55
57
|
"vitest": "^4.1.2"
|
|
56
58
|
}
|
|
57
|
-
}
|
|
59
|
+
}
|