nuxt-ai-ready 2.5.0 → 2.5.1
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/dist/chunks/agent-skills.mjs +1 -1
- package/dist/chunks/prerender.mjs +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/server/db/queries.js +5 -4
- package/dist/shared/{nuxt-ai-ready.DsokNmXc.mjs → nuxt-ai-ready.CLSWou20.mjs} +2 -0
- package/node_modules/@mdream/js/LICENSE.md +9 -0
- package/node_modules/@mdream/js/README.md +792 -0
- package/node_modules/@mdream/js/bin/mdream.mjs +2 -0
- package/node_modules/@mdream/js/dist/_chunks/const.mjs +134 -0
- package/node_modules/@mdream/js/dist/_chunks/index.d.mts +9 -0
- package/node_modules/@mdream/js/dist/_chunks/markdown-processor.mjs +1968 -0
- package/node_modules/@mdream/js/dist/_chunks/minimal.d.mts +6 -0
- package/node_modules/@mdream/js/dist/_chunks/parse.mjs +2756 -0
- package/node_modules/@mdream/js/dist/_chunks/plugins.mjs +725 -0
- package/node_modules/@mdream/js/dist/_chunks/resolve-plugins.mjs +44 -0
- package/node_modules/@mdream/js/dist/_chunks/stream.mjs +37 -0
- package/node_modules/@mdream/js/dist/_chunks/types.d.mts +473 -0
- package/node_modules/@mdream/js/dist/cli.d.mts +1 -0
- package/node_modules/@mdream/js/dist/cli.mjs +32 -0
- package/node_modules/@mdream/js/dist/core.d.mts +15 -0
- package/node_modules/@mdream/js/dist/core.mjs +28 -0
- package/node_modules/@mdream/js/dist/index.d.mts +4 -0
- package/node_modules/@mdream/js/dist/index.mjs +58 -0
- package/node_modules/@mdream/js/dist/llms-txt.d.mts +86 -0
- package/node_modules/@mdream/js/dist/llms-txt.mjs +308 -0
- package/node_modules/@mdream/js/dist/negotiate.d.mts +35 -0
- package/node_modules/@mdream/js/dist/negotiate.mjs +121 -0
- package/node_modules/@mdream/js/dist/parse.d.mts +90 -0
- package/node_modules/@mdream/js/dist/parse.mjs +2 -0
- package/node_modules/@mdream/js/dist/plugins.d.mts +85 -0
- package/node_modules/@mdream/js/dist/plugins.mjs +2 -0
- package/node_modules/@mdream/js/dist/preset/minimal.d.mts +2 -0
- package/node_modules/@mdream/js/dist/preset/minimal.mjs +33 -0
- package/node_modules/@mdream/js/dist/splitter.d.mts +18 -0
- package/node_modules/@mdream/js/dist/splitter.mjs +194 -0
- package/node_modules/@mdream/js/package.json +103 -0
- package/node_modules/cac/LICENSE +21 -0
- package/node_modules/cac/README.md +492 -0
- package/node_modules/cac/dist/index.d.ts +196 -0
- package/node_modules/cac/dist/index.js +638 -0
- package/node_modules/cac/package.json +72 -0
- package/node_modules/mdream/LICENSE.md +9 -0
- package/node_modules/mdream/README.md +1091 -0
- package/node_modules/mdream/bin/mdream.mjs +46 -0
- package/node_modules/mdream/dist/browser.d.mts +105 -0
- package/node_modules/mdream/dist/browser.mjs +262 -0
- package/node_modules/mdream/dist/edge.d.mts +100 -0
- package/node_modules/mdream/dist/edge.mjs +250 -0
- package/node_modules/mdream/dist/iife.js +605 -0
- package/node_modules/mdream/dist/index.d.mts +89 -0
- package/node_modules/mdream/dist/index.mjs +184 -0
- package/node_modules/mdream/dist/wasm.d.mts +100 -0
- package/node_modules/mdream/dist/wasm.mjs +140 -0
- package/node_modules/mdream/dist/worker.d.mts +101 -0
- package/node_modules/mdream/dist/worker.mjs +217 -0
- package/node_modules/mdream/napi/index.d.mts +127 -0
- package/node_modules/mdream/napi/index.d.ts +127 -0
- package/node_modules/mdream/napi/index.mjs +725 -0
- package/node_modules/mdream/napi/rust.android-arm-eabi.node +0 -0
- package/node_modules/mdream/napi/rust.android-arm64.node +0 -0
- package/node_modules/mdream/napi/rust.darwin-arm64.node +0 -0
- package/node_modules/mdream/napi/rust.darwin-x64.node +0 -0
- package/node_modules/mdream/napi/rust.freebsd-x64.node +0 -0
- package/node_modules/mdream/napi/rust.linux-arm-gnueabihf.node +0 -0
- package/node_modules/mdream/napi/rust.linux-arm64-gnu.node +0 -0
- package/node_modules/mdream/napi/rust.linux-arm64-musl.node +0 -0
- package/node_modules/mdream/napi/rust.linux-x64-gnu.node +0 -0
- package/node_modules/mdream/napi/rust.linux-x64-musl.node +0 -0
- package/node_modules/mdream/napi/rust.wasi.cjs +2144 -0
- package/node_modules/mdream/napi/rust.wasm32-wasi.wasm +0 -0
- package/node_modules/mdream/napi/rust.win32-arm64-msvc.node +0 -0
- package/node_modules/mdream/napi/rust.win32-x64-msvc.node +0 -0
- package/node_modules/mdream/node_modules/@emnapi/core/LICENSE +21 -0
- package/node_modules/mdream/node_modules/@emnapi/core/README.md +1 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.d.ts +392 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.d.ts +392 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.js +8351 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.js +7268 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.d.ts +5 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.js +843 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.d.ts +4 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.js +3 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.d.ts +5 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.js +1010 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.d.ts +5 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.js +1446 -0
- package/node_modules/mdream/node_modules/@emnapi/core/package.json +39 -0
- package/node_modules/mdream/node_modules/@emnapi/core/rollup.config.js +60 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/LICENSE +21 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/README.md +1 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.d.ts +833 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js +2306 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js.map +1 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/index.cjs +63 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/package.json +39 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/rollup.config.js +25 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/LICENSE +21 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/README.md +203 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +236 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +1086 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/package.json +35 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/rollup.config.js +6 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.cjs +1472 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.js +1470 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +237 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs.js +18260 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +317 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/package.json +67 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.cjs +39 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.js +36 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/LICENSE +21 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/README.md +193 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/tsdoc-metadata.json +11 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.d.ts +423 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +2932 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +2932 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +1 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.js +2954 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +1 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/asyncify.js +158 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/index.js +13 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/jspi.js +46 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/load.js +97 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/memory.js +35 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/error.js +103 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fd.js +268 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fs.js +3 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/index.js +192 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/path.js +316 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +1599 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/rights.js +141 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/types.js +220 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/util.js +128 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/webassembly.js +13 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/asyncify.mjs +153 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/index.mjs +9 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/jspi.mjs +39 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/load.mjs +89 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/memory.mjs +28 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/error.mjs +97 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fd.mjs +256 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fs.mjs +1 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/index.mjs +186 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/path.mjs +310 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +1593 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/rights.mjs +135 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/types.mjs +216 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/util.mjs +113 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/webassembly.mjs +9 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/package.json +58 -0
- package/node_modules/mdream/node_modules/tslib/CopyrightNotice.txt +15 -0
- package/node_modules/mdream/node_modules/tslib/LICENSE.txt +12 -0
- package/node_modules/mdream/node_modules/tslib/README.md +164 -0
- package/node_modules/mdream/node_modules/tslib/SECURITY.md +41 -0
- package/node_modules/mdream/node_modules/tslib/modules/index.d.ts +38 -0
- package/node_modules/mdream/node_modules/tslib/modules/index.js +70 -0
- package/node_modules/mdream/node_modules/tslib/modules/package.json +3 -0
- package/node_modules/mdream/node_modules/tslib/package.json +47 -0
- package/node_modules/mdream/node_modules/tslib/tslib.d.ts +460 -0
- package/node_modules/mdream/node_modules/tslib/tslib.es6.html +1 -0
- package/node_modules/mdream/node_modules/tslib/tslib.es6.js +402 -0
- package/node_modules/mdream/node_modules/tslib/tslib.es6.mjs +401 -0
- package/node_modules/mdream/node_modules/tslib/tslib.html +1 -0
- package/node_modules/mdream/node_modules/tslib/tslib.js +484 -0
- package/node_modules/mdream/package.json +110 -0
- package/node_modules/mdream/skills/mdream/SKILL.md +124 -0
- package/node_modules/mdream/skills/mdream/references/runtimes.md +49 -0
- package/node_modules/mdream/wasm/mdream_edge.d.ts +90 -0
- package/node_modules/mdream/wasm/mdream_edge.js +517 -0
- package/node_modules/mdream/wasm/mdream_edge_bg.wasm +0 -0
- package/node_modules/mdream/wasm/mdream_edge_bg.wasm.d.ts +20 -0
- package/node_modules/mdream/wasm/package.json +17 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge.d.ts +45 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge.js +13 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.js +413 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm +0 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm.d.ts +20 -0
- package/node_modules/mdream/wasm-bundler/package.json +19 -0
- package/node_modules/pathe/LICENSE +70 -0
- package/node_modules/pathe/README.md +73 -0
- package/node_modules/pathe/dist/index.cjs +39 -0
- package/node_modules/pathe/dist/index.d.cts +47 -0
- package/node_modules/pathe/dist/index.d.mts +47 -0
- package/node_modules/pathe/dist/index.d.ts +47 -0
- package/node_modules/pathe/dist/index.mjs +19 -0
- package/node_modules/pathe/dist/shared/pathe.BSlhyZSM.cjs +266 -0
- package/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +249 -0
- package/node_modules/pathe/dist/utils.cjs +82 -0
- package/node_modules/pathe/dist/utils.d.cts +32 -0
- package/node_modules/pathe/dist/utils.d.mts +32 -0
- package/node_modules/pathe/dist/utils.d.ts +32 -0
- package/node_modules/pathe/dist/utils.mjs +77 -0
- package/node_modules/pathe/package.json +61 -0
- package/node_modules/pathe/utils.d.ts +1 -0
- package/package.json +8 -64
|
@@ -0,0 +1,792 @@
|
|
|
1
|
+
# @mdream/js
|
|
2
|
+
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
+
[![License][license-src]][license-href]
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# pnpm
|
|
11
|
+
pnpm add @mdream/js@beta
|
|
12
|
+
|
|
13
|
+
# npm
|
|
14
|
+
npm install @mdream/js@beta
|
|
15
|
+
|
|
16
|
+
# yarn
|
|
17
|
+
yarn add @mdream/js@beta
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Entry Points
|
|
21
|
+
|
|
22
|
+
| Import | Description |
|
|
23
|
+
|---|---|
|
|
24
|
+
| `@mdream/js` | Full `htmlToMarkdown` and `streamHtmlToMarkdown` APIs, including declarative plugins and cleanup |
|
|
25
|
+
| `@mdream/js/core` | Tree-shakable pre-v1-style conversion APIs with composable plugin arrays and tag overrides |
|
|
26
|
+
| `@mdream/js/plugins` | Plugin utilities: `createPlugin`, `extractionPlugin`, `extractionCollectorPlugin`, `filterPlugin`, `frontmatterPlugin`, `isolateMainPlugin`, `tailwindPlugin` |
|
|
27
|
+
| `@mdream/js/preset/minimal` | `withMinimalPreset` for declarative config combining frontmatter, isolateMain, tailwind, and filter plugins |
|
|
28
|
+
| `@mdream/js/negotiate` | HTTP content negotiation: `shouldServeMarkdown`, `parseAcceptHeader` |
|
|
29
|
+
| `@mdream/js/parse` | Low-level HTML parser: `parseHtml`, `parseHtmlStream` |
|
|
30
|
+
| `@mdream/js/splitter` | Single-pass markdown splitter: `htmlToMarkdownSplitChunks`, `htmlToMarkdownSplitChunksStream` |
|
|
31
|
+
| `@mdream/js/llms-txt` | llms.txt artifact generation: `generateLlmsTxtArtifacts`, `createLlmsTxtStream` |
|
|
32
|
+
|
|
33
|
+
## API Reference
|
|
34
|
+
|
|
35
|
+
The package root remains the full conversion API. Import `@mdream/js/core` when
|
|
36
|
+
you want the smaller tree-shakable implementation and explicitly composed
|
|
37
|
+
plugins.
|
|
38
|
+
|
|
39
|
+
### `htmlToMarkdown(html, options?)`
|
|
40
|
+
|
|
41
|
+
Converts an HTML string synchronously.
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { htmlToMarkdown } from '@mdream/js'
|
|
45
|
+
|
|
46
|
+
const md = htmlToMarkdown('<h1>Hello</h1><p>World</p>')
|
|
47
|
+
// # Hello\n\nWorld
|
|
48
|
+
|
|
49
|
+
const text = htmlToMarkdown('<h1>Hello</h1><p><strong>World</strong></p>', {
|
|
50
|
+
format: 'text',
|
|
51
|
+
})
|
|
52
|
+
// Hello\n\nWorld
|
|
53
|
+
|
|
54
|
+
const html = htmlToMarkdown('<h1>Hello</h1><p><strong>World</strong></p>', {
|
|
55
|
+
format: 'html',
|
|
56
|
+
})
|
|
57
|
+
// <h1 id="hello">Hello</h1><p><strong>World</strong></p>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Parameters:**
|
|
61
|
+
|
|
62
|
+
| Parameter | Type | Description |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| `html` | `string` | The HTML string to convert |
|
|
65
|
+
| `options` | `Partial<MdreamOptions>` | Optional configuration (see [MdreamOptions](#mdreamoptions)) |
|
|
66
|
+
|
|
67
|
+
**Returns:** `string`
|
|
68
|
+
|
|
69
|
+
### `streamHtmlToMarkdown(htmlStream, options?)`
|
|
70
|
+
|
|
71
|
+
Converts an HTML stream incrementally. Useful for large documents or streaming HTTP responses.
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { streamHtmlToMarkdown } from '@mdream/js'
|
|
75
|
+
|
|
76
|
+
const stream = streamHtmlToMarkdown(response.body, {
|
|
77
|
+
origin: 'https://example.com',
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
for await (const chunk of stream) {
|
|
81
|
+
process.stdout.write(chunk)
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Parameters:**
|
|
86
|
+
|
|
87
|
+
| Parameter | Type | Description |
|
|
88
|
+
|---|---|---|
|
|
89
|
+
| `htmlStream` | `ReadableStream<Uint8Array \| string> \| null` | A web `ReadableStream` of HTML content |
|
|
90
|
+
| `options` | `Partial<MdreamOptions>` | Optional configuration (see [MdreamOptions](#mdreamoptions)) |
|
|
91
|
+
|
|
92
|
+
**Returns:** `AsyncIterable<string>`
|
|
93
|
+
|
|
94
|
+
### Tree-shakable core
|
|
95
|
+
|
|
96
|
+
The `/core` subpath restores the original composable JS interface without
|
|
97
|
+
loading declarative built-in plugins or cleanup:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { htmlToMarkdown } from '@mdream/js/core'
|
|
101
|
+
import { filterPlugin } from '@mdream/js/plugins'
|
|
102
|
+
|
|
103
|
+
const markdown = htmlToMarkdown(html, {
|
|
104
|
+
plugins: [filterPlugin({ exclude: ['nav', 'footer'] })],
|
|
105
|
+
})
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Options
|
|
111
|
+
|
|
112
|
+
### `MdreamOptions`
|
|
113
|
+
|
|
114
|
+
| Option | Type | Default | Description |
|
|
115
|
+
|---|---|---|---|
|
|
116
|
+
| `origin` | `string` | `undefined` | Origin URL for resolving relative image paths and internal links |
|
|
117
|
+
| `plugins` | `BuiltinPlugins` | `undefined` | Declarative built-in plugin configuration (see [BuiltinPlugins](#builtinplugins)) |
|
|
118
|
+
| `clean` | `boolean \| CleanOptions` | `undefined` | Post-processing cleanup. Pass `true` for all cleanup rules or an object for specific features (see [CleanOptions](#cleanoptions)). Sync API only for `fragments`. |
|
|
119
|
+
| `hooks` | `TransformPlugin[]` | `undefined` | Imperative hook-based transform plugins for custom behavior (see [Plugins](#plugins)) |
|
|
120
|
+
| `wrapWidth` | `number` | `undefined` | Hard-wrap prose at this many characters on word boundaries |
|
|
121
|
+
| `format` | `'markdown' \| 'text' \| 'html'` | `'markdown'` | Output Markdown, plain text, or HTML |
|
|
122
|
+
|
|
123
|
+
### `BuiltinPlugins`
|
|
124
|
+
|
|
125
|
+
Declarative configuration for built-in plugins. Works with both the JavaScript and Rust engines.
|
|
126
|
+
|
|
127
|
+
| Option | Type | Default | Description |
|
|
128
|
+
|---|---|---|---|
|
|
129
|
+
| `frontmatter` | `boolean \| ((fm: Record<string, string>) => void) \| FrontmatterConfig` | `undefined` | Extract metadata from HTML `<head>` into YAML frontmatter. Pass `true` for defaults, a callback to receive structured data, or a config object. |
|
|
130
|
+
| `isolateMain` | `boolean` | `undefined` | Isolate main content area. Prioritizes `<main>` elements, then falls back to header-to-footer heuristic. |
|
|
131
|
+
| `tailwind` | `boolean` | `undefined` | Convert Tailwind utility classes (bold, italic, hidden, etc.) to semantic Markdown formatting. |
|
|
132
|
+
| `filter` | `{ include?, exclude?, processChildren? }` | `undefined` | Filter elements by CSS selectors, tag names, or TAG_* constants (see [Filter Plugin](#filterpluginoptions)). |
|
|
133
|
+
| `extraction` | `Record<string, (element: ExtractedElement) => void>` | `undefined` | Extract elements matching CSS selectors during conversion. Each key is a CSS selector; the handler is called for every match. |
|
|
134
|
+
| `tagOverrides` | `Record<string, TagOverride \| string>` | `undefined` | Declarative tag overrides. String values act as aliases (e.g., `{ "x-heading": "h2" }`). Object values override specific handler properties. |
|
|
135
|
+
|
|
136
|
+
### `FrontmatterConfig`
|
|
137
|
+
|
|
138
|
+
| Option | Type | Default | Description |
|
|
139
|
+
|---|---|---|---|
|
|
140
|
+
| `additionalFields` | `Record<string, string>` | `undefined` | Extra key-value pairs to inject into the frontmatter |
|
|
141
|
+
| `metaFields` | `string[]` | `['description', 'keywords', 'author', 'date', 'og:title', 'og:description', 'twitter:title', 'twitter:description']` | Meta tag names to extract beyond the standard set |
|
|
142
|
+
| `onExtract` | `(frontmatter: Record<string, string>) => void` | `undefined` | Callback to receive structured frontmatter data after conversion |
|
|
143
|
+
|
|
144
|
+
### `TagOverride`
|
|
145
|
+
|
|
146
|
+
| Option | Type | Description |
|
|
147
|
+
|---|---|---|
|
|
148
|
+
| `enter` | `string` | Markdown string to emit when entering the tag |
|
|
149
|
+
| `exit` | `string` | Markdown string to emit when exiting the tag |
|
|
150
|
+
| `spacing` | `[number, number]` | Newlines to add `[before, after]` the tag |
|
|
151
|
+
| `isInline` | `boolean` | Whether the tag is inline (no block-level spacing) |
|
|
152
|
+
| `isSelfClosing` | `boolean` | Whether the tag is self-closing |
|
|
153
|
+
| `collapsesInnerWhiteSpace` | `boolean` | Whether inner whitespace should be collapsed |
|
|
154
|
+
|
|
155
|
+
### `CleanOptions`
|
|
156
|
+
|
|
157
|
+
Post-processing cleanup options. Pass `true` to `clean` to enable all of these.
|
|
158
|
+
|
|
159
|
+
| Option | Type | Default | Description |
|
|
160
|
+
|---|---|---|---|
|
|
161
|
+
| `urls` | `boolean` | `false` | Strip tracking query parameters (`utm_*`, `fbclid`, `gclid`, etc.) from URLs |
|
|
162
|
+
| `fragments` | `boolean` | `false` | Strip fragment-only links that do not match any heading slug in the output |
|
|
163
|
+
| `emptyLinks` | `boolean` | `false` | Strip links with meaningless hrefs (`#`, `javascript:void(0)`, `data:`, `vbscript:`) and replace with plain text |
|
|
164
|
+
| `blankLines` | `boolean` | `false` | Collapse 3+ consecutive blank lines to 2 |
|
|
165
|
+
| `redundantLinks` | `boolean` | `false` | Strip links where text equals URL: `[https://x.com](https://x.com)` becomes `https://x.com` |
|
|
166
|
+
| `selfLinkHeadings` | `boolean` | `false` | Strip self-referencing heading anchors: `## [Title](#title)` becomes `## Title` |
|
|
167
|
+
| `emptyImages` | `boolean` | `false` | Strip images with no alt text (decorative images, tracking pixels) |
|
|
168
|
+
| `emptyLinkText` | `boolean` | `false` | Drop links that produce no visible text: `[](url)` is removed entirely |
|
|
169
|
+
|
|
170
|
+
When `clean: true` is passed, all options except `urls` and `blankLines` are enabled.
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Plugins
|
|
175
|
+
|
|
176
|
+
### `createPlugin(plugin)`
|
|
177
|
+
|
|
178
|
+
Factory function for creating type-safe transform plugins. All hooks are optional.
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { createPlugin } from '@mdream/js/plugins'
|
|
182
|
+
|
|
183
|
+
const myPlugin = createPlugin({
|
|
184
|
+
beforeNodeProcess(event, state) {
|
|
185
|
+
// Return { skip: true } to skip this node entirely
|
|
186
|
+
},
|
|
187
|
+
onNodeEnter(element, state) {
|
|
188
|
+
// Return a string to inject markdown at this position
|
|
189
|
+
},
|
|
190
|
+
onNodeExit(element, state) {
|
|
191
|
+
// Return a string to inject markdown at this position
|
|
192
|
+
},
|
|
193
|
+
processAttributes(element, state) {
|
|
194
|
+
// Inspect or modify element attributes
|
|
195
|
+
},
|
|
196
|
+
processTextNode(textNode, state) {
|
|
197
|
+
// Return { content: string, skip: boolean } to transform text
|
|
198
|
+
// Return undefined for no transformation
|
|
199
|
+
},
|
|
200
|
+
})
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
#### Plugin Hook Reference
|
|
204
|
+
|
|
205
|
+
| Hook | Parameters | Return Type | Description |
|
|
206
|
+
|---|---|---|---|
|
|
207
|
+
| `beforeNodeProcess` | `(event: NodeEvent, state)` | `{ skip: boolean } \| void` | Called before any node processing. Return `{ skip: true }` to skip the node. |
|
|
208
|
+
| `onNodeEnter` | `(element: ElementNode, state)` | `string \| void` | Called when entering an element. Return a string to inject markdown. |
|
|
209
|
+
| `onNodeExit` | `(element: ElementNode, state)` | `string \| void` | Called when exiting an element. Return a string to inject markdown. |
|
|
210
|
+
| `processAttributes` | `(element: ElementNode, state)` | `void` | Called to inspect or modify element attributes. |
|
|
211
|
+
| `processTextNode` | `(textNode: TextNode, state)` | `{ content: string, skip: boolean } \| void` | Called for each text node. Return an object to transform text or skip it. |
|
|
212
|
+
|
|
213
|
+
### `filterPlugin(options)`
|
|
214
|
+
|
|
215
|
+
Filters elements by CSS selectors, tag names, or TAG_* constants.
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
import { TAG_FOOTER, TAG_NAV } from '@mdream/js'
|
|
219
|
+
import { filterPlugin } from '@mdream/js/plugins'
|
|
220
|
+
|
|
221
|
+
// Exclude navigation and footer
|
|
222
|
+
const plugin = filterPlugin({
|
|
223
|
+
exclude: [TAG_NAV, TAG_FOOTER, '.sidebar', '#ads'],
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
// Include only specific elements
|
|
227
|
+
const plugin2 = filterPlugin({
|
|
228
|
+
include: ['article', 'main'],
|
|
229
|
+
processChildren: true, // default: true
|
|
230
|
+
})
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
| Option | Type | Default | Description |
|
|
234
|
+
|---|---|---|---|
|
|
235
|
+
| `include` | `(string \| number)[]` | `[]` | CSS selectors, tag names, or TAG_* constants for elements to include (all others excluded) |
|
|
236
|
+
| `exclude` | `(string \| number)[]` | `[]` | CSS selectors, tag names, or TAG_* constants for elements to exclude |
|
|
237
|
+
| `processChildren` | `boolean` | `true` | Whether to also process children of matching elements |
|
|
238
|
+
|
|
239
|
+
### `frontmatterPlugin(options?)`
|
|
240
|
+
|
|
241
|
+
Extracts metadata from HTML `<head>` into YAML frontmatter. Collects `<title>` and `<meta>` tags.
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
import { frontmatterPlugin } from '@mdream/js/plugins'
|
|
245
|
+
|
|
246
|
+
const plugin = frontmatterPlugin({
|
|
247
|
+
additionalFields: { source: 'crawler' },
|
|
248
|
+
metaFields: ['robots', 'viewport'],
|
|
249
|
+
})
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Default meta fields extracted: `description`, `keywords`, `author`, `date`, `og:title`, `og:description`, `twitter:title`, `twitter:description`.
|
|
253
|
+
|
|
254
|
+
### `isolateMainPlugin()`
|
|
255
|
+
|
|
256
|
+
Isolates the main content area of a page using a priority-based strategy:
|
|
257
|
+
|
|
258
|
+
1. If an explicit `<main>` element exists (within 5 depth levels), use its content exclusively.
|
|
259
|
+
2. Otherwise, find content between the first heading (`h1`-`h6`) that is not inside a `<header>` tag and the first `<footer>`.
|
|
260
|
+
3. The `<head>` section is always passed through for other plugins (e.g., frontmatter extraction).
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
import { isolateMainPlugin } from '@mdream/js/plugins'
|
|
264
|
+
|
|
265
|
+
const plugin = isolateMainPlugin()
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### `tailwindPlugin()`
|
|
269
|
+
|
|
270
|
+
Converts Tailwind utility classes to Markdown formatting. Supports mobile-first responsive breakpoints (`sm:`, `md:`, `lg:`, `xl:`, `2xl:`).
|
|
271
|
+
|
|
272
|
+
| Tailwind Class | Markdown Output |
|
|
273
|
+
|---|---|
|
|
274
|
+
| `font-bold`, `font-semibold`, `font-black`, `font-extrabold`, `font-medium` | `**text**` |
|
|
275
|
+
| `italic`, `font-italic` | `*text*` |
|
|
276
|
+
| `line-through` | `~~text~~` |
|
|
277
|
+
| `hidden`, `invisible` | Element skipped |
|
|
278
|
+
| `absolute`, `fixed`, `sticky` | Element skipped |
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
import { tailwindPlugin } from '@mdream/js/plugins'
|
|
282
|
+
|
|
283
|
+
const plugin = tailwindPlugin()
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### `extractionPlugin(selectors)`
|
|
287
|
+
|
|
288
|
+
Use this explicitly imported plugin with the tree-shakable core converter. Use
|
|
289
|
+
the `plugins.extraction` declarative config instead when sharing options with
|
|
290
|
+
the Rust engine.
|
|
291
|
+
|
|
292
|
+
Extracts elements matching CSS selectors during conversion. Callbacks receive matching elements with their accumulated text content.
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
import { extractionPlugin } from '@mdream/js/plugins'
|
|
296
|
+
|
|
297
|
+
const plugin = extractionPlugin({
|
|
298
|
+
'h2': (element, state) => {
|
|
299
|
+
console.log('Heading:', element.textContent)
|
|
300
|
+
},
|
|
301
|
+
'img[alt]': (element, state) => {
|
|
302
|
+
console.log('Image:', element.attributes.src)
|
|
303
|
+
},
|
|
304
|
+
})
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### `extractionCollectorPlugin(selectors)`
|
|
308
|
+
|
|
309
|
+
Internal extraction collector for the `plugins.extraction` config. Collects results during processing and calls callbacks post-conversion to match Rust engine behavior.
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
## Presets
|
|
314
|
+
|
|
315
|
+
### `withMinimalPreset(options?)`
|
|
316
|
+
|
|
317
|
+
Returns a declarative config combining frontmatter, isolateMain, tailwind, and filter plugins. Also enables `clean: true` by default. You can override any option.
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
import { htmlToMarkdown } from '@mdream/js'
|
|
321
|
+
import { withMinimalPreset } from '@mdream/js/preset/minimal'
|
|
322
|
+
|
|
323
|
+
const md = htmlToMarkdown(html, withMinimalPreset({
|
|
324
|
+
origin: 'https://example.com',
|
|
325
|
+
}))
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
The minimal preset excludes these elements by default: `<form>`, `<fieldset>`, `<object>`, `<embed>`, `<footer>`, `<aside>`, `<iframe>`, `<input>`, `<textarea>`, `<select>`, `<button>`, `<nav>`.
|
|
329
|
+
|
|
330
|
+
You can override or extend the plugin config:
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
const md = htmlToMarkdown(html, withMinimalPreset({
|
|
334
|
+
origin: 'https://example.com',
|
|
335
|
+
clean: { urls: true, fragments: true },
|
|
336
|
+
plugins: {
|
|
337
|
+
frontmatter: {
|
|
338
|
+
additionalFields: { source: 'my-crawler' },
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
}))
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
## Content Negotiation
|
|
347
|
+
|
|
348
|
+
### `shouldServeMarkdown(acceptHeader?, secFetchDest?)`
|
|
349
|
+
|
|
350
|
+
Determines if a client prefers Markdown over HTML using HTTP content negotiation.
|
|
351
|
+
|
|
352
|
+
- Returns `true` when `text/markdown` or `text/plain` has higher quality than `text/html` in the Accept header.
|
|
353
|
+
- If qualities are equal, earlier position wins.
|
|
354
|
+
- Bare wildcards (`*/*`) do not trigger Markdown (prevents breaking OG crawlers).
|
|
355
|
+
- `sec-fetch-dest: document` always returns `false` (browser navigation).
|
|
356
|
+
|
|
357
|
+
```typescript
|
|
358
|
+
import { shouldServeMarkdown } from '@mdream/js/negotiate'
|
|
359
|
+
|
|
360
|
+
if (shouldServeMarkdown(request.headers.accept, request.headers['sec-fetch-dest'])) {
|
|
361
|
+
return new Response(markdown, {
|
|
362
|
+
headers: { 'content-type': 'text/markdown' },
|
|
363
|
+
})
|
|
364
|
+
}
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
**Parameters:**
|
|
368
|
+
|
|
369
|
+
| Parameter | Type | Description |
|
|
370
|
+
|---|---|---|
|
|
371
|
+
| `acceptHeader` | `string \| undefined` | The HTTP `Accept` header value |
|
|
372
|
+
| `secFetchDest` | `string \| undefined` | The `Sec-Fetch-Dest` header value |
|
|
373
|
+
|
|
374
|
+
**Returns:** `boolean`
|
|
375
|
+
|
|
376
|
+
### `parseAcceptHeader(accept)`
|
|
377
|
+
|
|
378
|
+
Parses an HTTP Accept header into an ordered list of media types with quality values.
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
import { parseAcceptHeader } from '@mdream/js/negotiate'
|
|
382
|
+
|
|
383
|
+
const entries = parseAcceptHeader('text/markdown;q=0.9, text/html')
|
|
384
|
+
// [{ type: 'text/markdown', q: 0.9, position: 0 }, { type: 'text/html', q: 1, position: 1 }]
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
**Returns:** `Array<{ type: string, q: number, position: number }>`
|
|
388
|
+
|
|
389
|
+
---
|
|
390
|
+
|
|
391
|
+
## Markdown Splitter
|
|
392
|
+
|
|
393
|
+
### `htmlToMarkdownSplitChunks(html, options?)`
|
|
394
|
+
|
|
395
|
+
Converts HTML to Markdown and returns an array of chunks. Compatible with LangChain's `Document` structure.
|
|
396
|
+
|
|
397
|
+
```typescript
|
|
398
|
+
import { htmlToMarkdownSplitChunks } from '@mdream/js/splitter'
|
|
399
|
+
|
|
400
|
+
const chunks = htmlToMarkdownSplitChunks(html, {
|
|
401
|
+
chunkSize: 1000,
|
|
402
|
+
chunkOverlap: 200,
|
|
403
|
+
origin: 'https://example.com',
|
|
404
|
+
})
|
|
405
|
+
|
|
406
|
+
for (const chunk of chunks) {
|
|
407
|
+
console.log(chunk.content)
|
|
408
|
+
console.log(chunk.metadata.headers) // e.g., { h2: 'Section Title' }
|
|
409
|
+
console.log(chunk.metadata.code) // e.g., 'typescript'
|
|
410
|
+
console.log(chunk.metadata.loc) // e.g., { lines: { from: 1, to: 10 } }
|
|
411
|
+
}
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
**Returns:** `MarkdownChunk[]`
|
|
415
|
+
|
|
416
|
+
### `htmlToMarkdownSplitChunksStream(html, options?)`
|
|
417
|
+
|
|
418
|
+
Generator version that yields chunks during processing for better memory efficiency.
|
|
419
|
+
|
|
420
|
+
```typescript
|
|
421
|
+
import { htmlToMarkdownSplitChunksStream } from '@mdream/js/splitter'
|
|
422
|
+
|
|
423
|
+
for (const chunk of htmlToMarkdownSplitChunksStream(html, options)) {
|
|
424
|
+
process.stdout.write(chunk.content)
|
|
425
|
+
}
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
**Returns:** `Generator<MarkdownChunk, void, undefined>`
|
|
429
|
+
|
|
430
|
+
### `SplitterOptions`
|
|
431
|
+
|
|
432
|
+
Extends `EngineOptions` with chunking-specific settings.
|
|
433
|
+
|
|
434
|
+
| Option | Type | Default | Description |
|
|
435
|
+
|---|---|---|---|
|
|
436
|
+
| `headersToSplitOn` | `number[]` | `[TAG_H2, TAG_H3, TAG_H4, TAG_H5, TAG_H6]` | TAG_* header constants to split on |
|
|
437
|
+
| `returnEachLine` | `boolean` | `false` | Return each non-empty line as an individual chunk |
|
|
438
|
+
| `stripHeaders` | `boolean` | `true` | Strip header lines from chunk content |
|
|
439
|
+
| `chunkSize` | `number` | `1000` | Maximum chunk size (measured by `lengthFunction`) |
|
|
440
|
+
| `chunkOverlap` | `number` | `200` | Overlap between chunks for context preservation. Must be less than `chunkSize`. |
|
|
441
|
+
| `lengthFunction` | `(text: string) => number` | `(text) => text.length` | Function to measure chunk length. Replace with a token counter for LLM applications. |
|
|
442
|
+
| `keepSeparator` | `boolean` | `false` | Keep separators in the split chunks |
|
|
443
|
+
|
|
444
|
+
### `MarkdownChunk`
|
|
445
|
+
|
|
446
|
+
| Field | Type | Description |
|
|
447
|
+
|---|---|---|
|
|
448
|
+
| `content` | `string` | The markdown content of the chunk |
|
|
449
|
+
| `metadata.headers` | `Record<string, string> \| undefined` | Header hierarchy at this chunk position (e.g., `{ h2: 'API', h3: 'Methods' }`) |
|
|
450
|
+
| `metadata.code` | `string \| undefined` | Code block language if chunk contains code |
|
|
451
|
+
| `metadata.loc` | `{ lines: { from: number, to: number } } \| undefined` | Line number range in original document |
|
|
452
|
+
|
|
453
|
+
---
|
|
454
|
+
|
|
455
|
+
## llms.txt Generation
|
|
456
|
+
|
|
457
|
+
### `generateLlmsTxtArtifacts(options)`
|
|
458
|
+
|
|
459
|
+
Generates llms.txt content, optionally including llms-full.txt and individual markdown files.
|
|
460
|
+
|
|
461
|
+
```typescript
|
|
462
|
+
import { generateLlmsTxtArtifacts } from '@mdream/js/llms-txt'
|
|
463
|
+
|
|
464
|
+
const result = await generateLlmsTxtArtifacts({
|
|
465
|
+
files: processedPages,
|
|
466
|
+
siteName: 'My Site',
|
|
467
|
+
description: 'A description of my site',
|
|
468
|
+
origin: 'https://example.com',
|
|
469
|
+
generateFull: true,
|
|
470
|
+
generateMarkdown: true,
|
|
471
|
+
sections: [
|
|
472
|
+
{
|
|
473
|
+
title: 'Documentation',
|
|
474
|
+
description: 'API reference and guides',
|
|
475
|
+
links: [
|
|
476
|
+
{ title: 'Getting Started', href: '/docs/start', description: 'Quick start guide' },
|
|
477
|
+
],
|
|
478
|
+
},
|
|
479
|
+
],
|
|
480
|
+
notes: 'Generated by mdream',
|
|
481
|
+
})
|
|
482
|
+
|
|
483
|
+
// result.llmsTxt -- index file with links to pages
|
|
484
|
+
// result.llmsFullTxt -- single file with all page content (if generateFull: true)
|
|
485
|
+
// result.markdownFiles -- array of { path, content } (if generateMarkdown: true)
|
|
486
|
+
// result.processedFiles -- the input files passed through
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
#### `LlmsTxtArtifactsOptions`
|
|
490
|
+
|
|
491
|
+
| Option | Type | Default | Description |
|
|
492
|
+
|---|---|---|---|
|
|
493
|
+
| `files` | `ProcessedFile[]` | (required) | Array of processed page files |
|
|
494
|
+
| `siteName` | `string` | `'Site'` | Site name for the header |
|
|
495
|
+
| `description` | `string` | `undefined` | Site description (rendered as blockquote) |
|
|
496
|
+
| `origin` | `string` | `''` | Origin URL to prepend to relative URLs |
|
|
497
|
+
| `generateFull` | `boolean` | `false` | Generate llms-full.txt with complete page content |
|
|
498
|
+
| `generateMarkdown` | `boolean` | `false` | Generate individual markdown files under `md/` directory |
|
|
499
|
+
| `outputDir` | `string` | `undefined` | Output directory (used to compute relative file paths) |
|
|
500
|
+
| `sections` | `LlmsTxtSection[]` | `undefined` | Custom sections to write before the Pages section |
|
|
501
|
+
| `notes` | `string \| string[]` | `undefined` | Notes to append at the end |
|
|
502
|
+
|
|
503
|
+
#### `ProcessedFile`
|
|
504
|
+
|
|
505
|
+
| Field | Type | Description |
|
|
506
|
+
|---|---|---|
|
|
507
|
+
| `title` | `string` | Page title |
|
|
508
|
+
| `content` | `string` | Markdown content of the page |
|
|
509
|
+
| `url` | `string` | URL path of the page |
|
|
510
|
+
| `filePath` | `string \| undefined` | Optional file path on disk |
|
|
511
|
+
| `metadata` | `{ title?, description?, keywords?, author? }` | Optional metadata extracted from the page |
|
|
512
|
+
|
|
513
|
+
#### `LlmsTxtSection`
|
|
514
|
+
|
|
515
|
+
| Field | Type | Description |
|
|
516
|
+
|---|---|---|
|
|
517
|
+
| `title` | `string` | Section heading |
|
|
518
|
+
| `description` | `string \| string[]` | Section description (can be multiple paragraphs) |
|
|
519
|
+
| `links` | `LlmsTxtLink[]` | Links in the section |
|
|
520
|
+
|
|
521
|
+
#### `LlmsTxtLink`
|
|
522
|
+
|
|
523
|
+
| Field | Type | Description |
|
|
524
|
+
|---|---|---|
|
|
525
|
+
| `title` | `string` | Link title |
|
|
526
|
+
| `href` | `string` | Link URL |
|
|
527
|
+
| `description` | `string \| undefined` | Optional description shown after the link |
|
|
528
|
+
|
|
529
|
+
### `createLlmsTxtStream(options)`
|
|
530
|
+
|
|
531
|
+
Creates a `WritableStream<ProcessedFile>` that generates llms.txt artifacts incrementally. Writes files to disk as pages are streamed in, never keeping full content in memory. Pages in llms.txt are sorted by URL path hierarchy on close.
|
|
532
|
+
|
|
533
|
+
```typescript
|
|
534
|
+
import { createLlmsTxtStream } from '@mdream/js/llms-txt'
|
|
535
|
+
|
|
536
|
+
const stream = createLlmsTxtStream({
|
|
537
|
+
outputDir: './output',
|
|
538
|
+
siteName: 'My Site',
|
|
539
|
+
origin: 'https://example.com',
|
|
540
|
+
generateFull: true,
|
|
541
|
+
})
|
|
542
|
+
|
|
543
|
+
const writer = stream.getWriter()
|
|
544
|
+
await writer.write({ title: 'Home', content: '# Home\nWelcome', url: '/' })
|
|
545
|
+
await writer.write({ title: 'About', content: '# About\nInfo', url: '/about' })
|
|
546
|
+
await writer.close()
|
|
547
|
+
// Writes llms.txt and llms-full.txt to ./output/
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
**Returns:** `WritableStream<ProcessedFile>`
|
|
551
|
+
|
|
552
|
+
---
|
|
553
|
+
|
|
554
|
+
## Low-Level Parser
|
|
555
|
+
|
|
556
|
+
### `parseHtml(html, options?)`
|
|
557
|
+
|
|
558
|
+
Parses HTML into a list of DOM events. Returns the events and any remaining unparsed HTML.
|
|
559
|
+
|
|
560
|
+
```typescript
|
|
561
|
+
import { parseHtml } from '@mdream/js/parse'
|
|
562
|
+
|
|
563
|
+
const { events, remainingHtml } = parseHtml('<p>Hello</p>')
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
**Returns:** `{ events: NodeEvent[], remainingHtml: string }`
|
|
567
|
+
|
|
568
|
+
### `parseHtmlStream(html, state, onEvent)`
|
|
569
|
+
|
|
570
|
+
Streaming parser that calls `onEvent` for each DOM event. Returns any remaining unparsed HTML (useful for processing partial chunks).
|
|
571
|
+
|
|
572
|
+
```typescript
|
|
573
|
+
import { parseHtmlStream } from '@mdream/js/parse'
|
|
574
|
+
|
|
575
|
+
const state = { depthMap: new Uint8Array(1024), depth: 0 }
|
|
576
|
+
const remaining = parseHtmlStream(htmlChunk, state, (event) => {
|
|
577
|
+
// Process each event
|
|
578
|
+
})
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
**Returns:** `string` (remaining unparsed HTML)
|
|
582
|
+
|
|
583
|
+
---
|
|
584
|
+
|
|
585
|
+
## CLI
|
|
586
|
+
|
|
587
|
+
Reads HTML from stdin and writes the selected format to stdout.
|
|
588
|
+
|
|
589
|
+
```bash
|
|
590
|
+
# Basic conversion
|
|
591
|
+
curl -s https://example.com | npx @mdream/js
|
|
592
|
+
|
|
593
|
+
# With origin URL for resolving relative paths
|
|
594
|
+
curl -s https://example.com | npx @mdream/js --origin https://example.com
|
|
595
|
+
|
|
596
|
+
# With minimal preset
|
|
597
|
+
curl -s https://example.com | npx @mdream/js --origin https://example.com --preset minimal
|
|
598
|
+
|
|
599
|
+
# Plain text output
|
|
600
|
+
curl -s https://example.com | npx @mdream/js --format text
|
|
601
|
+
|
|
602
|
+
# HTML output
|
|
603
|
+
curl -s https://example.com | npx @mdream/js --format html
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
### CLI Options
|
|
607
|
+
|
|
608
|
+
| Flag | Description |
|
|
609
|
+
|---|---|
|
|
610
|
+
| `--origin <url>` | Origin URL for resolving relative image paths and links |
|
|
611
|
+
| `--preset <preset>` | Conversion preset. Currently supports: `minimal` |
|
|
612
|
+
| `--wrap-width <n>` | Hard-wrap prose at `n` characters |
|
|
613
|
+
| `--format <format>` | Output format: `markdown`, `text`, `html` |
|
|
614
|
+
| `--text` | Alias for `--format text` |
|
|
615
|
+
| `-v, --version` | Show version number |
|
|
616
|
+
| `-h, --help` | Show help |
|
|
617
|
+
|
|
618
|
+
---
|
|
619
|
+
|
|
620
|
+
## Usage Examples
|
|
621
|
+
|
|
622
|
+
### Custom Tag Overrides
|
|
623
|
+
|
|
624
|
+
Map custom HTML elements to standard Markdown behavior:
|
|
625
|
+
|
|
626
|
+
```typescript
|
|
627
|
+
import { htmlToMarkdown } from '@mdream/js/core'
|
|
628
|
+
|
|
629
|
+
const md = htmlToMarkdown('<x-heading>Title</x-heading>', {
|
|
630
|
+
plugins: {
|
|
631
|
+
tagOverrides: {
|
|
632
|
+
// String alias: make <x-heading> behave like <h2>
|
|
633
|
+
'x-heading': 'h2',
|
|
634
|
+
|
|
635
|
+
// Object override: custom enter/exit strings
|
|
636
|
+
'callout': {
|
|
637
|
+
enter: '> **Note:** ',
|
|
638
|
+
exit: '\n',
|
|
639
|
+
spacing: [2, 2],
|
|
640
|
+
},
|
|
641
|
+
},
|
|
642
|
+
},
|
|
643
|
+
})
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
### Declarative Extraction
|
|
647
|
+
|
|
648
|
+
Extract data from elements during conversion:
|
|
649
|
+
|
|
650
|
+
```typescript
|
|
651
|
+
import { htmlToMarkdown } from '@mdream/js'
|
|
652
|
+
|
|
653
|
+
const images: { src: string, alt: string }[] = []
|
|
654
|
+
|
|
655
|
+
const md = htmlToMarkdown(html, {
|
|
656
|
+
plugins: {
|
|
657
|
+
extraction: {
|
|
658
|
+
'img[alt]': (element) => {
|
|
659
|
+
images.push({
|
|
660
|
+
src: element.attributes.src,
|
|
661
|
+
alt: element.attributes.alt,
|
|
662
|
+
})
|
|
663
|
+
},
|
|
664
|
+
},
|
|
665
|
+
},
|
|
666
|
+
})
|
|
667
|
+
|
|
668
|
+
console.log('Found images:', images)
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
### Frontmatter with Callback
|
|
672
|
+
|
|
673
|
+
Receive structured frontmatter data for further processing:
|
|
674
|
+
|
|
675
|
+
```typescript
|
|
676
|
+
import { htmlToMarkdown } from '@mdream/js'
|
|
677
|
+
|
|
678
|
+
let metadata: Record<string, string> = {}
|
|
679
|
+
|
|
680
|
+
const md = htmlToMarkdown(html, {
|
|
681
|
+
plugins: {
|
|
682
|
+
frontmatter: {
|
|
683
|
+
additionalFields: { source: 'crawler' },
|
|
684
|
+
metaFields: ['robots'],
|
|
685
|
+
onExtract: (fm) => {
|
|
686
|
+
metadata = fm
|
|
687
|
+
},
|
|
688
|
+
},
|
|
689
|
+
},
|
|
690
|
+
})
|
|
691
|
+
|
|
692
|
+
console.log('Title:', metadata.title)
|
|
693
|
+
console.log('Description:', metadata.description)
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
### Composable Plugin for Content Filtering
|
|
697
|
+
|
|
698
|
+
```typescript
|
|
699
|
+
import { htmlToMarkdown } from '@mdream/js/core'
|
|
700
|
+
import { createPlugin } from '@mdream/js/plugins'
|
|
701
|
+
|
|
702
|
+
const md = htmlToMarkdown(html, {
|
|
703
|
+
plugins: [
|
|
704
|
+
createPlugin({
|
|
705
|
+
beforeNodeProcess(event) {
|
|
706
|
+
const { node } = event
|
|
707
|
+
if (node.type === 1 /* ELEMENT_NODE */) {
|
|
708
|
+
const el = node as any
|
|
709
|
+
// Skip ads and promotional content
|
|
710
|
+
if (el.attributes?.class?.includes('ad')
|
|
711
|
+
|| el.attributes?.id?.includes('promo')) {
|
|
712
|
+
return { skip: true }
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
},
|
|
716
|
+
processTextNode(textNode) {
|
|
717
|
+
// Uppercase all TODO markers
|
|
718
|
+
if (textNode.value.includes('TODO')) {
|
|
719
|
+
return { content: textNode.value.toUpperCase(), skip: false }
|
|
720
|
+
}
|
|
721
|
+
},
|
|
722
|
+
}),
|
|
723
|
+
],
|
|
724
|
+
})
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
### Token-Based Chunking for LLMs
|
|
728
|
+
|
|
729
|
+
```typescript
|
|
730
|
+
import { htmlToMarkdownSplitChunks } from '@mdream/js/splitter'
|
|
731
|
+
import { encoding_for_model } from 'tiktoken'
|
|
732
|
+
|
|
733
|
+
const enc = encoding_for_model('gpt-4')
|
|
734
|
+
|
|
735
|
+
const chunks = htmlToMarkdownSplitChunks(html, {
|
|
736
|
+
chunkSize: 512,
|
|
737
|
+
chunkOverlap: 64,
|
|
738
|
+
lengthFunction: text => enc.encode(text).length,
|
|
739
|
+
origin: 'https://example.com',
|
|
740
|
+
})
|
|
741
|
+
```
|
|
742
|
+
|
|
743
|
+
---
|
|
744
|
+
|
|
745
|
+
## Exported Types
|
|
746
|
+
|
|
747
|
+
```typescript
|
|
748
|
+
import type {
|
|
749
|
+
BuiltinPlugins,
|
|
750
|
+
CleanOptions,
|
|
751
|
+
ElementNode,
|
|
752
|
+
EngineOptions,
|
|
753
|
+
ExtractedElement,
|
|
754
|
+
FrontmatterConfig,
|
|
755
|
+
MarkdownChunk,
|
|
756
|
+
MdreamOptions,
|
|
757
|
+
Node,
|
|
758
|
+
NodeEvent,
|
|
759
|
+
PluginContext,
|
|
760
|
+
SplitterOptions,
|
|
761
|
+
TagOverride,
|
|
762
|
+
TextNode,
|
|
763
|
+
TransformPlugin,
|
|
764
|
+
} from '@mdream/js'
|
|
765
|
+
|
|
766
|
+
import type { CoreOptions, Plugin } from '@mdream/js/core'
|
|
767
|
+
```
|
|
768
|
+
|
|
769
|
+
## Exported Constants
|
|
770
|
+
|
|
771
|
+
```typescript
|
|
772
|
+
import {
|
|
773
|
+
ELEMENT_NODE, // Node type for HTML elements (1)
|
|
774
|
+
NodeEventEnter, // Event type for entering a node (0)
|
|
775
|
+
NodeEventExit, // Event type for exiting a node (1)
|
|
776
|
+
TAG_H1, // Tag ID constant for <h1>
|
|
777
|
+
TAG_H2, // Tag ID constant for <h2>
|
|
778
|
+
TAG_H3, // Tag ID constant for <h3>
|
|
779
|
+
TAG_H4, // Tag ID constant for <h4>
|
|
780
|
+
TAG_H5, // Tag ID constant for <h5>
|
|
781
|
+
TAG_H6, // Tag ID constant for <h6>
|
|
782
|
+
TEXT_NODE, // Node type for text content (3)
|
|
783
|
+
} from '@mdream/js'
|
|
784
|
+
```
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
[npm-version-src]: https://img.shields.io/npm/v/@mdream/js/latest.svg?style=flat&colorA=18181B&colorB=4C9BE0
|
|
788
|
+
[npm-version-href]: https://npmjs.com/package/@mdream/js
|
|
789
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@mdream/js.svg?style=flat&colorA=18181B&colorB=4C9BE0
|
|
790
|
+
[npm-downloads-href]: https://npm.chart.dev/@mdream/js
|
|
791
|
+
[license-src]: https://img.shields.io/npm/l/@mdream/js.svg?style=flat&colorA=18181B&colorB=4C9BE0
|
|
792
|
+
[license-href]: https://npmjs.com/package/@mdream/js
|