@mdgate/fb2 0.6.7 → 0.6.9
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 +142 -8
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
# @mdgate/fb2
|
|
2
2
|
|
|
3
|
-
Convert FictionBook (FB2) files to Markdown
|
|
4
|
-
and browsers. No native addons.
|
|
3
|
+
**Convert FictionBook (FB2) files to Markdown in TypeScript.**
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
[`@mdgate/fb2`](https://github.com/mdgate/converters/tree/main/packages/fb2) reads `.fb2` and `.fb2.zip` files directly in JavaScript and converts them into GitHub-Flavored Markdown, without Python, native addons, WASM, or an ebook app.
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
Works in **Node.js, Cloudflare Workers, Edge runtimes, and browsers**.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @mdgate/fb2
|
|
11
|
+
```
|
|
9
12
|
|
|
10
13
|
```ts
|
|
11
14
|
import { toMarkdown } from '@mdgate/fb2';
|
|
@@ -13,14 +16,145 @@ import { toMarkdown } from '@mdgate/fb2';
|
|
|
13
16
|
const markdown = await toMarkdown(bytes);
|
|
14
17
|
```
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
`bytes` is a `Uint8Array`, so the book can come from a file upload, object storage, an HTTP request, a browser file picker, or anywhere else your application gets bytes.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Why [`@mdgate/fb2`](https://github.com/mdgate/converters/tree/main/packages/fb2)
|
|
24
|
+
|
|
25
|
+
FB2 is a common ebook format in Russian and other Cyrillic libraries. It is XML, not EPUB.
|
|
26
|
+
|
|
27
|
+
[`@mdgate/fb2`](https://github.com/mdgate/converters/tree/main/packages/fb2) is an FB2 reader written for the same runtime as your application:
|
|
28
|
+
|
|
29
|
+
* **Pure TypeScript**
|
|
30
|
+
* **FB2 → Markdown locally**
|
|
31
|
+
* **No Python runtime**
|
|
32
|
+
* **No native addons**
|
|
33
|
+
* **No WASM runtime**
|
|
34
|
+
* **Zero third-party runtime dependencies**
|
|
35
|
+
* **Works with raw `Uint8Array` input**
|
|
36
|
+
* **Detects FB2 XML and FB2 ZIP from their contents, not only the filename**
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## What it extracts
|
|
41
|
+
|
|
42
|
+
[`@mdgate/fb2`](https://github.com/mdgate/converters/tree/main/packages/fb2) parses FictionBook XML (plain or zipped) and rebuilds a shared document model.
|
|
43
|
+
|
|
44
|
+
The converter handles FB2-specific concerns including:
|
|
45
|
+
|
|
46
|
+
* title and body sections
|
|
47
|
+
* headings and paragraphs
|
|
48
|
+
* emphasis
|
|
49
|
+
* nested ZIP (`.fb2.zip`)
|
|
50
|
+
|
|
51
|
+
The output is Markdown that can be searched, indexed, chunked, cached, or passed directly to an AI agent.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Node.js
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { readFile } from 'node:fs/promises';
|
|
59
|
+
import { toMarkdown } from '@mdgate/fb2';
|
|
60
|
+
|
|
61
|
+
const bytes = new Uint8Array(await readFile('book.fb2'));
|
|
62
|
+
const markdown = await toMarkdown(bytes);
|
|
63
|
+
|
|
64
|
+
console.log(markdown);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Browser
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { toMarkdown } from '@mdgate/fb2';
|
|
73
|
+
|
|
74
|
+
const file = input.files![0];
|
|
75
|
+
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
76
|
+
|
|
77
|
+
const markdown = await toMarkdown(bytes);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Cloudflare Workers and Edge runtimes
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { toMarkdown } from '@mdgate/fb2';
|
|
86
|
+
|
|
87
|
+
export default {
|
|
88
|
+
async fetch(request: Request) {
|
|
89
|
+
const bytes = new Uint8Array(await request.arrayBuffer());
|
|
90
|
+
const markdown = await toMarkdown(bytes);
|
|
91
|
+
|
|
92
|
+
return new Response(markdown, {
|
|
93
|
+
headers: {
|
|
94
|
+
'content-type': 'text/markdown; charset=utf-8',
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Format detection
|
|
104
|
+
|
|
105
|
+
You do not need to trust the file extension.
|
|
106
|
+
|
|
107
|
+
[`@mdgate/fb2`](https://github.com/mdgate/converters/tree/main/packages/fb2) recognizes FictionBook XML and zipped FB2 from their contents.
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
const markdown = await toMarkdown(bytes);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
A path can still be supplied as a format hint when [`@mdgate/fb2`](https://github.com/mdgate/converters/tree/main/packages/fb2) is used through [`@mdgate/converters`](https://github.com/mdgate/converters/tree/main/packages/converters) or a reader composed with [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core), but the path is never used to read a file from disk.
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Compose it with other file readers
|
|
118
|
+
|
|
119
|
+
[`@mdgate/fb2`](https://github.com/mdgate/converters/tree/main/packages/fb2) implements the converter interface from [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core).
|
|
17
120
|
|
|
18
121
|
```ts
|
|
19
122
|
import { create } from '@mdgate/core';
|
|
20
123
|
import { fb2 } from '@mdgate/fb2';
|
|
124
|
+
import { epub } from '@mdgate/epub';
|
|
125
|
+
|
|
126
|
+
const read = create([
|
|
127
|
+
fb2(),
|
|
128
|
+
epub(),
|
|
129
|
+
]);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The application still uses one reading interface while each format remains independently installable.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Need more than FB2?
|
|
137
|
+
|
|
138
|
+
If your application needs to read many different file types, use the complete converter set:
|
|
21
139
|
|
|
22
|
-
|
|
140
|
+
```bash
|
|
141
|
+
npm install @mdgate/converters
|
|
23
142
|
```
|
|
24
143
|
|
|
25
|
-
|
|
26
|
-
|
|
144
|
+
```ts
|
|
145
|
+
import { toMarkdown } from '@mdgate/converters';
|
|
146
|
+
|
|
147
|
+
const markdown = await toMarkdown(bytes, {
|
|
148
|
+
path: filename,
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
[`@mdgate/fb2`](https://github.com/mdgate/converters/tree/main/packages/fb2) is one of the single-format packages in the open-source [`mdgate/converters`](https://github.com/mdgate/converters) project.
|
|
153
|
+
|
|
154
|
+
For AI agents, the same converter architecture can be used to extend `read_file` from text files to real-world document formats.
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## License
|
|
159
|
+
|
|
160
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdgate/fb2",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"description": "mdgate FictionBook (FB2) converter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"homepage": "https://
|
|
7
|
+
"homepage": "https://convert.mdgate.dev",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/mdgate/converters.git",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"prepublishOnly": "bun run build"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@mdgate/containers": "0.6.
|
|
32
|
-
"@mdgate/core": "0.6.
|
|
33
|
-
"@mdgate/document": "0.6.
|
|
34
|
-
"@mdgate/utils": "0.6.
|
|
31
|
+
"@mdgate/containers": "0.6.9",
|
|
32
|
+
"@mdgate/core": "0.6.9",
|
|
33
|
+
"@mdgate/document": "0.6.9",
|
|
34
|
+
"@mdgate/utils": "0.6.9"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|