@mdgate/hwp 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 +168 -15
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -1,36 +1,189 @@
1
1
  # @mdgate/hwp
2
2
 
3
- Convert Hangul Word Processor files to Markdown. Outputs GitHub-Flavored Markdown. Works in Node,
4
- Edge, and browsers. No native addons.
3
+ **Convert Hangul / Hancom documents to Markdown in TypeScript.**
5
4
 
6
- Handles: `.hwp`, `.hwpx`, `.hwt`, `.hwtx`
5
+ [`@mdgate/hwp`](https://github.com/mdgate/converters/tree/main/packages/hwp) reads `.hwp`, `.hwpx`, `.hwt`, and `.hwtx` files directly in JavaScript and converts them into GitHub-Flavored Markdown, without Python, native addons, WASM, or Hancom Office.
7
6
 
8
- - **HWPX / HWTX** ZIP + OWPML. Reads `Contents/section*.xml` (and `Contents/header.xml` for
9
- outline/heading styles) for paragraphs, line breaks, and tables.
10
- - **HWP / HWT** — OLE compound files (HWP 5) or the classic `HWP Document File` signature (HWP 3).
11
- BodyText section streams are decompressed and scanned for `PARA_TEXT` records when the layout is
12
- recognizable. The binary record format is only partially specified publicly; when a stream is too
13
- opaque, readable UTF-16 strings (and the `PrvText` preview) are emitted as paragraphs. Tables,
14
- drawings, and other controls in binary HWP are not reconstructed.
7
+ Works in **Node.js, Cloudflare Workers, Edge runtimes, and browsers**.
8
+
9
+ ```bash
10
+ npm install @mdgate/hwp
11
+ ```
12
+
13
+ ```ts
14
+ import { toMarkdown } from '@mdgate/hwp';
15
+
16
+ const markdown = await toMarkdown(bytes);
17
+ ```
18
+
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/hwp`](https://github.com/mdgate/converters/tree/main/packages/hwp)
24
+
25
+ HWP is a default office format in a large part of Korea. A Word parser will not read it.
26
+
27
+ [`@mdgate/hwp`](https://github.com/mdgate/converters/tree/main/packages/hwp) is a Hangul reader written for the same runtime as your application:
28
+
29
+ * **Pure TypeScript**
30
+ * **HWP → 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 HWP / HWPX from their contents, not only the filename**
37
+
38
+ Use it when an agent or ingestion pipeline has to read the files Korean users actually send.
39
+
40
+ ---
41
+
42
+ ## What it extracts
43
+
44
+ HWP is several formats under one name. [`@mdgate/hwp`](https://github.com/mdgate/converters/tree/main/packages/hwp) handles them differently.
45
+
46
+ **HWPX / HWTX** (ZIP + OWPML):
47
+
48
+ * paragraphs and line breaks from `Contents/section*.xml`
49
+ * heading styles from `Contents/header.xml` when present
50
+ * tables
51
+
52
+ **HWP / HWT** (OLE HWP 5, or the classic `HWP Document File` signature for HWP 3):
53
+
54
+ * `PARA_TEXT` records when the binary layout is recognizable
55
+ * readable UTF-16 strings and the `PrvText` preview as paragraphs when a stream is too opaque
56
+ * tables, drawings, and other binary controls are not reconstructed
57
+
58
+ The binary record format is only partly specified in public. The converter prefers structured text when it can find it, and falls back to extracted strings rather than pretending it has a full HWP renderer.
15
59
 
16
60
  Encrypted or distribution-locked documents fail with `ConvertError.encrypted`.
17
61
 
18
- ## Usage
62
+ ---
63
+
64
+ ## Node.js
65
+
66
+ ```ts
67
+ import { readFile } from 'node:fs/promises';
68
+ import { toMarkdown } from '@mdgate/hwp';
69
+
70
+ const bytes = new Uint8Array(await readFile('report.hwp'));
71
+ const markdown = await toMarkdown(bytes);
72
+
73
+ console.log(markdown);
74
+ ```
75
+
76
+ ---
77
+
78
+ ## Browser
79
+
80
+ ```ts
81
+ import { toMarkdown } from '@mdgate/hwp';
82
+
83
+ const file = input.files![0];
84
+ const bytes = new Uint8Array(await file.arrayBuffer());
85
+
86
+ const markdown = await toMarkdown(bytes);
87
+ ```
88
+
89
+ ---
90
+
91
+ ## Cloudflare Workers and Edge runtimes
19
92
 
20
93
  ```ts
21
94
  import { toMarkdown } from '@mdgate/hwp';
22
95
 
96
+ export default {
97
+ async fetch(request: Request) {
98
+ const bytes = new Uint8Array(await request.arrayBuffer());
99
+ const markdown = await toMarkdown(bytes);
100
+
101
+ return new Response(markdown, {
102
+ headers: {
103
+ 'content-type': 'text/markdown; charset=utf-8',
104
+ },
105
+ });
106
+ },
107
+ };
108
+ ```
109
+
110
+ ```text
111
+ upload HWP
112
+
113
+ Cloudflare Worker
114
+
115
+ @mdgate/hwp
116
+
117
+ Markdown
118
+
119
+ agent / search / index / storage
120
+ ```
121
+
122
+ ---
123
+
124
+ ## Format detection
125
+
126
+ You do not need to trust the file extension.
127
+
128
+ [`@mdgate/hwp`](https://github.com/mdgate/converters/tree/main/packages/hwp) recognizes HWPX ZIP packages, HWP 5 OLE streams, and the HWP 3 file signature from the bytes.
129
+
130
+ ```ts
23
131
  const markdown = await toMarkdown(bytes);
24
132
  ```
25
133
 
26
- Compose with other converters:
134
+ A path can still be supplied as a format hint when [`@mdgate/hwp`](https://github.com/mdgate/converters/tree/main/packages/hwp) 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.
135
+
136
+ ---
137
+
138
+ ## Encrypted documents
139
+
140
+ Encrypted or password-protected HWP files are reported as encrypted rather than returning misleading partial output.
141
+
142
+ ---
143
+
144
+ ## Compose it with other file readers
145
+
146
+ [`@mdgate/hwp`](https://github.com/mdgate/converters/tree/main/packages/hwp) implements the converter interface from [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core).
27
147
 
28
148
  ```ts
29
149
  import { create } from '@mdgate/core';
30
150
  import { hwp } from '@mdgate/hwp';
151
+ import { docx } from '@mdgate/docx';
152
+ import { pdf } from '@mdgate/pdf';
153
+
154
+ const read = create([
155
+ hwp(),
156
+ docx(),
157
+ pdf(),
158
+ ]);
159
+ ```
160
+
161
+ The application still uses one reading interface while each format remains independently installable.
162
+
163
+ ---
164
+
165
+ ## Need more than HWP?
31
166
 
32
- const convert = create([hwp()]);
167
+ If your application needs to read many different file types, use the complete converter set:
168
+
169
+ ```bash
170
+ npm install @mdgate/converters
171
+ ```
172
+
173
+ ```ts
174
+ import { toMarkdown } from '@mdgate/converters';
175
+
176
+ const markdown = await toMarkdown(bytes, {
177
+ path: filename,
178
+ });
33
179
  ```
34
180
 
35
- Part of [mdgate converters](https://github.com/mdgate/converters); install
36
- `@mdgate/converters` for every format at once.
181
+ [`@mdgate/hwp`](https://github.com/mdgate/converters/tree/main/packages/hwp) is one of the single-format packages in the open-source [`mdgate/converters`](https://github.com/mdgate/converters) project.
182
+
183
+ For AI agents, the same converter architecture can be used to extend `read_file` from text files to real-world document formats.
184
+
185
+ ---
186
+
187
+ ## License
188
+
189
+ MIT
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@mdgate/hwp",
3
- "version": "0.6.8",
3
+ "version": "0.6.9",
4
4
  "description": "mdgate Hangul HWP / HWPX 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/containers": "0.6.8",
32
- "@mdgate/core": "0.6.8",
33
- "@mdgate/document": "0.6.8",
34
- "@mdgate/utils": "0.6.8"
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"