@mdgate/rtf 0.6.8 → 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.
Files changed (2) hide show
  1. package/README.md +144 -8
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -1,11 +1,14 @@
1
1
  # @mdgate/rtf
2
2
 
3
- Convert RTF documents to Markdown. Outputs GitHub-Flavored Markdown. Works in Node, Edge, and
4
- browsers. No native addons.
3
+ **Convert RTF to Markdown in TypeScript.**
5
4
 
6
- Handles: `.rtf` (also RTF content wearing a `.doc` extension)
5
+ [`@mdgate/rtf`](https://github.com/mdgate/converters/tree/main/packages/rtf) reads Rich Text Format files directly in JavaScript and converts them into GitHub-Flavored Markdown, without Python, native addons, WASM, or Word.
7
6
 
8
- ## Usage
7
+ Works in **Node.js, Cloudflare Workers, Edge runtimes, and browsers**.
8
+
9
+ ```bash
10
+ npm install @mdgate/rtf
11
+ ```
9
12
 
10
13
  ```ts
11
14
  import { toMarkdown } from '@mdgate/rtf';
@@ -13,14 +16,147 @@ import { toMarkdown } from '@mdgate/rtf';
13
16
  const markdown = await toMarkdown(bytes);
14
17
  ```
15
18
 
16
- Compose with other converters:
19
+ `bytes` is a `Uint8Array`, so the document 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/rtf`](https://github.com/mdgate/converters/tree/main/packages/rtf)
24
+
25
+ RTF still shows up in email, older Word "Save As" output, and files that wear a `.doc` extension but start with `{\rtf`.
26
+
27
+ [`@mdgate/rtf`](https://github.com/mdgate/converters/tree/main/packages/rtf) is an RTF reader written for the same runtime as your application:
28
+
29
+ * **Pure TypeScript**
30
+ * **RTF → 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 RTF from the file contents, not only the filename**
37
+
38
+ ---
39
+
40
+ ## What it extracts
41
+
42
+ [`@mdgate/rtf`](https://github.com/mdgate/converters/tree/main/packages/rtf) lexes RTF control words and rebuilds a shared document model.
43
+
44
+ The converter handles RTF-specific concerns including:
45
+
46
+ * paragraphs and headings
47
+ * bold, italic, and strikethrough
48
+ * lists
49
+ * tables
50
+ * Unicode and legacy code-page text
51
+ * RTF content stored under a `.doc` name
52
+
53
+ The output is Markdown that can be searched, indexed, chunked, cached, or passed directly to an AI agent.
54
+
55
+ ---
56
+
57
+ ## Node.js
58
+
59
+ ```ts
60
+ import { readFile } from 'node:fs/promises';
61
+ import { toMarkdown } from '@mdgate/rtf';
62
+
63
+ const bytes = new Uint8Array(await readFile('notes.rtf'));
64
+ const markdown = await toMarkdown(bytes);
65
+
66
+ console.log(markdown);
67
+ ```
68
+
69
+ ---
70
+
71
+ ## Browser
72
+
73
+ ```ts
74
+ import { toMarkdown } from '@mdgate/rtf';
75
+
76
+ const file = input.files![0];
77
+ const bytes = new Uint8Array(await file.arrayBuffer());
78
+
79
+ const markdown = await toMarkdown(bytes);
80
+ ```
81
+
82
+ ---
83
+
84
+ ## Cloudflare Workers and Edge runtimes
85
+
86
+ ```ts
87
+ import { toMarkdown } from '@mdgate/rtf';
88
+
89
+ export default {
90
+ async fetch(request: Request) {
91
+ const bytes = new Uint8Array(await request.arrayBuffer());
92
+ const markdown = await toMarkdown(bytes);
93
+
94
+ return new Response(markdown, {
95
+ headers: {
96
+ 'content-type': 'text/markdown; charset=utf-8',
97
+ },
98
+ });
99
+ },
100
+ };
101
+ ```
102
+
103
+ ---
104
+
105
+ ## Format detection
106
+
107
+ You do not need to trust the file extension.
108
+
109
+ [`@mdgate/rtf`](https://github.com/mdgate/converters/tree/main/packages/rtf) recognizes RTF from the opening `{\rtf` group.
110
+
111
+ ```ts
112
+ const markdown = await toMarkdown(bytes);
113
+ ```
114
+
115
+ A path can still be supplied as a format hint when [`@mdgate/rtf`](https://github.com/mdgate/converters/tree/main/packages/rtf) 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.
116
+
117
+ ---
118
+
119
+ ## Compose it with other file readers
120
+
121
+ [`@mdgate/rtf`](https://github.com/mdgate/converters/tree/main/packages/rtf) implements the converter interface from [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core).
17
122
 
18
123
  ```ts
19
124
  import { create } from '@mdgate/core';
20
125
  import { rtf } from '@mdgate/rtf';
126
+ import { docx } from '@mdgate/docx';
127
+
128
+ const read = create([
129
+ rtf(),
130
+ docx(),
131
+ ]);
132
+ ```
133
+
134
+ The application still uses one reading interface while each format remains independently installable.
135
+
136
+ ---
137
+
138
+ ## Need more than RTF?
139
+
140
+ If your application needs to read many different file types, use the complete converter set:
21
141
 
22
- const convert = create([rtf()]);
142
+ ```bash
143
+ npm install @mdgate/converters
23
144
  ```
24
145
 
25
- Part of [mdgate converters](https://github.com/mdgate/converters); install
26
- `@mdgate/converters` for every format at once.
146
+ ```ts
147
+ import { toMarkdown } from '@mdgate/converters';
148
+
149
+ const markdown = await toMarkdown(bytes, {
150
+ path: filename,
151
+ });
152
+ ```
153
+
154
+ [`@mdgate/rtf`](https://github.com/mdgate/converters/tree/main/packages/rtf) is one of the single-format packages in the open-source [`mdgate/converters`](https://github.com/mdgate/converters) project.
155
+
156
+ For AI agents, the same converter architecture can be used to extend `read_file` from text files to real-world document formats.
157
+
158
+ ---
159
+
160
+ ## License
161
+
162
+ MIT
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@mdgate/rtf",
3
- "version": "0.6.8",
3
+ "version": "0.6.9",
4
4
  "description": "mdgate RTF converter",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
- "homepage": "https://demo.mdgate.dev",
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/core": "0.6.8",
32
- "@mdgate/document": "0.6.8",
33
- "@mdgate/office-common": "0.6.8",
34
- "@mdgate/utils": "0.6.8"
31
+ "@mdgate/core": "0.6.9",
32
+ "@mdgate/document": "0.6.9",
33
+ "@mdgate/office-common": "0.6.9",
34
+ "@mdgate/utils": "0.6.9"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"