kordoc 4.0.8 → 4.2.0
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 +50 -16
- package/dist/{-LE4RLXVA.js → -SXQIZHYA.js} +24 -10
- package/dist/{parser-TCTCSBYZ.js → chunk-26AJJCFF.js} +1427 -2027
- package/dist/chunk-26AJJCFF.js.map +1 -0
- package/dist/{parser-KMMUS73Q.js → chunk-4JPPLIIV.js} +1425 -2025
- package/dist/chunk-4JPPLIIV.js.map +1 -0
- package/dist/chunk-4VNLZ2GZ.js +13 -0
- package/dist/chunk-4VNLZ2GZ.js.map +1 -0
- package/dist/{chunk-2DZQF6YJ.js → chunk-6SHO3BNV.js} +24 -15
- package/dist/chunk-6SHO3BNV.js.map +1 -0
- package/dist/chunk-7FCNOKOR.js +144 -0
- package/dist/chunk-7FCNOKOR.js.map +1 -0
- package/dist/{chunk-6XAAYAWL.cjs → chunk-CMN3SYZ3.js} +62 -304
- package/dist/chunk-CMN3SYZ3.js.map +1 -0
- package/dist/chunk-DZIXKL7E.js +145 -0
- package/dist/chunk-DZIXKL7E.js.map +1 -0
- package/dist/chunk-ELOV2GIJ.js +82 -0
- package/dist/chunk-ELOV2GIJ.js.map +1 -0
- package/dist/chunk-F2HYH62H.cjs +130 -0
- package/dist/chunk-F2HYH62H.cjs.map +1 -0
- package/dist/{chunk-HMUEU7D7.js → chunk-FSXLSHCW.js} +3 -3
- package/dist/{chunk-HMUEU7D7.js.map → chunk-FSXLSHCW.js.map} +1 -1
- package/dist/chunk-GEPINOL6.js +83 -0
- package/dist/chunk-GEPINOL6.js.map +1 -0
- package/dist/chunk-H7OWEYH2.cjs +243 -0
- package/dist/chunk-H7OWEYH2.cjs.map +1 -0
- package/dist/{chunk-7S3M4N4E.js → chunk-IGGRLWT5.js} +683 -226
- package/dist/chunk-IGGRLWT5.js.map +1 -0
- package/dist/chunk-J2RZ444H.js +243 -0
- package/dist/chunk-J2RZ444H.js.map +1 -0
- package/dist/chunk-JP5YH3Z4.js +130 -0
- package/dist/chunk-JP5YH3Z4.js.map +1 -0
- package/dist/{parser-ITMU2WN5.cjs → chunk-LHROM2BO.cjs} +1409 -2012
- package/dist/chunk-LHROM2BO.cjs.map +1 -0
- package/dist/chunk-NNDVFNMJ.js +246 -0
- package/dist/chunk-NNDVFNMJ.js.map +1 -0
- package/dist/{chunk-RROH5WHO.js → chunk-PLIY23LY.js} +2 -2
- package/dist/{chunk-BNU5QGIZ.js → chunk-V6U6YS5B.js} +12 -4
- package/dist/chunk-V6U6YS5B.js.map +1 -0
- package/dist/{chunk-UEIYETCQ.js → chunk-WF2E5P2G.js} +40 -35
- package/dist/chunk-WF2E5P2G.js.map +1 -0
- package/dist/{chunk-D35VBACN.js → chunk-WQLHPOMJ.js} +7 -4
- package/dist/chunk-WQLHPOMJ.js.map +1 -0
- package/dist/{chunk-OQPILS7B.js → chunk-XTCT6KQ5.cjs} +79 -183
- package/dist/chunk-XTCT6KQ5.cjs.map +1 -0
- package/dist/{chunk-MEPHGCPQ.js → chunk-YOO6ET6M.js} +7 -3
- package/dist/chunk-YOO6ET6M.js.map +1 -0
- package/dist/chunks-ZQEFAZNC.js +10 -0
- package/dist/cli.js +228 -36
- package/dist/cli.js.map +1 -1
- package/dist/{detect-RI2MQ33K.js → detect-YEZX2XCF.js} +2 -2
- package/dist/{formula-RXVSQPXI.js → formula-KSNAEBZ2.js} +23 -232
- package/dist/formula-KSNAEBZ2.js.map +1 -0
- package/dist/{formula-5NKVS2LR.cjs → formula-SB3NHDUM.cjs} +30 -240
- package/dist/formula-SB3NHDUM.cjs.map +1 -0
- package/dist/{formula-JCNF43NE.js → formula-SXC6LRRC.js} +23 -233
- package/dist/formula-SXC6LRRC.js.map +1 -0
- package/dist/index.cjs +1280 -589
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +112 -4
- package/dist/index.d.ts +112 -4
- package/dist/index.js +929 -238
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +278 -68
- package/dist/mcp.js.map +1 -1
- package/dist/models-KA4GLQK5.js +25 -0
- package/dist/parser-ND2YGQZR.js +800 -0
- package/dist/parser-ND2YGQZR.js.map +1 -0
- package/dist/parser-RBZHA6SY.js +804 -0
- package/dist/parser-RBZHA6SY.js.map +1 -0
- package/dist/parser-WDZOMDG4.cjs +803 -0
- package/dist/parser-WDZOMDG4.cjs.map +1 -0
- package/dist/pdf-ocr-2Z7VZIFI.cjs +439 -0
- package/dist/pdf-ocr-2Z7VZIFI.cjs.map +1 -0
- package/dist/pdf-ocr-FJFXFADQ.js +438 -0
- package/dist/pdf-ocr-FJFXFADQ.js.map +1 -0
- package/dist/pdf-ocr-VYE4DHD4.js +386 -0
- package/dist/pdf-ocr-VYE4DHD4.js.map +1 -0
- package/dist/{profile-io-SLN4P76T.js → profile-io-TWHDIVPL.js} +3 -3
- package/dist/rasterize-W2NEZUSW.js +40 -0
- package/dist/rasterize-W2NEZUSW.js.map +1 -0
- package/dist/redact-7ILEAUTS.js +12 -0
- package/dist/redact-7ILEAUTS.js.map +1 -0
- package/dist/render-4MG5QUDG.js +10 -0
- package/dist/render-4MG5QUDG.js.map +1 -0
- package/dist/seal-D2QNXJVO.js +10 -0
- package/dist/seal-D2QNXJVO.js.map +1 -0
- package/dist/{setup-57FB3LSP.js → setup-Q2PRE7UA.js} +5 -3
- package/dist/setup-Q2PRE7UA.js.map +1 -0
- package/dist/{watch-OHQWSVPE.js → watch-VWXJZT2R.js} +78 -23
- package/dist/watch-VWXJZT2R.js.map +1 -0
- package/package.json +2 -1
- package/dist/chunk-2DZQF6YJ.js.map +0 -1
- package/dist/chunk-6XAAYAWL.cjs.map +0 -1
- package/dist/chunk-7S3M4N4E.js.map +0 -1
- package/dist/chunk-BNU5QGIZ.js.map +0 -1
- package/dist/chunk-D35VBACN.js.map +0 -1
- package/dist/chunk-MEPHGCPQ.js.map +0 -1
- package/dist/chunk-OQPILS7B.js.map +0 -1
- package/dist/chunk-UEIYETCQ.js.map +0 -1
- package/dist/formula-5NKVS2LR.cjs.map +0 -1
- package/dist/formula-JCNF43NE.js.map +0 -1
- package/dist/formula-RXVSQPXI.js.map +0 -1
- package/dist/parser-ITMU2WN5.cjs.map +0 -1
- package/dist/parser-KMMUS73Q.js.map +0 -1
- package/dist/parser-TCTCSBYZ.js.map +0 -1
- package/dist/provider-4ZJKV3DC.js +0 -37
- package/dist/provider-4ZJKV3DC.js.map +0 -1
- package/dist/provider-AKROB7WQ.js +0 -39
- package/dist/provider-AKROB7WQ.js.map +0 -1
- package/dist/provider-G4C2V2PD.cjs +0 -39
- package/dist/provider-G4C2V2PD.cjs.map +0 -1
- package/dist/render-25BT623I.js +0 -10
- package/dist/seal-R4TETA4C.js +0 -10
- package/dist/setup-57FB3LSP.js.map +0 -1
- package/dist/watch-OHQWSVPE.js.map +0 -1
- /package/dist/{-LE4RLXVA.js.map → -SXQIZHYA.js.map} +0 -0
- /package/dist/{chunk-RROH5WHO.js.map → chunk-PLIY23LY.js.map} +0 -0
- /package/dist/{detect-RI2MQ33K.js.map → chunks-ZQEFAZNC.js.map} +0 -0
- /package/dist/{profile-io-SLN4P76T.js.map → detect-YEZX2XCF.js.map} +0 -0
- /package/dist/{render-25BT623I.js.map → models-KA4GLQK5.js.map} +0 -0
- /package/dist/{seal-R4TETA4C.js.map → profile-io-TWHDIVPL.js.map} +0 -0
|
@@ -1,104 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return buf.buffer;
|
|
6
|
-
}
|
|
7
|
-
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
8
|
-
}
|
|
9
|
-
var KordocError = class extends Error {
|
|
10
|
-
constructor(message) {
|
|
11
|
-
super(message);
|
|
12
|
-
this.name = "KordocError";
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
function isPathTraversal(name) {
|
|
16
|
-
if (name.includes("\0")) return true;
|
|
17
|
-
const normalized = name.replace(/\\/g, "/");
|
|
18
|
-
const segments = normalized.split("/");
|
|
19
|
-
return segments.some((s) => s === "..") || normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized);
|
|
20
|
-
}
|
|
21
|
-
function normalizeSectionHref(href) {
|
|
22
|
-
if (!href) return null;
|
|
23
|
-
let normalized = href.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
24
|
-
if (isPathTraversal(normalized)) return null;
|
|
25
|
-
if (/^[Ss]ection\d+\.xml$/.test(normalized)) normalized = "Contents/" + normalized;
|
|
26
|
-
return /(?:^|\/)[Ss]ection\d+\.xml$/.test(normalized) ? normalized : null;
|
|
27
|
-
}
|
|
28
|
-
function compareSectionPaths(a, b) {
|
|
29
|
-
const ai = Number(_nullishCoalesce(_optionalChain([a, 'access', _2 => _2.match, 'call', _3 => _3(/[Ss]ection(\d+)\.xml$/), 'optionalAccess', _4 => _4[1]]), () => ( Number.MAX_SAFE_INTEGER)));
|
|
30
|
-
const bi = Number(_nullishCoalesce(_optionalChain([b, 'access', _5 => _5.match, 'call', _6 => _6(/[Ss]ection(\d+)\.xml$/), 'optionalAccess', _7 => _7[1]]), () => ( Number.MAX_SAFE_INTEGER)));
|
|
31
|
-
return ai === bi ? a.localeCompare(b) : ai - bi;
|
|
32
|
-
}
|
|
33
|
-
function precheckZipSize(buffer, maxUncompressedSize = 100 * 1024 * 1024, maxEntries = 500) {
|
|
34
|
-
try {
|
|
35
|
-
const data = new DataView(buffer);
|
|
36
|
-
const len = buffer.byteLength;
|
|
37
|
-
let eocdOffset = -1;
|
|
38
|
-
for (let i = len - 22; i >= Math.max(0, len - 65557); i--) {
|
|
39
|
-
if (data.getUint32(i, true) === 101010256) {
|
|
40
|
-
eocdOffset = i;
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (eocdOffset < 0) return { totalUncompressed: 0, entryCount: 0 };
|
|
45
|
-
const entryCount = data.getUint16(eocdOffset + 10, true);
|
|
46
|
-
if (entryCount > maxEntries) {
|
|
47
|
-
throw new KordocError(`ZIP \uC5D4\uD2B8\uB9AC \uC218 \uCD08\uACFC: ${entryCount} (\uCD5C\uB300 ${maxEntries})`);
|
|
48
|
-
}
|
|
49
|
-
const cdSize = data.getUint32(eocdOffset + 12, true);
|
|
50
|
-
const cdOffset = data.getUint32(eocdOffset + 16, true);
|
|
51
|
-
if (cdOffset + cdSize > len) return { totalUncompressed: 0, entryCount };
|
|
52
|
-
let totalUncompressed = 0;
|
|
53
|
-
let pos = cdOffset;
|
|
54
|
-
for (let i = 0; i < entryCount && pos + 46 <= cdOffset + cdSize; i++) {
|
|
55
|
-
if (data.getUint32(pos, true) !== 33639248) break;
|
|
56
|
-
totalUncompressed += data.getUint32(pos + 24, true);
|
|
57
|
-
const nameLen = data.getUint16(pos + 28, true);
|
|
58
|
-
const extraLen = data.getUint16(pos + 30, true);
|
|
59
|
-
const commentLen = data.getUint16(pos + 32, true);
|
|
60
|
-
pos += 46 + nameLen + extraLen + commentLen;
|
|
61
|
-
}
|
|
62
|
-
if (totalUncompressed > maxUncompressedSize) {
|
|
63
|
-
throw new KordocError(`ZIP \uBE44\uC555\uCD95 \uD06C\uAE30 \uCD08\uACFC: ${(totalUncompressed / 1024 / 1024).toFixed(1)}MB (\uCD5C\uB300 ${maxUncompressedSize / 1024 / 1024}MB)`);
|
|
64
|
-
}
|
|
65
|
-
return { totalUncompressed, entryCount };
|
|
66
|
-
} catch (err) {
|
|
67
|
-
if (err instanceof KordocError) throw err;
|
|
68
|
-
return { totalUncompressed: 0, entryCount: 0 };
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
function stripDtd(xml) {
|
|
72
|
-
return xml.replace(/<!DOCTYPE\s[^[>]*(\[[\s\S]*?\])?\s*>/gi, "");
|
|
73
|
-
}
|
|
74
|
-
var SAFE_HREF_RE = /^(?:https?:|mailto:|tel:|#)/i;
|
|
75
|
-
function sanitizeHref(href) {
|
|
76
|
-
const trimmed = href.trim();
|
|
77
|
-
if (!trimmed || !SAFE_HREF_RE.test(trimmed)) return null;
|
|
78
|
-
return trimmed;
|
|
79
|
-
}
|
|
80
|
-
function safeMin(arr) {
|
|
81
|
-
let min = Infinity;
|
|
82
|
-
for (let i = 0; i < arr.length; i++) if (arr[i] < min) min = arr[i];
|
|
83
|
-
return min;
|
|
84
|
-
}
|
|
85
|
-
function safeMax(arr) {
|
|
86
|
-
let max = -Infinity;
|
|
87
|
-
for (let i = 0; i < arr.length; i++) if (arr[i] > max) max = arr[i];
|
|
88
|
-
return max;
|
|
89
|
-
}
|
|
90
|
-
function classifyError(err) {
|
|
91
|
-
if (!(err instanceof Error)) return "PARSE_ERROR";
|
|
92
|
-
const msg = err.message;
|
|
93
|
-
if (msg.includes("\uC554\uD638\uD654")) return "ENCRYPTED";
|
|
94
|
-
if (msg.includes("DRM")) return "DRM_PROTECTED";
|
|
95
|
-
if (msg.includes("ZIP bomb") || msg.includes("ZIP \uBE44\uC555\uCD95 \uD06C\uAE30 \uCD08\uACFC") || msg.includes("ZIP \uC5D4\uD2B8\uB9AC \uC218 \uCD08\uACFC")) return "ZIP_BOMB";
|
|
96
|
-
if (msg.includes("bomb") || msg.includes("\uD06C\uAE30 \uCD08\uACFC") || msg.includes("\uC555\uCD95 \uD574\uC81C")) return "DECOMPRESSION_BOMB";
|
|
97
|
-
if (msg.includes("\uC774\uBBF8\uC9C0 \uAE30\uBC18")) return "IMAGE_BASED_PDF";
|
|
98
|
-
if (msg.includes("\uC139\uC158") && (msg.includes("\uCC3E\uC744 \uC218 \uC5C6") || msg.includes("\uC5C6\uC74C"))) return "NO_SECTIONS";
|
|
99
|
-
if (msg.includes("\uC2DC\uADF8\uB2C8\uCC98") || msg.includes("\uBCF5\uAD6C\uD560 \uC218 \uC5C6")) return "CORRUPTED";
|
|
100
|
-
return "PARSE_ERROR";
|
|
101
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
sanitizeHref
|
|
4
|
+
} from "./chunk-FSXLSHCW.js";
|
|
102
5
|
|
|
103
6
|
// src/shared/pua.ts
|
|
104
7
|
var BMP_SYMBOL_MAP = {
|
|
@@ -218,8 +121,10 @@ var SUPPLEMENTARY_MAP = {
|
|
|
218
121
|
// ▸
|
|
219
122
|
985103: "\u2501",
|
|
220
123
|
// ━
|
|
221
|
-
985127: "\u25A0"
|
|
124
|
+
985127: "\u25A0",
|
|
222
125
|
// ■
|
|
126
|
+
984005: "\u25A1"
|
|
127
|
+
// □ 글머리 — HWP3→HWP5 한컴 변환본 보존 코드, 한컴오피스 표시값 (rhwp #1105)
|
|
223
128
|
};
|
|
224
129
|
function mapPuaChar(code) {
|
|
225
130
|
if (code >= 61472 && code <= 61695) {
|
|
@@ -234,7 +139,7 @@ function mapPuaText(text) {
|
|
|
234
139
|
let out = "";
|
|
235
140
|
for (const ch of text) {
|
|
236
141
|
const code = ch.codePointAt(0);
|
|
237
|
-
out +=
|
|
142
|
+
out += mapPuaChar(code) ?? ch;
|
|
238
143
|
}
|
|
239
144
|
return out;
|
|
240
145
|
}
|
|
@@ -242,11 +147,11 @@ function mapPuaText(text) {
|
|
|
242
147
|
// src/table/builder.ts
|
|
243
148
|
var MAX_COLS = 200;
|
|
244
149
|
var MAX_ROWS = 1e4;
|
|
245
|
-
function buildTable(rows) {
|
|
150
|
+
function buildTable(rows, options) {
|
|
246
151
|
if (rows.length > MAX_ROWS) rows = rows.slice(0, MAX_ROWS);
|
|
247
152
|
const numRows = rows.length;
|
|
248
153
|
const hasAddr = rows.some((row) => row.some((c) => c.colAddr !== void 0 && c.rowAddr !== void 0));
|
|
249
|
-
if (hasAddr) return buildTableDirect(rows, numRows);
|
|
154
|
+
if (hasAddr) return buildTableDirect(rows, numRows, options);
|
|
250
155
|
let maxCols = 0;
|
|
251
156
|
const tempOccupied = Array.from({ length: numRows }, () => []);
|
|
252
157
|
for (let rowIdx = 0; rowIdx < numRows; rowIdx++) {
|
|
@@ -269,6 +174,7 @@ function buildTable(rows) {
|
|
|
269
174
|
() => Array.from({ length: maxCols }, () => ({ text: "", colSpan: 1, rowSpan: 1 }))
|
|
270
175
|
);
|
|
271
176
|
const occupied = Array.from({ length: numRows }, () => Array(maxCols).fill(false));
|
|
177
|
+
const anchorCols = /* @__PURE__ */ new Set();
|
|
272
178
|
for (let rowIdx = 0; rowIdx < numRows; rowIdx++) {
|
|
273
179
|
let colIdx = 0;
|
|
274
180
|
let cellIdx = 0;
|
|
@@ -276,6 +182,7 @@ function buildTable(rows) {
|
|
|
276
182
|
while (colIdx < maxCols && occupied[rowIdx][colIdx]) colIdx++;
|
|
277
183
|
if (colIdx >= maxCols) break;
|
|
278
184
|
const cell = rows[rowIdx][cellIdx];
|
|
185
|
+
anchorCols.add(colIdx);
|
|
279
186
|
grid[rowIdx][colIdx] = {
|
|
280
187
|
text: cell.text.trim(),
|
|
281
188
|
colSpan: cell.colSpan,
|
|
@@ -290,13 +197,13 @@ function buildTable(rows) {
|
|
|
290
197
|
cellIdx++;
|
|
291
198
|
}
|
|
292
199
|
}
|
|
293
|
-
return trimAndReturn(grid, numRows, maxCols);
|
|
200
|
+
return trimAndReturn(grid, numRows, maxCols, anchorCols, options);
|
|
294
201
|
}
|
|
295
|
-
function buildTableDirect(rows, numRows) {
|
|
202
|
+
function buildTableDirect(rows, numRows, options) {
|
|
296
203
|
let maxCols = 0;
|
|
297
204
|
for (const row of rows) {
|
|
298
205
|
for (const cell of row) {
|
|
299
|
-
const end = (
|
|
206
|
+
const end = (cell.colAddr ?? 0) + cell.colSpan;
|
|
300
207
|
if (end > maxCols) maxCols = end;
|
|
301
208
|
}
|
|
302
209
|
}
|
|
@@ -306,11 +213,13 @@ function buildTableDirect(rows, numRows) {
|
|
|
306
213
|
{ length: numRows },
|
|
307
214
|
() => Array.from({ length: maxCols }, () => ({ text: "", colSpan: 1, rowSpan: 1 }))
|
|
308
215
|
);
|
|
216
|
+
const anchorCols = /* @__PURE__ */ new Set();
|
|
309
217
|
for (const row of rows) {
|
|
310
218
|
for (const cell of row) {
|
|
311
|
-
const r =
|
|
312
|
-
const c =
|
|
219
|
+
const r = cell.rowAddr ?? 0;
|
|
220
|
+
const c = cell.colAddr ?? 0;
|
|
313
221
|
if (r >= numRows || c >= maxCols || r < 0 || c < 0) continue;
|
|
222
|
+
anchorCols.add(c);
|
|
314
223
|
grid[r][c] = { text: cell.text.trim(), colSpan: cell.colSpan, rowSpan: cell.rowSpan };
|
|
315
224
|
for (let dr = 0; dr < cell.rowSpan; dr++) {
|
|
316
225
|
for (let dc = 0; dc < cell.colSpan; dc++) {
|
|
@@ -322,13 +231,14 @@ function buildTableDirect(rows, numRows) {
|
|
|
322
231
|
}
|
|
323
232
|
}
|
|
324
233
|
}
|
|
325
|
-
return trimAndReturn(grid, numRows, maxCols);
|
|
234
|
+
return trimAndReturn(grid, numRows, maxCols, anchorCols, options);
|
|
326
235
|
}
|
|
327
|
-
function trimAndReturn(grid, numRows, maxCols) {
|
|
236
|
+
function trimAndReturn(grid, numRows, maxCols, anchorCols, options) {
|
|
328
237
|
let effectiveCols = maxCols;
|
|
329
238
|
while (effectiveCols > 0) {
|
|
330
|
-
const colEmpty = grid.every((row) => !
|
|
239
|
+
const colEmpty = grid.every((row) => !row[effectiveCols - 1]?.text?.trim());
|
|
331
240
|
if (!colEmpty) break;
|
|
241
|
+
if (options?.keepAnchoredEmptyCols && anchorCols.has(effectiveCols - 1)) break;
|
|
332
242
|
effectiveCols--;
|
|
333
243
|
}
|
|
334
244
|
if (effectiveCols < maxCols && effectiveCols > 0) {
|
|
@@ -345,14 +255,14 @@ function convertTableToText(rows) {
|
|
|
345
255
|
function escapeGfm(text) {
|
|
346
256
|
const NUL = String.fromCharCode(0);
|
|
347
257
|
const spans = [];
|
|
348
|
-
const masked = text.replace(
|
|
258
|
+
const masked = text.replace(/!\[[^\]]*\]\([^)\n]*\)|\]\((?:https?:|mailto:|tel:|#)[^)\n]*\)|\$\$[^$]*\$\$|\$[^$\n]*\$/gi, (m) => {
|
|
349
259
|
spans.push(m);
|
|
350
260
|
return NUL + (spans.length - 1) + NUL;
|
|
351
261
|
});
|
|
352
|
-
const escaped = masked.replace(/([~*])/g, "\\$1");
|
|
262
|
+
const escaped = masked.replace(/([~*_`])/g, "\\$1");
|
|
353
263
|
return escaped.replace(new RegExp(NUL + "(\\d+)" + NUL, "g"), (_, n) => spans[Number(n)]);
|
|
354
264
|
}
|
|
355
|
-
var HWP_SHAPE_ALT_TEXT_RE =
|
|
265
|
+
var HWP_SHAPE_ALT_TEXT_RE = /^(?:모서리가 둥근 |둥근 )?(?:사각형|직사각형|정사각형|원|타원|삼각형|이등변 삼각형|직각 삼각형|선|직선|곡선|화살표|굵은 화살표|이중 화살표|오각형|육각형|팔각형|별|[4-8]점별|십자|십자형|구름|구름형|마름모|도넛|평행사변형|사다리꼴|부채꼴|호|반원|물결|번개|하트|빗금|블록 화살표|수식|표|그림|개체|그리기\s?개체|묶음\s?개체|글상자|수식\s?개체|OLE\s?개체)\s?입니다\.?$/gm;
|
|
356
266
|
function sanitizeText(text) {
|
|
357
267
|
let result = mapPuaText(text).replace(/[\u{F0000}-\u{FFFFD}]/gu, "").replace(HWP_SHAPE_ALT_TEXT_RE, "").replace(/ +/g, " ").trim();
|
|
358
268
|
if (result.length <= 30 && result.includes(" ")) {
|
|
@@ -381,7 +291,7 @@ function flattenLayoutTables(blocks) {
|
|
|
381
291
|
let totalTextLen = 0;
|
|
382
292
|
for (let r = 0; r < numRows; r++) {
|
|
383
293
|
for (let c = 0; c < numCols; c++) {
|
|
384
|
-
const t =
|
|
294
|
+
const t = cells[r]?.[c]?.text || "";
|
|
385
295
|
totalNewlines += (t.match(/\n/g) || []).length;
|
|
386
296
|
totalTextLen += t.length;
|
|
387
297
|
}
|
|
@@ -389,13 +299,13 @@ function flattenLayoutTables(blocks) {
|
|
|
389
299
|
if (numCols < 4 && (totalNewlines > 5 || numRows <= 2 && totalTextLen > 300)) {
|
|
390
300
|
for (let r = 0; r < numRows; r++) {
|
|
391
301
|
for (let c = 0; c < numCols; c++) {
|
|
392
|
-
const cell =
|
|
302
|
+
const cell = cells[r]?.[c];
|
|
393
303
|
if (!cell) continue;
|
|
394
|
-
if (
|
|
304
|
+
if (cell.blocks?.length) {
|
|
395
305
|
result.push(...flattenLayoutTables(cell.blocks));
|
|
396
306
|
continue;
|
|
397
307
|
}
|
|
398
|
-
const cellText =
|
|
308
|
+
const cellText = cell.text?.trim();
|
|
399
309
|
if (!cellText) continue;
|
|
400
310
|
for (const line of cellText.split("\n")) {
|
|
401
311
|
const trimmed = line.trim();
|
|
@@ -415,7 +325,7 @@ var RUNNING_HEADER_MAX_LEN = 40;
|
|
|
415
325
|
var RUNNING_HEADER_MIN_FREQ = 3;
|
|
416
326
|
function isRunningHeaderCandidate(block) {
|
|
417
327
|
if (block.type !== "paragraph" && block.type !== "heading") return false;
|
|
418
|
-
const text =
|
|
328
|
+
const text = block.text?.trim();
|
|
419
329
|
if (!text || text.length > RUNNING_HEADER_MAX_LEN) return false;
|
|
420
330
|
return /^\d+\.\s/.test(text);
|
|
421
331
|
}
|
|
@@ -424,14 +334,14 @@ function dedupeRunningHeaders(blocks) {
|
|
|
424
334
|
for (const block of blocks) {
|
|
425
335
|
if (!isRunningHeaderCandidate(block)) continue;
|
|
426
336
|
const text = block.text.trim();
|
|
427
|
-
freq.set(text, (
|
|
337
|
+
freq.set(text, (freq.get(text) ?? 0) + 1);
|
|
428
338
|
}
|
|
429
339
|
const seen = /* @__PURE__ */ new Set();
|
|
430
340
|
const result = [];
|
|
431
341
|
for (const block of blocks) {
|
|
432
342
|
if (isRunningHeaderCandidate(block)) {
|
|
433
343
|
const text = block.text.trim();
|
|
434
|
-
if ((
|
|
344
|
+
if ((freq.get(text) ?? 0) >= RUNNING_HEADER_MIN_FREQ) {
|
|
435
345
|
if (seen.has(text)) continue;
|
|
436
346
|
seen.add(text);
|
|
437
347
|
}
|
|
@@ -496,7 +406,7 @@ function blocksToMarkdown(blocks) {
|
|
|
496
406
|
if (!text) continue;
|
|
497
407
|
if (/^\[별표\s*\d+/.test(text)) {
|
|
498
408
|
const nextBlock = blocks[i + 1];
|
|
499
|
-
if (
|
|
409
|
+
if (nextBlock?.type === "paragraph" && nextBlock.text && /관련\)?$/.test(nextBlock.text)) {
|
|
500
410
|
lines.push("", `## ${escapeGfm(text)} ${escapeGfm(nextBlock.text)}`, "");
|
|
501
411
|
i++;
|
|
502
412
|
} else {
|
|
@@ -509,7 +419,7 @@ function blocksToMarkdown(blocks) {
|
|
|
509
419
|
continue;
|
|
510
420
|
}
|
|
511
421
|
const listIndent = block.listDepth ? " ".repeat(block.listDepth) : "";
|
|
512
|
-
if (
|
|
422
|
+
if (block.spans?.length) {
|
|
513
423
|
let rendered = spansToMarkdown(block.spans);
|
|
514
424
|
if (block.href) {
|
|
515
425
|
const href = sanitizeHref(block.href);
|
|
@@ -555,27 +465,27 @@ function hasMergedCells(table) {
|
|
|
555
465
|
function hasNestedTables(table) {
|
|
556
466
|
for (const row of table.cells) {
|
|
557
467
|
for (const cell of row) {
|
|
558
|
-
if (
|
|
468
|
+
if (cell.blocks?.some((b) => b.type === "table" && b.table)) return true;
|
|
559
469
|
}
|
|
560
470
|
}
|
|
561
471
|
return false;
|
|
562
472
|
}
|
|
563
473
|
function cellInnerHtml(cell) {
|
|
564
|
-
if (
|
|
474
|
+
if (cell.blocks?.length) {
|
|
565
475
|
return cell.blocks.map((b) => {
|
|
566
476
|
if (b.type === "table" && b.table) {
|
|
567
477
|
const cap = b.table.caption ? sanitizeText(b.table.caption) : "";
|
|
568
478
|
return (cap ? cap + "<br>" : "") + tableToHtml(b.table);
|
|
569
479
|
}
|
|
570
480
|
if (b.type === "image" && b.text) return `<img src="${b.text}" alt="image">`;
|
|
571
|
-
const t = sanitizeText(
|
|
481
|
+
const t = sanitizeText(b.text ?? "");
|
|
572
482
|
return t ? t.replace(/\n/g, "<br>") : "";
|
|
573
483
|
}).filter(Boolean).join("<br>");
|
|
574
484
|
}
|
|
575
485
|
return sanitizeText(cell.text).replace(/\n/g, "<br>");
|
|
576
486
|
}
|
|
577
487
|
function containsInlineMath(text) {
|
|
578
|
-
return /(^|[^\\])\$(?=\S)(
|
|
488
|
+
return /(^|[^\\])\$(?=\S)(?:[^$\n\\]|\\.)+?\S\$/.test(text);
|
|
579
489
|
}
|
|
580
490
|
function tableContainsInlineMath(table) {
|
|
581
491
|
for (const row of table.cells) {
|
|
@@ -594,7 +504,7 @@ function tableToHtml(table) {
|
|
|
594
504
|
const rowHtml = [];
|
|
595
505
|
for (let c = 0; c < numCols; c++) {
|
|
596
506
|
if (skip.has(`${r},${c}`)) continue;
|
|
597
|
-
const cell =
|
|
507
|
+
const cell = cells[r]?.[c];
|
|
598
508
|
if (!cell) continue;
|
|
599
509
|
for (let dr = 0; dr < cell.rowSpan; dr++) {
|
|
600
510
|
for (let dc = 0; dc < cell.colSpan; dc++) {
|
|
@@ -639,9 +549,9 @@ function tableToMarkdown(table) {
|
|
|
639
549
|
for (let r = 0; r < numRows; r++) {
|
|
640
550
|
for (let c = 0; c < numCols; c++) {
|
|
641
551
|
if (skip.has(`${r},${c}`)) continue;
|
|
642
|
-
const cell =
|
|
552
|
+
const cell = cells[r]?.[c];
|
|
643
553
|
if (!cell) continue;
|
|
644
|
-
display[r][c] = (
|
|
554
|
+
display[r][c] = (cell.blocks?.some((b) => b.spans) ? cell.blocks.map((b) => b.type === "image" && b.text ? `` : b.spans ? spansToMarkdown(b.spans) : escapeGfm(sanitizeText(b.text ?? ""))).filter(Boolean).join("<br>") : escapeGfm(sanitizeText(cell.text)).replace(/\n/g, "<br>")).replace(/\|/g, "\\|");
|
|
645
555
|
for (let dr = 0; dr < cell.rowSpan; dr++) {
|
|
646
556
|
for (let dc = 0; dc < cell.colSpan; dc++) {
|
|
647
557
|
if (dr === 0 && dc === 0) continue;
|
|
@@ -657,8 +567,15 @@ function tableToMarkdown(table) {
|
|
|
657
567
|
let pendingLabelRow = null;
|
|
658
568
|
for (let r = 0; r < display.length; r++) {
|
|
659
569
|
const row = display[r];
|
|
660
|
-
|
|
661
|
-
|
|
570
|
+
if (row.every((cell) => cell === "")) {
|
|
571
|
+
if (row.some((_, c) => skip.has(`${r},${c}`))) continue;
|
|
572
|
+
if (pendingLabelRow) {
|
|
573
|
+
uniqueRows.push(pendingLabelRow);
|
|
574
|
+
pendingLabelRow = null;
|
|
575
|
+
}
|
|
576
|
+
uniqueRows.push(row);
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
662
579
|
const nonEmptyCols = row.filter((cell) => cell !== "");
|
|
663
580
|
const hasSkipInRow = row.some((_, c) => skip.has(`${r},${c}`));
|
|
664
581
|
if (!hasSkipInRow && nonEmptyCols.length === 1 && row[0] !== "" && row.slice(1).every((c) => c === "")) {
|
|
@@ -684,173 +601,14 @@ function tableToMarkdown(table) {
|
|
|
684
601
|
return md.join("\n");
|
|
685
602
|
}
|
|
686
603
|
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
for (let k = 0; k < 8; k++) {
|
|
699
|
-
c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
700
|
-
}
|
|
701
|
-
table[n] = c >>> 0;
|
|
702
|
-
}
|
|
703
|
-
return table;
|
|
704
|
-
})();
|
|
705
|
-
function crc32(bytes) {
|
|
706
|
-
let c = 4294967295;
|
|
707
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
708
|
-
c = CRC_TABLE[(c ^ bytes[i]) & 255] ^ c >>> 8;
|
|
709
|
-
}
|
|
710
|
-
return (c ^ 4294967295) >>> 0;
|
|
711
|
-
}
|
|
712
|
-
var BI_RGB = 0;
|
|
713
|
-
var MAX_DIM = 32767;
|
|
714
|
-
var MAX_PIXELS = 36e6;
|
|
715
|
-
function bmpToPng(bmp) {
|
|
716
|
-
if (bmp.length < 54) return null;
|
|
717
|
-
if (bmp[0] !== 66 || bmp[1] !== 77) return null;
|
|
718
|
-
const dv = new DataView(bmp.buffer, bmp.byteOffset, bmp.byteLength);
|
|
719
|
-
const dataOffset = dv.getUint32(10, true);
|
|
720
|
-
const headerSize = dv.getUint32(14, true);
|
|
721
|
-
if (headerSize < 40) return null;
|
|
722
|
-
const width = dv.getInt32(18, true);
|
|
723
|
-
const rawHeight = dv.getInt32(22, true);
|
|
724
|
-
const bitCount = dv.getUint16(28, true);
|
|
725
|
-
const compression = dv.getUint32(30, true);
|
|
726
|
-
if (compression !== BI_RGB) return null;
|
|
727
|
-
if (bitCount !== 24 && bitCount !== 32) return null;
|
|
728
|
-
if (width <= 0 || rawHeight === 0) return null;
|
|
729
|
-
if (width > MAX_DIM || Math.abs(rawHeight) > MAX_DIM) return null;
|
|
730
|
-
const topDown = rawHeight < 0;
|
|
731
|
-
const height = Math.abs(rawHeight);
|
|
732
|
-
if (width * height > MAX_PIXELS) return null;
|
|
733
|
-
const bytesPerPixel = bitCount >> 3;
|
|
734
|
-
const rowStride = width * bytesPerPixel + 3 & ~3;
|
|
735
|
-
if (dataOffset + rowStride * height > bmp.length) return null;
|
|
736
|
-
const rgba = new Uint8Array(width * height * 4);
|
|
737
|
-
let anyAlpha = 0;
|
|
738
|
-
for (let y = 0; y < height; y++) {
|
|
739
|
-
const srcRow = topDown ? y : height - 1 - y;
|
|
740
|
-
let src = dataOffset + srcRow * rowStride;
|
|
741
|
-
let dst = y * width * 4;
|
|
742
|
-
for (let x = 0; x < width; x++) {
|
|
743
|
-
rgba[dst] = bmp[src + 2];
|
|
744
|
-
rgba[dst + 1] = bmp[src + 1];
|
|
745
|
-
rgba[dst + 2] = bmp[src];
|
|
746
|
-
const a = bitCount === 32 ? bmp[src + 3] : 255;
|
|
747
|
-
rgba[dst + 3] = a;
|
|
748
|
-
anyAlpha |= a;
|
|
749
|
-
src += bytesPerPixel;
|
|
750
|
-
dst += 4;
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
if (bitCount === 32 && anyAlpha === 0) {
|
|
754
|
-
for (let i = 3; i < rgba.length; i += 4) rgba[i] = 255;
|
|
755
|
-
}
|
|
756
|
-
return encodePng(width, height, rgba);
|
|
757
|
-
}
|
|
758
|
-
var PNG_SIGNATURE = Uint8Array.of(137, 80, 78, 71, 13, 10, 26, 10);
|
|
759
|
-
function chunk(type, data) {
|
|
760
|
-
const body = new Uint8Array(4 + data.length);
|
|
761
|
-
body[0] = type.charCodeAt(0);
|
|
762
|
-
body[1] = type.charCodeAt(1);
|
|
763
|
-
body[2] = type.charCodeAt(2);
|
|
764
|
-
body[3] = type.charCodeAt(3);
|
|
765
|
-
body.set(data, 4);
|
|
766
|
-
const out = new Uint8Array(8 + data.length + 4);
|
|
767
|
-
const dv = new DataView(out.buffer);
|
|
768
|
-
dv.setUint32(0, data.length, false);
|
|
769
|
-
out.set(body, 4);
|
|
770
|
-
dv.setUint32(8 + data.length, crc32(body), false);
|
|
771
|
-
return out;
|
|
772
|
-
}
|
|
773
|
-
function encodePng(width, height, rgba) {
|
|
774
|
-
const ihdr = new Uint8Array(13);
|
|
775
|
-
const iv = new DataView(ihdr.buffer);
|
|
776
|
-
iv.setUint32(0, width, false);
|
|
777
|
-
iv.setUint32(4, height, false);
|
|
778
|
-
ihdr[8] = 8;
|
|
779
|
-
ihdr[9] = 6;
|
|
780
|
-
const stride = width * 4;
|
|
781
|
-
const raw = new Uint8Array((stride + 1) * height);
|
|
782
|
-
for (let y = 0; y < height; y++) {
|
|
783
|
-
const rowStart = y * (stride + 1);
|
|
784
|
-
raw[rowStart] = 0;
|
|
785
|
-
raw.set(rgba.subarray(y * stride, y * stride + stride), rowStart + 1);
|
|
786
|
-
}
|
|
787
|
-
const idat = _zlib.deflateSync.call(void 0, raw);
|
|
788
|
-
const ihdrChunk = chunk("IHDR", ihdr);
|
|
789
|
-
const idatChunk = chunk("IDAT", idat);
|
|
790
|
-
const iendChunk = chunk("IEND", new Uint8Array(0));
|
|
791
|
-
const out = new Uint8Array(PNG_SIGNATURE.length + ihdrChunk.length + idatChunk.length + iendChunk.length);
|
|
792
|
-
let o = 0;
|
|
793
|
-
out.set(PNG_SIGNATURE, o);
|
|
794
|
-
o += PNG_SIGNATURE.length;
|
|
795
|
-
out.set(ihdrChunk, o);
|
|
796
|
-
o += ihdrChunk.length;
|
|
797
|
-
out.set(idatChunk, o);
|
|
798
|
-
o += idatChunk.length;
|
|
799
|
-
out.set(iendChunk, o);
|
|
800
|
-
return out;
|
|
801
|
-
}
|
|
802
|
-
function escapeRegExp(s) {
|
|
803
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
804
|
-
}
|
|
805
|
-
function inlineImagesIntoMarkdown(markdown, images, opts) {
|
|
806
|
-
const compress = _optionalChain([opts, 'optionalAccess', _40 => _40.compress]) !== false;
|
|
807
|
-
let out = markdown;
|
|
808
|
-
for (const img of images) {
|
|
809
|
-
let bytes = img.data;
|
|
810
|
-
let mime = img.mimeType;
|
|
811
|
-
if (compress && mime === "image/bmp") {
|
|
812
|
-
const png = bmpToPng(img.data);
|
|
813
|
-
if (png) {
|
|
814
|
-
bytes = png;
|
|
815
|
-
mime = "image/png";
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
const base64 = Buffer.from(bytes).toString("base64");
|
|
819
|
-
const dataUri = `data:${mime};base64,${base64}`;
|
|
820
|
-
const name = escapeRegExp(img.filename);
|
|
821
|
-
const mdRe = new RegExp(`!\\[image\\]\\((?:images/)?${name}\\)`, "g");
|
|
822
|
-
out = out.replace(mdRe, () => ``);
|
|
823
|
-
const imgTagRe = new RegExp(`(<img\\b[^>]*\\bsrc=")(?:images/)?${name}(")`, "g");
|
|
824
|
-
out = out.replace(imgTagRe, (_m, pre, post) => `${pre}${dataUri}${post}`);
|
|
825
|
-
}
|
|
826
|
-
return out;
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
exports.VERSION = VERSION; exports.toArrayBuffer = toArrayBuffer; exports.KordocError = KordocError; exports.isPathTraversal = isPathTraversal; exports.normalizeSectionHref = normalizeSectionHref; exports.compareSectionPaths = compareSectionPaths; exports.precheckZipSize = precheckZipSize; exports.stripDtd = stripDtd; exports.sanitizeHref = sanitizeHref; exports.safeMin = safeMin; exports.safeMax = safeMax; exports.classifyError = classifyError; exports.mapPuaText = mapPuaText; exports.MAX_COLS = MAX_COLS; exports.MAX_ROWS = MAX_ROWS; exports.buildTable = buildTable; exports.convertTableToText = convertTableToText; exports.flattenLayoutTables = flattenLayoutTables; exports.dedupeRunningHeaders = dedupeRunningHeaders; exports.blocksToMarkdown = blocksToMarkdown; exports.HEADING_RATIO_H1 = HEADING_RATIO_H1; exports.HEADING_RATIO_H2 = HEADING_RATIO_H2; exports.HEADING_RATIO_H3 = HEADING_RATIO_H3; exports.encodePng = encodePng; exports.inlineImagesIntoMarkdown = inlineImagesIntoMarkdown;
|
|
856
|
-
//# sourceMappingURL=chunk-6XAAYAWL.cjs.map
|
|
604
|
+
export {
|
|
605
|
+
mapPuaText,
|
|
606
|
+
MAX_COLS,
|
|
607
|
+
MAX_ROWS,
|
|
608
|
+
buildTable,
|
|
609
|
+
convertTableToText,
|
|
610
|
+
flattenLayoutTables,
|
|
611
|
+
dedupeRunningHeaders,
|
|
612
|
+
blocksToMarkdown
|
|
613
|
+
};
|
|
614
|
+
//# sourceMappingURL=chunk-CMN3SYZ3.js.map
|