@tanstack/markdown 0.0.10 → 0.0.11
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
CHANGED
|
@@ -10,6 +10,7 @@ A tiny, fast, deterministic Markdown parser and renderer for blogs and documenta
|
|
|
10
10
|
- serializable AST
|
|
11
11
|
- safe defaults for raw HTML and executable URLs
|
|
12
12
|
- optional docs extensions and external syntax highlighting
|
|
13
|
+
- optional AI streaming profile
|
|
13
14
|
|
|
14
15
|
```bash
|
|
15
16
|
pnpm add @tanstack/markdown
|
|
@@ -50,6 +51,7 @@ TanStack Markdown targets controlled technical content. It supports the Markdown
|
|
|
50
51
|
- [Syntax Profile](./docs/core-concepts/syntax-profile.md)
|
|
51
52
|
- [React Guide](./docs/guides/react.md)
|
|
52
53
|
- [Octane Guide](./docs/guides/octane.md)
|
|
54
|
+
- [AI Streaming](./docs/guides/ai-streaming.md)
|
|
53
55
|
- [Syntax Highlighting](./docs/guides/syntax-highlighting.md)
|
|
54
56
|
- [Extensions](./docs/guides/extensions.md)
|
|
55
57
|
- [API Reference](./docs/reference/index.md)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../src/extensions/streaming.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA2B,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE7E,wBAAgB,0BAA0B,IAAI,iBAAiB,CAQ9D"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export function streamingMarkdownExtension() {
|
|
2
|
+
return {
|
|
3
|
+
name: 'streaming',
|
|
4
|
+
transformDocument(document) {
|
|
5
|
+
const children = trimTrailingPlaceholder(document.children);
|
|
6
|
+
return children === document.children ? document : { ...document, children };
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function trimTrailingPlaceholder(children) {
|
|
11
|
+
const last = children.at(-1);
|
|
12
|
+
if (!last)
|
|
13
|
+
return children;
|
|
14
|
+
const trimmed = trimBlock(last);
|
|
15
|
+
if (trimmed === last)
|
|
16
|
+
return children;
|
|
17
|
+
if (!trimmed)
|
|
18
|
+
return children.slice(0, -1);
|
|
19
|
+
return [...children.slice(0, -1), trimmed];
|
|
20
|
+
}
|
|
21
|
+
function trimBlock(node) {
|
|
22
|
+
if (node.type === 'heading' && node.children.length === 0)
|
|
23
|
+
return undefined;
|
|
24
|
+
if (node.type === 'blockquote') {
|
|
25
|
+
const children = trimTrailingPlaceholder(node.children);
|
|
26
|
+
if (children.length === 0)
|
|
27
|
+
return undefined;
|
|
28
|
+
return children === node.children ? node : { ...node, children };
|
|
29
|
+
}
|
|
30
|
+
if (node.type !== 'list')
|
|
31
|
+
return node;
|
|
32
|
+
const last = node.items.at(-1);
|
|
33
|
+
if (!last)
|
|
34
|
+
return undefined;
|
|
35
|
+
const item = trimListItem(last);
|
|
36
|
+
if (item === last)
|
|
37
|
+
return node;
|
|
38
|
+
const items = item ? [...node.items.slice(0, -1), item] : node.items.slice(0, -1);
|
|
39
|
+
return items.length === 0 ? undefined : { ...node, items };
|
|
40
|
+
}
|
|
41
|
+
function trimListItem(item) {
|
|
42
|
+
const children = trimTrailingPlaceholder(item.children);
|
|
43
|
+
if (children.length === 0)
|
|
44
|
+
return undefined;
|
|
45
|
+
return children === item.children ? item : { ...item, children };
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/markdown",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A tiny, fast, deterministic Markdown renderer for blogs and documentation.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -61,6 +61,10 @@
|
|
|
61
61
|
"types": "./dist/extensions/headings.d.ts",
|
|
62
62
|
"import": "./dist/extensions/headings.js"
|
|
63
63
|
},
|
|
64
|
+
"./extensions/streaming": {
|
|
65
|
+
"types": "./dist/extensions/streaming.d.ts",
|
|
66
|
+
"import": "./dist/extensions/streaming.js"
|
|
67
|
+
},
|
|
64
68
|
"./extensions/tabs": {
|
|
65
69
|
"types": "./dist/extensions/tabs.d.ts",
|
|
66
70
|
"import": "./dist/extensions/tabs.js"
|