markemental 0.2.0 → 0.3.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/README.md +29 -16
- package/dist/index.cjs +653 -394
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +388 -304
- package/dist/index.d.ts +388 -304
- package/dist/index.js +648 -383
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,15 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
Incremental modular markdown renderer. Push markdown in arbitrarily-sized chunks and complete blocks render to the target as they arrive, instead of waiting for the full document.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Two pipelines cover the GFM/CommonMark flavors, and the environment is implicit: the same code drives a live page in the browser and lightweight DOMs like linkedom on the server through a minimal `DOMNodeLike` interface.
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
11
|
- Streaming input: `push()` chunks as they arrive, `flush()` the remainder.
|
|
12
|
+
- Incremental commit: tables render row-by-row from the delimiter row on, and lists item-by-item, instead of waiting for the whole block.
|
|
12
13
|
- Blocks: headings, paragraphs, fenced code, bullet and ordered lists, blockquotes, thematic breaks.
|
|
13
14
|
- Inlines: emphasis, strong, inline code, links, images, autolinks, escapes, hard breaks.
|
|
14
|
-
- GFM extras: tables (with column alignment) and strikethrough; CommonMark
|
|
15
|
-
-
|
|
15
|
+
- GFM extras: tables (with column alignment) and strikethrough; CommonMark has no tables, so table syntax renders as plain paragraph text.
|
|
16
|
+
- Pipelines batch DOM writes on `requestAnimationFrame` when given a scheduler.
|
|
16
17
|
|
|
17
18
|
## Install
|
|
18
19
|
|
|
@@ -31,9 +32,9 @@ npm install linkedom
|
|
|
31
32
|
Render a streamed response into a live page:
|
|
32
33
|
|
|
33
34
|
```ts
|
|
34
|
-
import {
|
|
35
|
+
import { createGFMPipeline } from "markemental";
|
|
35
36
|
|
|
36
|
-
const pipeline =
|
|
37
|
+
const pipeline = createGFMPipeline(
|
|
37
38
|
document.getElementById("out")!,
|
|
38
39
|
document,
|
|
39
40
|
{},
|
|
@@ -50,31 +51,43 @@ Render on the server with linkedom:
|
|
|
50
51
|
|
|
51
52
|
```ts
|
|
52
53
|
import { parseHTML } from "linkedom";
|
|
53
|
-
import {
|
|
54
|
+
import { createGFMPipeline } from "markemental";
|
|
54
55
|
|
|
55
56
|
const { document } = parseHTML("<div></div>");
|
|
56
57
|
const target = document.querySelector("div")!;
|
|
57
|
-
const pipeline =
|
|
58
|
+
const pipeline = createGFMPipeline(target, document, {});
|
|
58
59
|
|
|
59
60
|
await pipeline.push("# Hello\n\nWorld\n");
|
|
60
61
|
await pipeline.flush();
|
|
61
62
|
console.log(target.innerHTML);
|
|
62
63
|
```
|
|
63
64
|
|
|
64
|
-
Pick a pipeline by
|
|
65
|
+
Pick a pipeline by flavor:
|
|
65
66
|
|
|
66
|
-
| Factory |
|
|
67
|
-
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
70
|
-
| `createBackendGFMPipeline` | server | GFM |
|
|
71
|
-
| `createBackendCommonMarkPipeline` | server | CommonMark |
|
|
67
|
+
| Factory | Flavor |
|
|
68
|
+
|---|---|
|
|
69
|
+
| `createGFMPipeline` | GFM |
|
|
70
|
+
| `createCommonMarkPipeline` | CommonMark |
|
|
72
71
|
|
|
73
|
-
The trailing partial block is held back until more input completes it or `flush()` runs. Pushing after `flush()` throws. See the TSDoc on each factory for details.
|
|
72
|
+
The trailing partial block is held back until more input completes it or `flush()` runs. Tables commit once the delimiter row arrives and lists commit per item, so large blocks render progressively. Pushing after `flush()` throws. See the TSDoc on each factory for details.
|
|
73
|
+
|
|
74
|
+
## Custom renderers
|
|
75
|
+
|
|
76
|
+
Implement `MarkdownRenderer` to bring your own flavor or wrap a third-party parser, and compose it with any target through `createMarkdownPipeline`:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { createMarkdownPipeline, createRenderTarget } from "markemental";
|
|
80
|
+
|
|
81
|
+
const pipeline = createMarkdownPipeline(
|
|
82
|
+
new MyRenderer(createRenderTarget(document.getElementById("out")!), document),
|
|
83
|
+
);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The pipeline splits pushed chunks into lines and feeds them to the renderer one at a time; the renderer owns its target, document, and parse state. See the TSDoc on `createMarkdownPipeline` and `MarkdownRenderer` for details.
|
|
74
87
|
|
|
75
88
|
## MVP limitations
|
|
76
89
|
|
|
77
|
-
Single-line list items
|
|
90
|
+
Single-line list items with basic indented nesting, single-paragraph quotes, and same-line code spans. No task lists, lazy list continuation, bare-URL autolinking, footnotes, or raw HTML passthrough yet.
|
|
78
91
|
|
|
79
92
|
## Development
|
|
80
93
|
|