html-to-markdown-node 2.3.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/LICENSE +21 -0
- package/README.md +229 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright 2024-2025 Na'aman Hirschfeld
|
|
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,229 @@
|
|
|
1
|
+
# html-to-markdown-node
|
|
2
|
+
|
|
3
|
+
Native Node.js and Bun bindings for html-to-markdown using NAPI-RS v3.
|
|
4
|
+
|
|
5
|
+
High-performance HTML to Markdown conversion using native Rust code compiled to platform-specific binaries.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/html-to-markdown-node)
|
|
8
|
+
[](https://github.com/Goldziher/html-to-markdown/blob/main/LICENSE)
|
|
9
|
+
|
|
10
|
+
## Performance
|
|
11
|
+
|
|
12
|
+
Native NAPI-RS bindings deliver **the fastest HTML to Markdown conversion** available in JavaScript.
|
|
13
|
+
|
|
14
|
+
### Benchmark Results (Apple M4)
|
|
15
|
+
|
|
16
|
+
| Document Type | ops/sec | Notes |
|
|
17
|
+
| -------------------------- | ---------- | ------------------ |
|
|
18
|
+
| **Small (5 paragraphs)** | **86,233** | Simple documents |
|
|
19
|
+
| **Medium (25 paragraphs)** | **18,979** | Nested formatting |
|
|
20
|
+
| **Large (100 paragraphs)** | **4,907** | Complex structures |
|
|
21
|
+
| **Tables (20 tables)** | **5,003** | Table processing |
|
|
22
|
+
| **Lists (500 items)** | **1,819** | Nested lists |
|
|
23
|
+
| **Wikipedia (129KB)** | **1,125** | Real-world content |
|
|
24
|
+
| **Wikipedia (653KB)** | **156** | Large documents |
|
|
25
|
+
|
|
26
|
+
**Average: ~18,162 ops/sec** across varied workloads.
|
|
27
|
+
|
|
28
|
+
### Comparison
|
|
29
|
+
|
|
30
|
+
- **vs WASM**: ~1.17× faster (native has zero startup time, direct memory access)
|
|
31
|
+
- **vs Python**: ~7.4× faster (avoids FFI overhead)
|
|
32
|
+
- **Best for**: Node.js and Bun server-side applications requiring maximum throughput
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
### Node.js
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install html-to-markdown-node
|
|
40
|
+
# or
|
|
41
|
+
yarn add html-to-markdown-node
|
|
42
|
+
# or
|
|
43
|
+
pnpm add html-to-markdown-node
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Bun
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
bun add html-to-markdown-node
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
### Node.js (CommonJS)
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
const { convert } = require('html-to-markdown-node');
|
|
58
|
+
|
|
59
|
+
const html = '<h1>Hello World</h1><p>This is <strong>fast</strong>!</p>';
|
|
60
|
+
const markdown = convert(html);
|
|
61
|
+
console.log(markdown);
|
|
62
|
+
// # Hello World
|
|
63
|
+
//
|
|
64
|
+
// This is **fast**!
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Node.js (ESM)
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
import { convert } from 'html-to-markdown-node';
|
|
71
|
+
|
|
72
|
+
const markdown = convert('<h1>Hello</h1>', {
|
|
73
|
+
headingStyle: 'Atx',
|
|
74
|
+
codeBlockStyle: 'Backticks',
|
|
75
|
+
wrap: true,
|
|
76
|
+
wrapWidth: 80
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Bun
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { convert } from 'html-to-markdown-node';
|
|
84
|
+
|
|
85
|
+
const html = await Bun.file('input.html').text();
|
|
86
|
+
const markdown = convert(html, {
|
|
87
|
+
headingStyle: 'Atx',
|
|
88
|
+
listIndentWidth: 2,
|
|
89
|
+
bullets: '-'
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
await Bun.write('output.md', markdown);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## TypeScript
|
|
96
|
+
|
|
97
|
+
Full TypeScript definitions included:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { convert, convertWithInlineImages, type JsConversionOptions } from 'html-to-markdown-node';
|
|
101
|
+
|
|
102
|
+
const options: JsConversionOptions = {
|
|
103
|
+
headingStyle: 'Atx',
|
|
104
|
+
codeBlockStyle: 'Backticks',
|
|
105
|
+
listIndentWidth: 2,
|
|
106
|
+
bullets: '-',
|
|
107
|
+
wrap: true,
|
|
108
|
+
wrapWidth: 80
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const markdown = convert('<h1>Hello</h1>', options);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Inline Images
|
|
115
|
+
|
|
116
|
+
Extract and decode inline images (data URIs, SVG):
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { convertWithInlineImages } from 'html-to-markdown-node';
|
|
120
|
+
|
|
121
|
+
const html = '<img src="data:image/png;base64,iVBORw0..." alt="Logo">';
|
|
122
|
+
|
|
123
|
+
const result = convertWithInlineImages(html, null, {
|
|
124
|
+
maxDecodedSizeBytes: 5 * 1024 * 1024, // 5MB
|
|
125
|
+
inferDimensions: true,
|
|
126
|
+
filenamePrefix: 'img_',
|
|
127
|
+
captureSvg: true
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
console.log(result.markdown);
|
|
131
|
+
console.log(`Extracted ${result.inlineImages.length} images`);
|
|
132
|
+
|
|
133
|
+
for (const img of result.inlineImages) {
|
|
134
|
+
console.log(`${img.filename}: ${img.format}, ${img.data.length} bytes`);
|
|
135
|
+
// Save image data to disk
|
|
136
|
+
require('fs').writeFileSync(img.filename, img.data);
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Supported Platforms
|
|
141
|
+
|
|
142
|
+
Pre-built native binaries are provided for:
|
|
143
|
+
|
|
144
|
+
| Platform | Architectures |
|
|
145
|
+
| ----------- | --------------------------------------------------- |
|
|
146
|
+
| **macOS** | x64 (Intel), ARM64 (Apple Silicon) |
|
|
147
|
+
| **Linux** | x64 (glibc/musl), ARM64 (glibc/musl), ARMv7 (glibc) |
|
|
148
|
+
| **Windows** | x64, ARM64 |
|
|
149
|
+
|
|
150
|
+
### Runtime Compatibility
|
|
151
|
+
|
|
152
|
+
✅ **Node.js** 18+ (LTS)
|
|
153
|
+
✅ **Bun** 1.0+ (full NAPI-RS support)
|
|
154
|
+
❌ **Deno** (use [html-to-markdown-wasm](https://www.npmjs.com/package/html-to-markdown-wasm) instead)
|
|
155
|
+
|
|
156
|
+
## When to Use
|
|
157
|
+
|
|
158
|
+
Choose `html-to-markdown-node` when:
|
|
159
|
+
|
|
160
|
+
- ✅ Running in Node.js or Bun
|
|
161
|
+
- ✅ Maximum performance is required
|
|
162
|
+
- ✅ Server-side conversion at scale
|
|
163
|
+
|
|
164
|
+
Use [`html-to-markdown-wasm`](https://www.npmjs.com/package/html-to-markdown-wasm) for:
|
|
165
|
+
|
|
166
|
+
- 🌐 Browser/client-side conversion
|
|
167
|
+
- 🦕 Deno runtime
|
|
168
|
+
- ☁️ Edge runtimes (Cloudflare Workers, Deno Deploy)
|
|
169
|
+
- 📦 Universal packages
|
|
170
|
+
|
|
171
|
+
## Configuration Options
|
|
172
|
+
|
|
173
|
+
See [ConversionOptions](https://github.com/Goldziher/html-to-markdown/tree/main/crates/html-to-markdown-node#types) for all available options including:
|
|
174
|
+
|
|
175
|
+
- Heading styles (ATX, underlined, ATX closed)
|
|
176
|
+
- Code block styles (indented, backticks, tildes)
|
|
177
|
+
- List formatting (indent width, bullet characters)
|
|
178
|
+
- Text escaping and formatting
|
|
179
|
+
- Preprocessing for web scraping
|
|
180
|
+
- hOCR table extraction
|
|
181
|
+
- And more...
|
|
182
|
+
|
|
183
|
+
## Examples
|
|
184
|
+
|
|
185
|
+
### Web Scraping
|
|
186
|
+
|
|
187
|
+
```javascript
|
|
188
|
+
const { convert } = require('html-to-markdown-node');
|
|
189
|
+
|
|
190
|
+
const scrapedHtml = await fetch('https://example.com').then(r => r.text());
|
|
191
|
+
|
|
192
|
+
const markdown = convert(scrapedHtml, {
|
|
193
|
+
preprocessing: {
|
|
194
|
+
enabled: true,
|
|
195
|
+
preset: 'Aggressive',
|
|
196
|
+
removeNavigation: true,
|
|
197
|
+
removeForms: true
|
|
198
|
+
},
|
|
199
|
+
headingStyle: 'Atx',
|
|
200
|
+
codeBlockStyle: 'Backticks'
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### hOCR Document Processing
|
|
205
|
+
|
|
206
|
+
```javascript
|
|
207
|
+
const { convert } = require('html-to-markdown-node');
|
|
208
|
+
const fs = require('fs');
|
|
209
|
+
|
|
210
|
+
// OCR output from Tesseract in hOCR format
|
|
211
|
+
const hocrHtml = fs.readFileSync('scan.hocr', 'utf8');
|
|
212
|
+
|
|
213
|
+
// Automatically detects hOCR and reconstructs tables
|
|
214
|
+
const markdown = convert(hocrHtml, {
|
|
215
|
+
hocrSpatialTables: true // Enable spatial table reconstruction
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Links
|
|
220
|
+
|
|
221
|
+
- [GitHub Repository](https://github.com/Goldziher/html-to-markdown)
|
|
222
|
+
- [Full Documentation](https://github.com/Goldziher/html-to-markdown/blob/main/README.md)
|
|
223
|
+
- [WASM Package](https://www.npmjs.com/package/html-to-markdown-wasm)
|
|
224
|
+
- [Python Package](https://pypi.org/project/html-to-markdown/)
|
|
225
|
+
- [Rust Crate](https://crates.io/crates/html-to-markdown-rs)
|
|
226
|
+
|
|
227
|
+
## License
|
|
228
|
+
|
|
229
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "html-to-markdown-node",
|
|
3
|
+
"version": "2.3.1",
|
|
4
|
+
"description": "High-performance HTML to Markdown converter - Node.js native bindings",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"repository": "https://github.com/Goldziher/html-to-markdown",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"html",
|
|
11
|
+
"markdown",
|
|
12
|
+
"converter",
|
|
13
|
+
"rust",
|
|
14
|
+
"napi",
|
|
15
|
+
"native"
|
|
16
|
+
],
|
|
17
|
+
"files": [
|
|
18
|
+
"index.js",
|
|
19
|
+
"index.d.ts"
|
|
20
|
+
],
|
|
21
|
+
"napi": {
|
|
22
|
+
"binaryName": "html-to-markdown-node",
|
|
23
|
+
"targets": [
|
|
24
|
+
"x86_64-apple-darwin",
|
|
25
|
+
"aarch64-apple-darwin",
|
|
26
|
+
"x86_64-pc-windows-msvc",
|
|
27
|
+
"aarch64-pc-windows-msvc",
|
|
28
|
+
"x86_64-unknown-linux-gnu",
|
|
29
|
+
"x86_64-unknown-linux-musl",
|
|
30
|
+
"aarch64-unknown-linux-gnu",
|
|
31
|
+
"aarch64-unknown-linux-musl",
|
|
32
|
+
"armv7-unknown-linux-gnueabihf"
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">= 10"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"registry": "https://registry.npmjs.org/",
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@napi-rs/cli": "^3.3.1",
|
|
44
|
+
"@types/node": "^24.7.2",
|
|
45
|
+
"tinybench": "^5.0.1",
|
|
46
|
+
"tsx": "^4.20.6",
|
|
47
|
+
"vitest": "^3.0.0"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@emnapi/runtime": "1.5.0",
|
|
51
|
+
"@octokit/core": "7.0.5",
|
|
52
|
+
"typanion": "3.14.0",
|
|
53
|
+
"up": "^1.0.2"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"artifacts": "napi artifacts",
|
|
57
|
+
"build": "napi build --platform --release",
|
|
58
|
+
"build:debug": "napi build --platform",
|
|
59
|
+
"test": "vitest run",
|
|
60
|
+
"test:watch": "vitest",
|
|
61
|
+
"test:simple": "node test.js",
|
|
62
|
+
"bench": "tsx benchmark.ts",
|
|
63
|
+
"universal": "napi universal",
|
|
64
|
+
"version": "napi version",
|
|
65
|
+
"clean": "rm -rf dist node_modules *.node"
|
|
66
|
+
}
|
|
67
|
+
}
|