kordoc 3.8.4 → 3.9.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 +12 -0
- package/dist/{-ZAIG6FWT.js → -6CLKMLK2.js} +3 -3
- package/dist/{chunk-T4SGNVVS.js → chunk-EZ5GBTBE.js} +2 -2
- package/dist/{chunk-6EDNKPXQ.js → chunk-ITPZD7XK.js} +344 -5
- package/dist/chunk-ITPZD7XK.js.map +1 -0
- package/dist/{chunk-Z3O36LBJ.cjs → chunk-VHXUD3PW.cjs} +2 -2
- package/dist/{chunk-Z3O36LBJ.cjs.map → chunk-VHXUD3PW.cjs.map} +1 -1
- package/dist/{chunk-2UDAEQPW.js → chunk-XKDA4FDM.js} +2 -2
- package/dist/cli.js +4 -4
- package/dist/index.cjs +454 -115
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +343 -4
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +3 -3
- package/dist/{parser-PR7CPMM4.js → parser-LVI45MVF.js} +2 -2
- package/dist/{parser-ZVKCFXR3.cjs → parser-N4G5KQBE.cjs} +14 -14
- package/dist/{parser-ZVKCFXR3.cjs.map → parser-N4G5KQBE.cjs.map} +1 -1
- package/dist/{parser-2THIF623.js → parser-NCNME2Z6.js} +2 -2
- package/dist/{watch-2HYPNMOB.js → watch-XSLV62BH.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-6EDNKPXQ.js.map +0 -1
- /package/dist/{-ZAIG6FWT.js.map → -6CLKMLK2.js.map} +0 -0
- /package/dist/{chunk-T4SGNVVS.js.map → chunk-EZ5GBTBE.js.map} +0 -0
- /package/dist/{chunk-2UDAEQPW.js.map → chunk-XKDA4FDM.js.map} +0 -0
- /package/dist/{parser-PR7CPMM4.js.map → parser-LVI45MVF.js.map} +0 -0
- /package/dist/{parser-2THIF623.js.map → parser-NCNME2Z6.js.map} +0 -0
- /package/dist/{watch-2HYPNMOB.js.map → watch-XSLV62BH.js.map} +0 -0
package/README.md
CHANGED
|
@@ -68,6 +68,13 @@ Windows 도 자동으로 `cmd /c npx` 래핑. 수동 JSON 편집 불필요. 재
|
|
|
68
68
|
|
|
69
69
|
---
|
|
70
70
|
|
|
71
|
+
## v3.9.0 변경사항
|
|
72
|
+
|
|
73
|
+
- **🧮 Markdown 수식 → HWPX native 수식 생성**: `$$ \frac{a}{b} $$` 같은 display math 블록이 한컴 수식 개체(`<hp:equation>`)로 생성됩니다. `\frac`·`\sqrt`·첨자·그리스 문자·적분/극한·행렬(matrix/pmatrix/bmatrix)·`\left(` 구분자·`\text` 리터럴 지원. 생성한 수식은 kordoc으로 다시 파싱해도 같은 LaTeX로 돌아옵니다 (#38, @leehuiso 기여).
|
|
74
|
+
- **🛡️ 수식 입력 가드**: 닫히지 않은 `$$`가 문서 전체를 삼키던 문제(일반 문단 폴백), 중괄호 폭탄 크래시(깊이/길이 상한), 닫는 `$$` 뒤 텍스트 소실을 수정했습니다.
|
|
75
|
+
- **📋 공문 모드 번호 연속**: 항목 사이에 수식이 끼어도 항목 번호가 이어집니다 (표와 동일).
|
|
76
|
+
- **⚖️ 법령 문서 왕복 무결성 게이트**: 조문 번호 뒤 분리·문장 중간 끊김이 없음을 실측(민원처리법 전문 228문단)하고 벤치 게이트로 고정했습니다.
|
|
77
|
+
|
|
71
78
|
## v3.8.4 변경사항
|
|
72
79
|
|
|
73
80
|
- **📑 DOCX 병합표·텍스트박스 복구**: 병합표에서 셀이 통째로 빠지던 버그(세로 병합 미동작 포함)와 텍스트박스 내용 전체 유실을 수정 — 신고서류·KS표준안류 회수율 0.67/0.92 → **1.0/0.998**.
|
|
@@ -439,6 +446,11 @@ import { markdownToHwpx } from "kordoc"
|
|
|
439
446
|
const hwpxBuffer = await markdownToHwpx("# 제목\n\n본문 텍스트\n\n| 이름 | 직급 |\n| --- | --- |\n| 홍길동 | 과장 |")
|
|
440
447
|
writeFileSync("출력.hwpx", Buffer.from(hwpxBuffer))
|
|
441
448
|
|
|
449
|
+
// display math block은 HWPX native 수식(<hp:equation>)으로 생성됩니다.
|
|
450
|
+
// 초기 지원 범위는 \frac, \sqrt, 첨자/위첨자, Greek, 적분/극한,
|
|
451
|
+
// 화살표, 관계 연산자, matrix 계열의 제한된 LaTeX-like subset입니다.
|
|
452
|
+
const withEquation = await markdownToHwpx("피타고라스\n\n$$a^2 + b^2 = c^2$$")
|
|
453
|
+
|
|
442
454
|
// 공문서 모드 — 항목부호 8단계 + 내어쓰기 + 공식 여백/명조 자동
|
|
443
455
|
const gongmun = await markdownToHwpx("1. 추진배경\n - 세부 항목\n2. 추진계획", {
|
|
444
456
|
gongmun: { preset: "보고서" }, // official | report | plan | notice | minutes
|
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
scanSectionXml,
|
|
42
42
|
simulateWrap,
|
|
43
43
|
simulateWrapKeepWord
|
|
44
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-ITPZD7XK.js";
|
|
45
45
|
import {
|
|
46
46
|
detectFormat,
|
|
47
47
|
detectOle2Format,
|
|
@@ -54,7 +54,7 @@ import {
|
|
|
54
54
|
import {
|
|
55
55
|
VERSION,
|
|
56
56
|
blocksToMarkdown
|
|
57
|
-
} from "./chunk-
|
|
57
|
+
} from "./chunk-XKDA4FDM.js";
|
|
58
58
|
import "./chunk-MOL7MDBG.js";
|
|
59
59
|
export {
|
|
60
60
|
HwpxSession,
|
|
@@ -108,4 +108,4 @@ export {
|
|
|
108
108
|
simulateWrap,
|
|
109
109
|
simulateWrapKeepWord
|
|
110
110
|
};
|
|
111
|
-
//# sourceMappingURL=-
|
|
111
|
+
//# sourceMappingURL=-6CLKMLK2.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/utils.ts
|
|
2
|
-
var VERSION = true ? "3.
|
|
2
|
+
var VERSION = true ? "3.9.0" : "0.0.0-dev";
|
|
3
3
|
function toArrayBuffer(buf) {
|
|
4
4
|
if (buf.byteOffset === 0 && buf.byteLength === buf.buffer.byteLength) {
|
|
5
5
|
return buf.buffer;
|
|
@@ -641,4 +641,4 @@ export {
|
|
|
641
641
|
HEADING_RATIO_H2,
|
|
642
642
|
HEADING_RATIO_H3
|
|
643
643
|
};
|
|
644
|
-
//# sourceMappingURL=chunk-
|
|
644
|
+
//# sourceMappingURL=chunk-EZ5GBTBE.js.map
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
sanitizeHref,
|
|
26
26
|
stripDtd,
|
|
27
27
|
toArrayBuffer
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-XKDA4FDM.js";
|
|
29
29
|
import {
|
|
30
30
|
parsePageRange
|
|
31
31
|
} from "./chunk-MOL7MDBG.js";
|
|
@@ -419,8 +419,10 @@ var CONVERT_MAP = {
|
|
|
419
419
|
SUCC: "\\succ",
|
|
420
420
|
UPLUS: "\\uplus",
|
|
421
421
|
"\xB1": "\\pm",
|
|
422
|
+
"+-": "\\pm",
|
|
422
423
|
"-+": "\\mp",
|
|
423
424
|
"\xF7": "\\div",
|
|
425
|
+
cdot: "\\cdot",
|
|
424
426
|
CIRC: "\\circ",
|
|
425
427
|
BULLET: "\\bullet",
|
|
426
428
|
DEG: " ^\\circ",
|
|
@@ -809,6 +811,10 @@ function hmlToLatex(hmlEqStr) {
|
|
|
809
811
|
const t = tokens[i];
|
|
810
812
|
if (t in CONVERT_MAP) tokens[i] = CONVERT_MAP[t];
|
|
811
813
|
else if (t in MIDDLE_CONVERT_MAP) tokens[i] = MIDDLE_CONVERT_MAP[t];
|
|
814
|
+
else {
|
|
815
|
+
const quoted = /^"(.+)"$/.exec(t);
|
|
816
|
+
if (quoted) tokens[i] = `\\text{${quoted[1]}}`;
|
|
817
|
+
}
|
|
812
818
|
}
|
|
813
819
|
tokens = tokens.filter((tok) => tok.length !== 0);
|
|
814
820
|
tokens = replaceBracket(tokens);
|
|
@@ -20552,6 +20558,16 @@ function buildPrvText(blocks) {
|
|
|
20552
20558
|
}
|
|
20553
20559
|
return lines.join("\n").slice(0, 1024);
|
|
20554
20560
|
}
|
|
20561
|
+
function findMathDelim(s, from) {
|
|
20562
|
+
let i = s.indexOf("$$", from);
|
|
20563
|
+
while (i > 0) {
|
|
20564
|
+
let backslashes = 0;
|
|
20565
|
+
for (let j = i - 1; j >= 0 && s[j] === "\\"; j--) backslashes++;
|
|
20566
|
+
if (backslashes % 2 === 0) break;
|
|
20567
|
+
i = s.indexOf("$$", i + 1);
|
|
20568
|
+
}
|
|
20569
|
+
return i;
|
|
20570
|
+
}
|
|
20555
20571
|
function parseMarkdownToBlocks(md2) {
|
|
20556
20572
|
const lines = md2.split("\n");
|
|
20557
20573
|
const blocks = [];
|
|
@@ -20562,6 +20578,45 @@ function parseMarkdownToBlocks(md2) {
|
|
|
20562
20578
|
i++;
|
|
20563
20579
|
continue;
|
|
20564
20580
|
}
|
|
20581
|
+
const mathOpen = /^\s*\$\$/.exec(line);
|
|
20582
|
+
if (mathOpen) {
|
|
20583
|
+
const afterOpen = line.slice(mathOpen[0].length);
|
|
20584
|
+
const closeSame = findMathDelim(afterOpen, 0);
|
|
20585
|
+
if (closeSame >= 0) {
|
|
20586
|
+
const inner = afterOpen.slice(0, closeSame).trim();
|
|
20587
|
+
const trailing2 = afterOpen.slice(closeSame + 2).trim();
|
|
20588
|
+
if (inner) blocks.push({ type: "equation", text: inner });
|
|
20589
|
+
if (trailing2) blocks.push({ type: "paragraph", text: trailing2 });
|
|
20590
|
+
i++;
|
|
20591
|
+
continue;
|
|
20592
|
+
}
|
|
20593
|
+
const mathLines = [];
|
|
20594
|
+
if (afterOpen.trim()) mathLines.push(afterOpen);
|
|
20595
|
+
let closed = false;
|
|
20596
|
+
let trailing = "";
|
|
20597
|
+
let j = i + 1;
|
|
20598
|
+
for (; j < lines.length; j++) {
|
|
20599
|
+
const l = lines[j];
|
|
20600
|
+
if (!l.trim() || /^\s*(`{3,}|~{3,})/.test(l)) break;
|
|
20601
|
+
const end = findMathDelim(l, 0);
|
|
20602
|
+
if (end >= 0) {
|
|
20603
|
+
const before = l.slice(0, end);
|
|
20604
|
+
if (before.trim()) mathLines.push(before);
|
|
20605
|
+
trailing = l.slice(end + 2).trim();
|
|
20606
|
+
closed = true;
|
|
20607
|
+
j++;
|
|
20608
|
+
break;
|
|
20609
|
+
}
|
|
20610
|
+
mathLines.push(l);
|
|
20611
|
+
}
|
|
20612
|
+
if (closed) {
|
|
20613
|
+
const text = mathLines.join("\n").trim();
|
|
20614
|
+
if (text) blocks.push({ type: "equation", text });
|
|
20615
|
+
if (trailing) blocks.push({ type: "paragraph", text: trailing });
|
|
20616
|
+
i = j;
|
|
20617
|
+
continue;
|
|
20618
|
+
}
|
|
20619
|
+
}
|
|
20565
20620
|
const fenceMatch = line.match(/^(`{3,}|~{3,})(.*)$/);
|
|
20566
20621
|
if (fenceMatch) {
|
|
20567
20622
|
const fence = fenceMatch[1];
|
|
@@ -20954,6 +21009,7 @@ function precomputeGongmunList(blocks, gongmun) {
|
|
|
20954
21009
|
i++;
|
|
20955
21010
|
continue;
|
|
20956
21011
|
}
|
|
21012
|
+
const passThrough = (t) => t === "table" || t === "html_table" || t === "equation";
|
|
20957
21013
|
const run = [];
|
|
20958
21014
|
while (i < blocks.length) {
|
|
20959
21015
|
const t = blocks[i].type;
|
|
@@ -20962,9 +21018,9 @@ function precomputeGongmunList(blocks, gongmun) {
|
|
|
20962
21018
|
i++;
|
|
20963
21019
|
continue;
|
|
20964
21020
|
}
|
|
20965
|
-
if (t
|
|
21021
|
+
if (passThrough(t)) {
|
|
20966
21022
|
let j = i + 1;
|
|
20967
|
-
while (j < blocks.length && (blocks[j].type
|
|
21023
|
+
while (j < blocks.length && passThrough(blocks[j].type)) j++;
|
|
20968
21024
|
if (j < blocks.length && blocks[j].type === "list_item") {
|
|
20969
21025
|
i = j;
|
|
20970
21026
|
continue;
|
|
@@ -21490,6 +21546,280 @@ function generateHtmlTableXml(rawHtml, theme, totalWidth = 44e3) {
|
|
|
21490
21546
|
return `<hp:tbl id="${tblId}" zOrder="0" numberingType="TABLE" pageBreak="CELL" repeatHeader="0" rowCnt="${rowCnt}" colCnt="${colCnt}" cellSpacing="0" borderFillIDRef="2" noShading="0"><hp:sz width="${tblW}" widthRelTo="ABSOLUTE" height="${cellH * rowCnt}" heightRelTo="ABSOLUTE" protect="0"/><hp:pos treatAsChar="1" affectLSpacing="0" flowWithText="0" allowOverlap="0" holdAnchorAndSO="0" vertRelTo="PARA" horzRelTo="PARA" vertAlign="TOP" horzAlign="LEFT" vertOffset="0" horzOffset="0"/><hp:outMargin left="0" right="0" top="0" bottom="0"/><hp:inMargin left="510" right="510" top="141" bottom="141"/>` + trXmls.join("") + `</hp:tbl>`;
|
|
21491
21547
|
}
|
|
21492
21548
|
|
|
21549
|
+
// src/hwpx/equation-generate.ts
|
|
21550
|
+
var MAX_EQUATION_SOURCE = 1e4;
|
|
21551
|
+
var MAX_GROUP_DEPTH = 64;
|
|
21552
|
+
var COMMAND_MAP = {
|
|
21553
|
+
alpha: "alpha",
|
|
21554
|
+
beta: "beta",
|
|
21555
|
+
gamma: "gamma",
|
|
21556
|
+
delta: "delta",
|
|
21557
|
+
epsilon: "epsilon",
|
|
21558
|
+
zeta: "zeta",
|
|
21559
|
+
eta: "eta",
|
|
21560
|
+
theta: "theta",
|
|
21561
|
+
iota: "iota",
|
|
21562
|
+
kappa: "kappa",
|
|
21563
|
+
lambda: "lambda",
|
|
21564
|
+
mu: "mu",
|
|
21565
|
+
nu: "nu",
|
|
21566
|
+
xi: "xi",
|
|
21567
|
+
pi: "pi",
|
|
21568
|
+
rho: "rho",
|
|
21569
|
+
sigma: "sigma",
|
|
21570
|
+
tau: "tau",
|
|
21571
|
+
upsilon: "upsilon",
|
|
21572
|
+
phi: "phi",
|
|
21573
|
+
chi: "chi",
|
|
21574
|
+
psi: "psi",
|
|
21575
|
+
omega: "omega",
|
|
21576
|
+
Gamma: "GAMMA",
|
|
21577
|
+
Delta: "DELTA",
|
|
21578
|
+
Theta: "THETA",
|
|
21579
|
+
Lambda: "LAMBDA",
|
|
21580
|
+
Xi: "XI",
|
|
21581
|
+
Pi: "PI",
|
|
21582
|
+
Sigma: "SIGMA",
|
|
21583
|
+
Upsilon: "UPSILON",
|
|
21584
|
+
Phi: "PHI",
|
|
21585
|
+
Psi: "PSI",
|
|
21586
|
+
Omega: "OMEGA",
|
|
21587
|
+
le: "LEQ",
|
|
21588
|
+
leq: "LEQ",
|
|
21589
|
+
ge: "GEQ",
|
|
21590
|
+
geq: "GEQ",
|
|
21591
|
+
ne: "!=",
|
|
21592
|
+
neq: "!=",
|
|
21593
|
+
pm: "+-",
|
|
21594
|
+
mp: "-+",
|
|
21595
|
+
times: "TIMES",
|
|
21596
|
+
cdot: "cdot",
|
|
21597
|
+
ast: "AST",
|
|
21598
|
+
circ: "CIRC",
|
|
21599
|
+
bullet: "BULLET",
|
|
21600
|
+
in: "IN",
|
|
21601
|
+
notin: "NOTIN",
|
|
21602
|
+
subset: "SUBSET",
|
|
21603
|
+
subseteq: "SUBSETEQ",
|
|
21604
|
+
supset: "SUPERSET",
|
|
21605
|
+
supseteq: "SUPSETEQ",
|
|
21606
|
+
cup: "CUP",
|
|
21607
|
+
cap: "SMALLINTER",
|
|
21608
|
+
emptyset: "EMPTYSET",
|
|
21609
|
+
forall: "FORALL",
|
|
21610
|
+
exists: "EXIST",
|
|
21611
|
+
infinity: "INF",
|
|
21612
|
+
infty: "INF",
|
|
21613
|
+
partial: "Partial",
|
|
21614
|
+
nabla: "NABLA",
|
|
21615
|
+
int: "int",
|
|
21616
|
+
iint: "dint",
|
|
21617
|
+
iiint: "tint",
|
|
21618
|
+
oint: "oint",
|
|
21619
|
+
sum: "sum",
|
|
21620
|
+
prod: "prod",
|
|
21621
|
+
lim: "lim",
|
|
21622
|
+
to: "->",
|
|
21623
|
+
rightarrow: "->",
|
|
21624
|
+
leftarrow: "larrow",
|
|
21625
|
+
leftrightarrow: "<->",
|
|
21626
|
+
Rightarrow: "RARROW",
|
|
21627
|
+
Leftarrow: "LARROW",
|
|
21628
|
+
Leftrightarrow: "LRARROW",
|
|
21629
|
+
cdots: "CDOTS",
|
|
21630
|
+
ldots: "LDOTS",
|
|
21631
|
+
vdots: "VDOTS",
|
|
21632
|
+
ddots: "DDOTS"
|
|
21633
|
+
};
|
|
21634
|
+
var ACCENT_COMMANDS = {
|
|
21635
|
+
bar: "bar",
|
|
21636
|
+
overline: "bar",
|
|
21637
|
+
vec: "vec",
|
|
21638
|
+
overrightarrow: "vec",
|
|
21639
|
+
hat: "hat",
|
|
21640
|
+
widehat: "hat",
|
|
21641
|
+
tilde: "tilde",
|
|
21642
|
+
widetilde: "tilde",
|
|
21643
|
+
dot: "dot",
|
|
21644
|
+
ddot: "ddot",
|
|
21645
|
+
underline: "under"
|
|
21646
|
+
};
|
|
21647
|
+
var RESERVED_WORDS = new Set(
|
|
21648
|
+
[...Object.keys(CONVERT_MAP), ...Object.keys(MIDDLE_CONVERT_MAP), "over", "root", "of"].filter((w) => /^[A-Za-z]+$/.test(w))
|
|
21649
|
+
);
|
|
21650
|
+
function skipSpaces(input, idx) {
|
|
21651
|
+
while (idx < input.length && /\s/.test(input[idx])) idx++;
|
|
21652
|
+
return idx;
|
|
21653
|
+
}
|
|
21654
|
+
function normalizeEqEdit(input) {
|
|
21655
|
+
return input.replace(/\s+/g, " ").trim();
|
|
21656
|
+
}
|
|
21657
|
+
function stripMathDelimiters(input) {
|
|
21658
|
+
let s = input.trim();
|
|
21659
|
+
if (s.startsWith("$$") && s.endsWith("$$")) s = s.slice(2, -2).trim();
|
|
21660
|
+
if (s.startsWith("\\[") && s.endsWith("\\]")) s = s.slice(2, -2).trim();
|
|
21661
|
+
return s;
|
|
21662
|
+
}
|
|
21663
|
+
function readBalanced(input, idx, open, close) {
|
|
21664
|
+
let depth = 1;
|
|
21665
|
+
let cursor = idx + 1;
|
|
21666
|
+
while (cursor < input.length) {
|
|
21667
|
+
const ch = input[cursor];
|
|
21668
|
+
if (ch === "\\") {
|
|
21669
|
+
cursor += 2;
|
|
21670
|
+
continue;
|
|
21671
|
+
}
|
|
21672
|
+
if (ch === open) depth++;
|
|
21673
|
+
else if (ch === close) depth--;
|
|
21674
|
+
if (depth === 0) {
|
|
21675
|
+
return { value: input.slice(idx + 1, cursor), next: cursor + 1 };
|
|
21676
|
+
}
|
|
21677
|
+
cursor++;
|
|
21678
|
+
}
|
|
21679
|
+
return { value: input.slice(idx + 1), next: input.length };
|
|
21680
|
+
}
|
|
21681
|
+
function readGroupOrToken(input, idx, depth) {
|
|
21682
|
+
const start = skipSpaces(input, idx);
|
|
21683
|
+
if (depth > MAX_GROUP_DEPTH) return { value: input.slice(start), next: input.length };
|
|
21684
|
+
if (input[start] === "{") {
|
|
21685
|
+
const group = readBalanced(input, start, "{", "}");
|
|
21686
|
+
return { value: convertLatexFragment(group.value, depth + 1), next: group.next };
|
|
21687
|
+
}
|
|
21688
|
+
if (input[start] === "\\") {
|
|
21689
|
+
const cmd = readCommand(input, start, depth + 1);
|
|
21690
|
+
return { value: cmd.value, next: cmd.next };
|
|
21691
|
+
}
|
|
21692
|
+
return { value: input[start] ?? "", next: Math.min(start + 1, input.length) };
|
|
21693
|
+
}
|
|
21694
|
+
function readCommandName(input, idx) {
|
|
21695
|
+
if (input[idx + 1] === "\\") return { value: "\\", next: idx + 2 };
|
|
21696
|
+
const match = /^[A-Za-z]+/.exec(input.slice(idx + 1));
|
|
21697
|
+
if (match) return { value: match[0], next: idx + 1 + match[0].length };
|
|
21698
|
+
return { value: input[idx + 1] ?? "", next: Math.min(idx + 2, input.length) };
|
|
21699
|
+
}
|
|
21700
|
+
function readCommand(input, idx, depth) {
|
|
21701
|
+
const name = readCommandName(input, idx);
|
|
21702
|
+
const command = name.value;
|
|
21703
|
+
if (command === "\\") return { value: "#", next: name.next };
|
|
21704
|
+
if (command === "frac") {
|
|
21705
|
+
const num = readGroupOrToken(input, name.next, depth);
|
|
21706
|
+
const den = readGroupOrToken(input, num.next, depth);
|
|
21707
|
+
return { value: `{${num.value}} over {${den.value}}`, next: den.next };
|
|
21708
|
+
}
|
|
21709
|
+
if (command === "sqrt") {
|
|
21710
|
+
let cursor = skipSpaces(input, name.next);
|
|
21711
|
+
let root = null;
|
|
21712
|
+
if (input[cursor] === "[") {
|
|
21713
|
+
const opt = readBalanced(input, cursor, "[", "]");
|
|
21714
|
+
root = { value: convertLatexFragment(opt.value, depth + 1), next: opt.next };
|
|
21715
|
+
cursor = opt.next;
|
|
21716
|
+
}
|
|
21717
|
+
const body = readGroupOrToken(input, cursor, depth);
|
|
21718
|
+
if (root) return { value: `root {${root.value}} of {${body.value}}`, next: body.next };
|
|
21719
|
+
return { value: `sqrt{${body.value}}`, next: body.next };
|
|
21720
|
+
}
|
|
21721
|
+
if (command === "begin") {
|
|
21722
|
+
const env = readGroupOrToken(input, name.next, depth);
|
|
21723
|
+
const endTag = `\\end{${env.value}}`;
|
|
21724
|
+
const endIdx = input.indexOf(endTag, env.next);
|
|
21725
|
+
if (endIdx === -1) return { value: env.value, next: env.next };
|
|
21726
|
+
const body = convertLatexFragment(input.slice(env.next, endIdx), depth + 1);
|
|
21727
|
+
if (env.value === "matrix" || env.value === "pmatrix" || env.value === "bmatrix") {
|
|
21728
|
+
return { value: `{${env.value}{${body}}}`, next: endIdx + endTag.length };
|
|
21729
|
+
}
|
|
21730
|
+
return { value: body, next: endIdx + endTag.length };
|
|
21731
|
+
}
|
|
21732
|
+
if (command === "left" || command === "right") {
|
|
21733
|
+
const kw = command === "left" ? "LEFT" : "RIGHT";
|
|
21734
|
+
const cursor = skipSpaces(input, name.next);
|
|
21735
|
+
let delimiter = input[cursor] ?? "";
|
|
21736
|
+
let next = delimiter ? cursor + 1 : cursor;
|
|
21737
|
+
if (delimiter === "\\") {
|
|
21738
|
+
const escaped = readCommandName(input, cursor);
|
|
21739
|
+
delimiter = escaped.value === "\\" ? "\\" : COMMAND_MAP[escaped.value] ?? escaped.value;
|
|
21740
|
+
next = escaped.next;
|
|
21741
|
+
}
|
|
21742
|
+
return { value: delimiter ? `${kw} ${delimiter}` : kw, next };
|
|
21743
|
+
}
|
|
21744
|
+
if (command in ACCENT_COMMANDS) {
|
|
21745
|
+
const body = readGroupOrToken(input, name.next, depth);
|
|
21746
|
+
return { value: `${ACCENT_COMMANDS[command]}{${body.value}}`, next: body.next };
|
|
21747
|
+
}
|
|
21748
|
+
if (command === "mathrm" || command === "text") {
|
|
21749
|
+
const start = skipSpaces(input, name.next);
|
|
21750
|
+
if (input[start] === "{") {
|
|
21751
|
+
const group = readBalanced(input, start, "{", "}");
|
|
21752
|
+
return { value: `"${group.value}"`, next: group.next };
|
|
21753
|
+
}
|
|
21754
|
+
const tok = readGroupOrToken(input, start, depth);
|
|
21755
|
+
return { value: `"${tok.value}"`, next: tok.next };
|
|
21756
|
+
}
|
|
21757
|
+
return { value: COMMAND_MAP[command] ?? command, next: name.next };
|
|
21758
|
+
}
|
|
21759
|
+
function convertLatexFragment(input, depth) {
|
|
21760
|
+
if (depth > MAX_GROUP_DEPTH) return normalizeEqEdit(input);
|
|
21761
|
+
let out = "";
|
|
21762
|
+
let idx = 0;
|
|
21763
|
+
while (idx < input.length) {
|
|
21764
|
+
const ch = input[idx];
|
|
21765
|
+
if (ch === "\\") {
|
|
21766
|
+
const cmd = readCommand(input, idx, depth + 1);
|
|
21767
|
+
out += ` ${cmd.value} `;
|
|
21768
|
+
idx = cmd.next;
|
|
21769
|
+
continue;
|
|
21770
|
+
}
|
|
21771
|
+
if (ch === "{") {
|
|
21772
|
+
const group = readBalanced(input, idx, "{", "}");
|
|
21773
|
+
out += `{${convertLatexFragment(group.value, depth + 1)}}`;
|
|
21774
|
+
idx = group.next;
|
|
21775
|
+
continue;
|
|
21776
|
+
}
|
|
21777
|
+
if (ch === "_" || ch === "^") {
|
|
21778
|
+
const script = readGroupOrToken(input, idx + 1, depth);
|
|
21779
|
+
out += ` ${ch}{${script.value}}`;
|
|
21780
|
+
idx = script.next;
|
|
21781
|
+
continue;
|
|
21782
|
+
}
|
|
21783
|
+
if (ch === "&") {
|
|
21784
|
+
out += " & ";
|
|
21785
|
+
idx++;
|
|
21786
|
+
continue;
|
|
21787
|
+
}
|
|
21788
|
+
out += ch;
|
|
21789
|
+
idx++;
|
|
21790
|
+
}
|
|
21791
|
+
return normalizeEqEdit(out);
|
|
21792
|
+
}
|
|
21793
|
+
function quoteReservedKeywords(latex) {
|
|
21794
|
+
return latex.replace(/([_^])\s*\{\s*([A-Za-z]+)\s*\}/g, (match, op, word) => RESERVED_WORDS.has(word) ? `${op}{"${word}"}` : match);
|
|
21795
|
+
}
|
|
21796
|
+
function latexLikeToEqEdit(input) {
|
|
21797
|
+
const src = stripMathDelimiters(input);
|
|
21798
|
+
if (src.length > MAX_EQUATION_SOURCE) return normalizeEqEdit(src);
|
|
21799
|
+
return convertLatexFragment(quoteReservedKeywords(src), 0);
|
|
21800
|
+
}
|
|
21801
|
+
function estimateEquationMetrics(script) {
|
|
21802
|
+
const cleaned = script.replace(/[{}\\^_]/g, "").replace(/\s+/g, " ").trim();
|
|
21803
|
+
const width = Math.min(Math.max(cleaned.length, 5) * 700 + 2e3, 4e4);
|
|
21804
|
+
const rowCount = Math.max(1, (script.match(/#/g) ?? []).length + 1);
|
|
21805
|
+
if (/\bmatrix\b|#/.test(script)) {
|
|
21806
|
+
if (rowCount >= 4) return { width, height: 5500, baseline: 55 };
|
|
21807
|
+
if (rowCount === 3) return { width, height: 4500, baseline: 60 };
|
|
21808
|
+
return { width, height: 3260, baseline: 63 };
|
|
21809
|
+
}
|
|
21810
|
+
if (/\bover\b|\broot\b|\bsqrt\b/.test(script)) return { width, height: 3010, baseline: 69 };
|
|
21811
|
+
return { width, height: 1450, baseline: 71 };
|
|
21812
|
+
}
|
|
21813
|
+
function generateEquationXml(script, zOrder = 0) {
|
|
21814
|
+
const { width, height, baseline } = estimateEquationMetrics(script);
|
|
21815
|
+
const eqId = 2000000001 + zOrder;
|
|
21816
|
+
return `<hp:equation id="${eqId}" zOrder="${zOrder}" numberingType="EQUATION" textWrap="TOP_AND_BOTTOM" textFlow="BOTH_SIDES" lock="0" dropcapstyle="None" version="Equation Version 60" baseLine="${baseline}" textColor="#000000" baseUnit="1200" lineMode="CHAR" font="HYhwpEQ"><hp:sz width="${width}" widthRelTo="ABSOLUTE" height="${height}" heightRelTo="ABSOLUTE" protect="0"/><hp:pos treatAsChar="1" affectLSpacing="0" flowWithText="1" allowOverlap="0" holdAnchorAndSO="0" vertRelTo="PARA" horzRelTo="PARA" vertAlign="TOP" horzAlign="LEFT" vertOffset="0" horzOffset="0"/><hp:outMargin left="56" right="56" top="0" bottom="0"/><hp:shapeComment>\uC218\uC2DD\uC785\uB2C8\uB2E4.</hp:shapeComment><hp:script>${escapeXml(script)}</hp:script></hp:equation>`;
|
|
21817
|
+
}
|
|
21818
|
+
function generateEquationParagraph(input, zOrder = 0) {
|
|
21819
|
+
const script = latexLikeToEqEdit(input);
|
|
21820
|
+
return `<hp:p paraPrIDRef="${PARA_NORMAL}" styleIDRef="0"><hp:run charPrIDRef="${CHAR_NORMAL}">${generateEquationXml(script, zOrder)}</hp:run></hp:p>`;
|
|
21821
|
+
}
|
|
21822
|
+
|
|
21493
21823
|
// src/hwpx/gen-section.ts
|
|
21494
21824
|
function generateSecPr(gongmun) {
|
|
21495
21825
|
const m = gongmun ? {
|
|
@@ -21537,6 +21867,15 @@ function blocksToSectionXml(blocks, theme, gongmun, gongmunList = gongmun ? prec
|
|
|
21537
21867
|
xml = codeLines.map((line) => generateParagraph(line || " ", PARA_CODE)).join("\n ");
|
|
21538
21868
|
break;
|
|
21539
21869
|
}
|
|
21870
|
+
case "equation": {
|
|
21871
|
+
if (isFirst) {
|
|
21872
|
+
const secRun = `<hp:run charPrIDRef="0">${generateSecPr(gongmun)}<hp:t></hp:t></hp:run>`;
|
|
21873
|
+
paraXmls.push(`<hp:p paraPrIDRef="0" styleIDRef="0">${secRun}</hp:p>`);
|
|
21874
|
+
isFirst = false;
|
|
21875
|
+
}
|
|
21876
|
+
xml = generateEquationParagraph(block.text || "", blockIdx);
|
|
21877
|
+
break;
|
|
21878
|
+
}
|
|
21540
21879
|
case "blockquote":
|
|
21541
21880
|
xml = generateParagraph(
|
|
21542
21881
|
block.text || "",
|
|
@@ -24368,7 +24707,7 @@ async function parseHwp(buffer, options) {
|
|
|
24368
24707
|
async function parsePdf(buffer, options) {
|
|
24369
24708
|
let parsePdfDocument;
|
|
24370
24709
|
try {
|
|
24371
|
-
const mod = await import("./parser-
|
|
24710
|
+
const mod = await import("./parser-LVI45MVF.js");
|
|
24372
24711
|
parsePdfDocument = mod.parsePdfDocument;
|
|
24373
24712
|
} catch {
|
|
24374
24713
|
return {
|
|
@@ -24503,4 +24842,4 @@ export {
|
|
|
24503
24842
|
parseHwpml,
|
|
24504
24843
|
fillForm
|
|
24505
24844
|
};
|
|
24506
|
-
//# sourceMappingURL=chunk-
|
|
24845
|
+
//# sourceMappingURL=chunk-ITPZD7XK.js.map
|