@aparte/plugin-streaming-markdown 0.2.0-alpha.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 +23 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 aparté
|
|
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
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @aparte/plugin-streaming-markdown
|
|
2
|
+
|
|
3
|
+
Incremental (token-by-token) Markdown rendering for [aparté](https://github.com/apartejs/aparte) via
|
|
4
|
+
[`streaming-markdown`](https://github.com/thetarnav/streaming-markdown). Parses only the new text and
|
|
5
|
+
**appends** DOM nodes per streamed chunk — no per-token re-parse or `innerHTML` rebuild.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @aparte/plugin-streaming-markdown @aparte/core streaming-markdown
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { setupStreamingMarkdownProvider } from '@aparte/plugin-streaming-markdown';
|
|
13
|
+
|
|
14
|
+
setupStreamingMarkdownProvider();
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`@aparte/core` and `streaming-markdown` are **peer dependencies**. Pair it with a one-shot provider
|
|
18
|
+
(e.g. `@aparte/plugin-marked`) for finished / re-rendered messages.
|
|
19
|
+
|
|
20
|
+
**Security**: the streaming path writes DOM directly, bypassing the one-shot sanitizer, so it enforces
|
|
21
|
+
the URL policy live — a streamed `[x](javascript:…)` never produces a clickable `javascript:` link.
|
|
22
|
+
|
|
23
|
+
> ESM-only. Part of the aparté monorepo.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register `streaming-markdown` as aparté's incremental (streaming) Markdown
|
|
3
|
+
* renderer.
|
|
4
|
+
*
|
|
5
|
+
* Once registered, the chat bubble feeds each streamed token chunk to a
|
|
6
|
+
* persistent incremental parser that parses only the new text and APPENDS DOM
|
|
7
|
+
* nodes — O(n) over the whole message, with no per-token re-parse or
|
|
8
|
+
* `innerHTML` rebuild. Finished / re-rendered messages still go through the
|
|
9
|
+
* one-shot `setMarkdownProvider` (e.g. `@aparte/plugin-marked`).
|
|
10
|
+
*
|
|
11
|
+
* Framework-agnostic — vanilla DOM, no framework imports.
|
|
12
|
+
*
|
|
13
|
+
* **Security**: the streaming path writes DOM nodes directly and therefore
|
|
14
|
+
* bypasses the one-shot `AparteConfig.sanitizeHtml`. To keep the same URL policy
|
|
15
|
+
* live (an attacker-controlled `[x](javascript:…)` streamed token would produce
|
|
16
|
+
* a clickable `javascript:` link before the final re-render sanitises it), the
|
|
17
|
+
* renderer's `set_attr` is wrapped to drop any `href`/`src` whose scheme fails
|
|
18
|
+
* {@link isSafeUrl}. The one-shot re-render at `end()` remains the full-fidelity
|
|
19
|
+
* re-sanitisation.
|
|
20
|
+
*
|
|
21
|
+
* Call once at application startup.
|
|
22
|
+
*/
|
|
23
|
+
export declare function setupStreamingMarkdownProvider(): void;
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,8BAA8B,IAAI,IAAI,CAerD"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AparteConfig, isSafeUrl } from "@aparte/core";
|
|
2
|
+
import { default_renderer, HREF, SRC, parser, parser_end, parser_write } from "streaming-markdown";
|
|
3
|
+
function setupStreamingMarkdownProvider() {
|
|
4
|
+
AparteConfig.setStreamingMarkdownProvider((target) => {
|
|
5
|
+
const renderer = default_renderer(target);
|
|
6
|
+
const originalSetAttr = renderer.set_attr;
|
|
7
|
+
renderer.set_attr = (data, type, value) => {
|
|
8
|
+
if (type === HREF && !isSafeUrl(value, "a")) return;
|
|
9
|
+
if (type === SRC && !isSafeUrl(value, "img")) return;
|
|
10
|
+
originalSetAttr(data, type, value);
|
|
11
|
+
};
|
|
12
|
+
const p = parser(renderer);
|
|
13
|
+
return {
|
|
14
|
+
write: (chunk) => {
|
|
15
|
+
parser_write(p, chunk);
|
|
16
|
+
},
|
|
17
|
+
end: () => {
|
|
18
|
+
parser_end(p);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
setupStreamingMarkdownProvider
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { AparteConfig, isSafeUrl } from '@aparte/core';\nimport { parser, parser_write, parser_end, default_renderer, HREF, SRC } from 'streaming-markdown';\n\n/**\n * Register `streaming-markdown` as aparté's incremental (streaming) Markdown\n * renderer.\n *\n * Once registered, the chat bubble feeds each streamed token chunk to a\n * persistent incremental parser that parses only the new text and APPENDS DOM\n * nodes — O(n) over the whole message, with no per-token re-parse or\n * `innerHTML` rebuild. Finished / re-rendered messages still go through the\n * one-shot `setMarkdownProvider` (e.g. `@aparte/plugin-marked`).\n *\n * Framework-agnostic — vanilla DOM, no framework imports.\n *\n * **Security**: the streaming path writes DOM nodes directly and therefore\n * bypasses the one-shot `AparteConfig.sanitizeHtml`. To keep the same URL policy\n * live (an attacker-controlled `[x](javascript:…)` streamed token would produce\n * a clickable `javascript:` link before the final re-render sanitises it), the\n * renderer's `set_attr` is wrapped to drop any `href`/`src` whose scheme fails\n * {@link isSafeUrl}. The one-shot re-render at `end()` remains the full-fidelity\n * re-sanitisation.\n *\n * Call once at application startup.\n */\nexport function setupStreamingMarkdownProvider(): void {\n AparteConfig.setStreamingMarkdownProvider((target: HTMLElement) => {\n const renderer = default_renderer(target);\n const originalSetAttr = renderer.set_attr;\n renderer.set_attr = (data, type, value) => {\n if (type === HREF && !isSafeUrl(value, 'a')) return;\n if (type === SRC && !isSafeUrl(value, 'img')) return;\n originalSetAttr(data, type, value);\n };\n const p = parser(renderer);\n return {\n write: (chunk: string): void => { parser_write(p, chunk); },\n end: (): void => { parser_end(p); },\n };\n });\n}\n"],"names":[],"mappings":";;AAyBO,SAAS,iCAAuC;AACnD,eAAa,6BAA6B,CAAC,WAAwB;AAC/D,UAAM,WAAW,iBAAiB,MAAM;AACxC,UAAM,kBAAkB,SAAS;AACjC,aAAS,WAAW,CAAC,MAAM,MAAM,UAAU;AACvC,UAAI,SAAS,QAAQ,CAAC,UAAU,OAAO,GAAG,EAAG;AAC7C,UAAI,SAAS,OAAO,CAAC,UAAU,OAAO,KAAK,EAAG;AAC9C,sBAAgB,MAAM,MAAM,KAAK;AAAA,IACrC;AACA,UAAM,IAAI,OAAO,QAAQ;AACzB,WAAO;AAAA,MACH,OAAO,CAAC,UAAwB;AAAE,qBAAa,GAAG,KAAK;AAAA,MAAG;AAAA,MAC1D,KAAK,MAAY;AAAE,mBAAW,CAAC;AAAA,MAAG;AAAA,IAAA;AAAA,EAE1C,CAAC;AACL;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aparte/plugin-streaming-markdown",
|
|
3
|
+
"version": "0.2.0-alpha.0",
|
|
4
|
+
"description": "Incremental (token-by-token) Markdown rendering for aparté via streaming-markdown, with a live URL-scheme guard.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"@aparte-workspace/source": "./src/index.ts",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"streaming-markdown": "^0.2.15",
|
|
28
|
+
"@aparte/core": "0.2.0-alpha.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"streaming-markdown": "^0.2.15",
|
|
32
|
+
"typescript": "^5.4.0",
|
|
33
|
+
"vite": "^6.0.0",
|
|
34
|
+
"vite-plugin-dts": "^4.5.4",
|
|
35
|
+
"@aparte/core": "0.2.0-alpha.0"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"aparte",
|
|
39
|
+
"plugin",
|
|
40
|
+
"markdown",
|
|
41
|
+
"streaming",
|
|
42
|
+
"incremental"
|
|
43
|
+
],
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/apartejs/aparte.git",
|
|
48
|
+
"directory": "packages/plugins/streaming-markdown"
|
|
49
|
+
},
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/apartejs/aparte/issues"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"dev": "vite",
|
|
55
|
+
"build": "vite build && tsc -b --emitDeclarationOnly --force",
|
|
56
|
+
"preview": "vite preview",
|
|
57
|
+
"test": "vitest",
|
|
58
|
+
"test:run": "vitest run",
|
|
59
|
+
"test:coverage": "vitest run --coverage"
|
|
60
|
+
}
|
|
61
|
+
}
|