kordoc 3.8.3 → 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/dist/index.js CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  sanitizeHref,
20
20
  stripDtd,
21
21
  toArrayBuffer
22
- } from "./chunk-7J73IGMK.js";
22
+ } from "./chunk-EZ5GBTBE.js";
23
23
  import {
24
24
  parsePageRange
25
25
  } from "./chunk-GE43BE46.js";
@@ -664,8 +664,10 @@ var CONVERT_MAP = {
664
664
  SUCC: "\\succ",
665
665
  UPLUS: "\\uplus",
666
666
  "\xB1": "\\pm",
667
+ "+-": "\\pm",
667
668
  "-+": "\\mp",
668
669
  "\xF7": "\\div",
670
+ cdot: "\\cdot",
669
671
  CIRC: "\\circ",
670
672
  BULLET: "\\bullet",
671
673
  DEG: " ^\\circ",
@@ -1054,6 +1056,10 @@ function hmlToLatex(hmlEqStr) {
1054
1056
  const t = tokens[i];
1055
1057
  if (t in CONVERT_MAP) tokens[i] = CONVERT_MAP[t];
1056
1058
  else if (t in MIDDLE_CONVERT_MAP) tokens[i] = MIDDLE_CONVERT_MAP[t];
1059
+ else {
1060
+ const quoted = /^"(.+)"$/.exec(t);
1061
+ if (quoted) tokens[i] = `\\text{${quoted[1]}}`;
1062
+ }
1057
1063
  }
1058
1064
  tokens = tokens.filter((tok) => tok.length !== 0);
1059
1065
  tokens = replaceBracket(tokens);
@@ -1150,14 +1156,14 @@ function resolveParaHeading(paraEl, ctx) {
1150
1156
  const head = numDef.heads.get(level);
1151
1157
  counters[level] = counters[level] === 0 ? head?.start ?? 1 : counters[level] + 1;
1152
1158
  for (let l = level + 1; l <= 10; l++) counters[l] = 0;
1153
- const fmtText = head?.text?.trim() || `^${level}.`;
1159
+ const fmtText = head ? head.text.trim() : `^${level}.`;
1154
1160
  const prefix = fmtText.replace(/\^(10|[1-9])/g, (_, d) => {
1155
1161
  const lv = parseInt(d, 10);
1156
1162
  const refHead = numDef.heads.get(lv);
1157
1163
  const n = counters[lv] || refHead?.start || 1;
1158
1164
  return formatHeadNumber(n, refHead?.numFormat || "DIGIT");
1159
1165
  });
1160
- return { prefix, headingLevel };
1166
+ return { prefix: prefix || void 0, headingLevel };
1161
1167
  }
1162
1168
 
1163
1169
  // src/hwpx/table-build.ts
@@ -18309,74 +18315,79 @@ function parseParagraph2(p, styles, numbering, footnotes, rels) {
18309
18315
  if (footnoteText) block.footnoteText = footnoteText;
18310
18316
  return block;
18311
18317
  }
18318
+ function collectTextboxParagraphs(node, inTxbx = false, out = [], depth = 0) {
18319
+ if (depth > 40) return out;
18320
+ for (const el of effectiveChildElements(node)) {
18321
+ if (matchesLocal(el, "Fallback")) continue;
18322
+ const nowIn = inTxbx || matchesLocal(el, "txbxContent");
18323
+ if (nowIn && matchesLocal(el, "p")) out.push(el);
18324
+ collectTextboxParagraphs(el, nowIn, out, depth + 1);
18325
+ }
18326
+ return out;
18327
+ }
18312
18328
  function parseTable(tbl, styles, numbering, footnotes, rels) {
18313
18329
  const trElements = getChildElements(tbl, "tr");
18314
18330
  if (trElements.length === 0) return null;
18315
- const rows = [];
18316
- let maxCols = 0;
18331
+ const rawRows = [];
18317
18332
  for (const tr of trElements) {
18318
- const tcElements = getChildElements(tr, "tc");
18319
18333
  const row = [];
18320
- for (const tc of tcElements) {
18334
+ let col = 0;
18335
+ for (const tc of getChildElements(tr, "tc")) {
18321
18336
  let colSpan = 1;
18322
- let rowSpan = 1;
18337
+ let vMerge = null;
18323
18338
  const tcPrEls = getChildElements(tc, "tcPr");
18324
18339
  if (tcPrEls.length > 0) {
18325
18340
  const gridSpanEls = getChildElements(tcPrEls[0], "gridSpan");
18326
18341
  if (gridSpanEls.length > 0) {
18327
- colSpan = parseInt(getAttr(gridSpanEls[0], "val") ?? "1", 10);
18342
+ colSpan = parseInt(getAttr(gridSpanEls[0], "val") ?? "1", 10) || 1;
18328
18343
  }
18329
18344
  const vMergeEls = getChildElements(tcPrEls[0], "vMerge");
18330
18345
  if (vMergeEls.length > 0) {
18331
- const val = getAttr(vMergeEls[0], "val");
18332
- if (val !== "restart" && val !== null) {
18333
- row.push({ text: "", colSpan, rowSpan: 0 });
18334
- continue;
18335
- }
18346
+ vMerge = getAttr(vMergeEls[0], "val") === "restart" ? "restart" : "continue";
18347
+ }
18348
+ }
18349
+ const text = vMerge === "continue" ? "" : collectCellText(tc, styles, numbering, footnotes, rels, 0).join("\n");
18350
+ row.push({ col, colSpan, vMerge, text });
18351
+ col += colSpan;
18352
+ }
18353
+ rawRows.push(row);
18354
+ }
18355
+ const cellRows = rawRows.map(
18356
+ (row, r) => row.filter((cell) => cell.vMerge !== "continue").map((cell) => {
18357
+ let rowSpan = 1;
18358
+ if (cell.vMerge === "restart") {
18359
+ for (let nr = r + 1; nr < rawRows.length; nr++) {
18360
+ if (!rawRows[nr].some((nc) => nc.col === cell.col && nc.vMerge === "continue")) break;
18361
+ rowSpan++;
18336
18362
  }
18337
18363
  }
18338
- const cellTexts = [];
18339
- const pElements = getChildElements(tc, "p");
18340
- for (const p of pElements) {
18341
- const block = parseParagraph2(p, styles, numbering, footnotes, rels);
18342
- if (block?.text) cellTexts.push(block.text);
18364
+ return { text: cell.text, colSpan: cell.colSpan, rowSpan, colAddr: cell.col, rowAddr: r };
18365
+ })
18366
+ );
18367
+ const table = buildTable(cellRows);
18368
+ if (table.rows === 0 || table.cols === 0) return null;
18369
+ return { type: "table", table };
18370
+ }
18371
+ function collectCellText(tc, styles, numbering, footnotes, rels, depth) {
18372
+ const parts = [];
18373
+ if (depth > 20) return parts;
18374
+ for (const el of effectiveChildElements(tc)) {
18375
+ if (matchesLocal(el, "p")) {
18376
+ const block = parseParagraph2(el, styles, numbering, footnotes, rels);
18377
+ if (block?.text) parts.push(block.text);
18378
+ for (const tp of collectTextboxParagraphs(el)) {
18379
+ const tb = parseParagraph2(tp, styles, numbering, footnotes, rels);
18380
+ if (tb?.text) parts.push(tb.text);
18343
18381
  }
18344
- row.push({ text: cellTexts.join("\n"), colSpan, rowSpan });
18345
- }
18346
- rows.push(row);
18347
- if (row.length > maxCols) maxCols = row.length;
18348
- }
18349
- for (let c = 0; c < maxCols; c++) {
18350
- for (let r = 0; r < rows.length; r++) {
18351
- const cell = rows[r][c];
18352
- if (!cell || cell.rowSpan === 0) continue;
18353
- let span = 1;
18354
- for (let nr = r + 1; nr < rows.length; nr++) {
18355
- if (rows[nr][c]?.rowSpan === 0) span++;
18356
- else break;
18382
+ } else if (matchesLocal(el, "tbl")) {
18383
+ for (const tr of getChildElements(el, "tr")) {
18384
+ for (const nestedTc of getChildElements(tr, "tc")) {
18385
+ parts.push(...collectCellText(nestedTc, styles, numbering, footnotes, rels, depth + 1));
18386
+ }
18357
18387
  }
18358
- cell.rowSpan = span;
18359
18388
  }
18360
18389
  }
18361
- const cleanRows = [];
18362
- for (const row of rows) {
18363
- const clean = row.filter((cell) => cell.rowSpan !== 0);
18364
- cleanRows.push(clean);
18365
- }
18366
- if (cleanRows.length === 0) return null;
18367
- let cols = 0;
18368
- for (const row of cleanRows) {
18369
- let c = 0;
18370
- for (const cell of row) c += cell.colSpan;
18371
- if (c > cols) cols = c;
18372
- }
18373
- const table = {
18374
- rows: cleanRows.length,
18375
- cols,
18376
- cells: cleanRows,
18377
- hasHeader: cleanRows.length > 1
18378
- };
18379
- return { type: "table", table };
18390
+ return parts;
18380
18391
  }
18381
18392
  async function extractImages(zip, rels, doc, warnings) {
18382
18393
  const blocks = [];
@@ -18482,6 +18493,10 @@ async function parseDocxDocument(buffer, options) {
18482
18493
  if (localName2 === "p") {
18483
18494
  const block = parseParagraph2(el, styles, numbering, footnotes, rels);
18484
18495
  if (block) blocks.push(block);
18496
+ for (const tp of collectTextboxParagraphs(el)) {
18497
+ const tb = parseParagraph2(tp, styles, numbering, footnotes, rels);
18498
+ if (tb) blocks.push(tb);
18499
+ }
18485
18500
  } else if (localName2 === "tbl") {
18486
18501
  const block = parseTable(el, styles, numbering, footnotes, rels);
18487
18502
  if (block) blocks.push(block);
@@ -18739,10 +18754,10 @@ function parseTable2(el, blocks, paraShapeMap, sectionNum, warnings) {
18739
18754
  }
18740
18755
  function extractCellText(cellEl) {
18741
18756
  const textParts = [];
18742
- collectCellText(cellEl, textParts, 0);
18757
+ collectCellText2(cellEl, textParts, 0);
18743
18758
  return textParts.filter(Boolean).join("\n").trim();
18744
18759
  }
18745
- function collectCellText(node, parts, depth) {
18760
+ function collectCellText2(node, parts, depth) {
18746
18761
  if (depth > 20) return;
18747
18762
  const children = node.childNodes;
18748
18763
  for (let i = 0; i < children.length; i++) {
@@ -18754,9 +18769,9 @@ function collectCellText(node, parts, depth) {
18754
18769
  if (t) parts.push(t);
18755
18770
  collectNestedTableText(el, parts, depth + 1);
18756
18771
  } else if (tag === "TABLE") {
18757
- collectCellText(el, parts, depth + 1);
18772
+ collectCellText2(el, parts, depth + 1);
18758
18773
  } else {
18759
- collectCellText(el, parts, depth + 1);
18774
+ collectCellText2(el, parts, depth + 1);
18760
18775
  }
18761
18776
  }
18762
18777
  }
@@ -18768,7 +18783,7 @@ function collectNestedTableText(node, parts, depth) {
18768
18783
  if (el.nodeType !== 1) continue;
18769
18784
  const tag = localName(el);
18770
18785
  if (tag === "TABLE") {
18771
- collectCellText(el, parts, depth + 1);
18786
+ collectCellText2(el, parts, depth + 1);
18772
18787
  continue;
18773
18788
  }
18774
18789
  if (tag === "FOOTNOTE" || tag === "ENDNOTE" || tag === "HEADER" || tag === "FOOTER") continue;
@@ -20727,12 +20742,13 @@ function charPr(id, height, bold, italic, fontId = 0, textColor = DEFAULT_TEXT_C
20727
20742
  </hh:charPr>`;
20728
20743
  }
20729
20744
  function paraPr(id, opts = {}) {
20730
- const { align = "JUSTIFY", spaceBefore = 0, spaceAfter = 0, lineSpacing = 160, indent = 0, left = 0, keepWord = false } = opts;
20745
+ const { align = "JUSTIFY", spaceBefore = 0, spaceAfter = 0, lineSpacing = 160, indent = 0, left = 0, keepWord = false, outlineLevel } = opts;
20731
20746
  const breakNonLatin = keepWord ? "KEEP_WORD" : "BREAK_WORD";
20732
20747
  const snapGrid = keepWord ? "0" : "1";
20748
+ const heading = outlineLevel !== void 0 ? `<hh:heading type="OUTLINE" idRef="0" level="${outlineLevel}"/>` : `<hh:heading type="NONE" idRef="0" level="0"/>`;
20733
20749
  return ` <hh:paraPr id="${id}" tabPrIDRef="0" condense="0" fontLineHeight="0" snapToGrid="${snapGrid}" suppressLineNumbers="0" checked="0" textDir="AUTO">
20734
20750
  <hh:align horizontal="${align}" vertical="BASELINE"/>
20735
- <hh:heading type="NONE" idRef="0" level="0"/>
20751
+ ${heading}
20736
20752
  <hh:breakSetting breakLatinWord="KEEP_WORD" breakNonLatinWord="${breakNonLatin}" widowOrphan="0" keepWithNext="0" keepLines="0" pageBreakBefore="0" lineWrap="BREAK"/>
20737
20753
  <hh:autoSpacing eAsianEng="0" eAsianNum="0"/>
20738
20754
  <hh:margin><hc:intent value="${indent}" unit="HWPUNIT"/><hc:left value="${left}" unit="HWPUNIT"/><hc:right value="0" unit="HWPUNIT"/><hc:prev value="${spaceBefore}" unit="HWPUNIT"/><hc:next value="${spaceAfter}" unit="HWPUNIT"/></hh:margin>
@@ -20760,6 +20776,16 @@ function buildPrvText(blocks) {
20760
20776
  }
20761
20777
  return lines.join("\n").slice(0, 1024);
20762
20778
  }
20779
+ function findMathDelim(s, from) {
20780
+ let i = s.indexOf("$$", from);
20781
+ while (i > 0) {
20782
+ let backslashes = 0;
20783
+ for (let j = i - 1; j >= 0 && s[j] === "\\"; j--) backslashes++;
20784
+ if (backslashes % 2 === 0) break;
20785
+ i = s.indexOf("$$", i + 1);
20786
+ }
20787
+ return i;
20788
+ }
20763
20789
  function parseMarkdownToBlocks(md2) {
20764
20790
  const lines = md2.split("\n");
20765
20791
  const blocks = [];
@@ -20770,6 +20796,45 @@ function parseMarkdownToBlocks(md2) {
20770
20796
  i++;
20771
20797
  continue;
20772
20798
  }
20799
+ const mathOpen = /^\s*\$\$/.exec(line);
20800
+ if (mathOpen) {
20801
+ const afterOpen = line.slice(mathOpen[0].length);
20802
+ const closeSame = findMathDelim(afterOpen, 0);
20803
+ if (closeSame >= 0) {
20804
+ const inner = afterOpen.slice(0, closeSame).trim();
20805
+ const trailing2 = afterOpen.slice(closeSame + 2).trim();
20806
+ if (inner) blocks.push({ type: "equation", text: inner });
20807
+ if (trailing2) blocks.push({ type: "paragraph", text: trailing2 });
20808
+ i++;
20809
+ continue;
20810
+ }
20811
+ const mathLines = [];
20812
+ if (afterOpen.trim()) mathLines.push(afterOpen);
20813
+ let closed = false;
20814
+ let trailing = "";
20815
+ let j = i + 1;
20816
+ for (; j < lines.length; j++) {
20817
+ const l = lines[j];
20818
+ if (!l.trim() || /^\s*(`{3,}|~{3,})/.test(l)) break;
20819
+ const end = findMathDelim(l, 0);
20820
+ if (end >= 0) {
20821
+ const before = l.slice(0, end);
20822
+ if (before.trim()) mathLines.push(before);
20823
+ trailing = l.slice(end + 2).trim();
20824
+ closed = true;
20825
+ j++;
20826
+ break;
20827
+ }
20828
+ mathLines.push(l);
20829
+ }
20830
+ if (closed) {
20831
+ const text = mathLines.join("\n").trim();
20832
+ if (text) blocks.push({ type: "equation", text });
20833
+ if (trailing) blocks.push({ type: "paragraph", text: trailing });
20834
+ i = j;
20835
+ continue;
20836
+ }
20837
+ }
20773
20838
  const fenceMatch = line.match(/^(`{3,}|~{3,})(.*)$/);
20774
20839
  if (fenceMatch) {
20775
20840
  const fence = fenceMatch[1];
@@ -20839,7 +20904,7 @@ function parseMarkdownToBlocks(md2) {
20839
20904
  if (listMatch) {
20840
20905
  const indent = Math.floor(listMatch[1].length / 2);
20841
20906
  const ordered = /\d/.test(listMatch[2]);
20842
- blocks.push({ type: "list_item", text: listMatch[3].trim(), ordered, indent });
20907
+ blocks.push({ type: "list_item", text: listMatch[3].trim(), ordered, indent, marker: listMatch[2] });
20843
20908
  i++;
20844
20909
  continue;
20845
20910
  }
@@ -20849,6 +20914,11 @@ function parseMarkdownToBlocks(md2) {
20849
20914
  return blocks;
20850
20915
  }
20851
20916
  function parseInlineMarkdown(text) {
20917
+ const literals = [];
20918
+ text = text.replace(/\x00/g, "").replace(/\\([\\`*_{}[\]()#+\-.!|>~])/g, (_, c) => {
20919
+ literals.push(c);
20920
+ return `\0${literals.length - 1}\0`;
20921
+ });
20852
20922
  text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1");
20853
20923
  text = text.replace(/\[([^\]]*)\]\(([^)]*)\)/g, (_, t, u) => t || u);
20854
20924
  text = text.replace(/~~([^~]+)~~/g, "$1");
@@ -20878,6 +20948,13 @@ function parseInlineMarkdown(text) {
20878
20948
  if (spans.length === 0) {
20879
20949
  spans.push({ text, bold: false, italic: false, code: false });
20880
20950
  }
20951
+ for (const span of spans) {
20952
+ if (!span.text.includes("\0")) continue;
20953
+ span.text = span.text.replace(/\x00(\d+)\x00/g, (_, i) => {
20954
+ const c = literals[+i] ?? "";
20955
+ return span.code ? "\\" + c : c;
20956
+ });
20957
+ }
20881
20958
  return spans;
20882
20959
  }
20883
20960
  function spanToCharPrId(span) {
@@ -20965,10 +21042,10 @@ function buildParaProperties(gongmun) {
20965
21042
  if (!gongmun) {
20966
21043
  const base2 = [
20967
21044
  paraPr(0),
20968
- paraPr(1, { align: "LEFT", spaceBefore: 800, spaceAfter: 200, lineSpacing: 180 }),
20969
- paraPr(2, { align: "LEFT", spaceBefore: 600, spaceAfter: 150, lineSpacing: 170 }),
20970
- paraPr(3, { align: "LEFT", spaceBefore: 400, spaceAfter: 100, lineSpacing: 160 }),
20971
- paraPr(4, { align: "LEFT", spaceBefore: 300, spaceAfter: 100, lineSpacing: 160 }),
21045
+ paraPr(1, { align: "LEFT", spaceBefore: 800, spaceAfter: 200, lineSpacing: 180, outlineLevel: 0 }),
21046
+ paraPr(2, { align: "LEFT", spaceBefore: 600, spaceAfter: 150, lineSpacing: 170, outlineLevel: 1 }),
21047
+ paraPr(3, { align: "LEFT", spaceBefore: 400, spaceAfter: 100, lineSpacing: 160, outlineLevel: 2 }),
21048
+ paraPr(4, { align: "LEFT", spaceBefore: 300, spaceAfter: 100, lineSpacing: 160, outlineLevel: 3 }),
20972
21049
  paraPr(5, { align: "LEFT", lineSpacing: 130, indent: 400 }),
20973
21050
  paraPr(6, { align: "LEFT", lineSpacing: 150, indent: 600 }),
20974
21051
  paraPr(7, { align: "LEFT", lineSpacing: 160, indent: 600 })
@@ -20981,10 +21058,10 @@ ${base2.join("\n")}
20981
21058
  const titleAlign = gongmun.centerTitle ? "CENTER" : "LEFT";
20982
21059
  const base = [
20983
21060
  paraPr(0, { lineSpacing: ls, keepWord: true }),
20984
- paraPr(1, { align: titleAlign, spaceBefore: 400, spaceAfter: 400, lineSpacing: ls, keepWord: true }),
20985
- paraPr(2, { align: "LEFT", spaceBefore: 600, spaceAfter: 150, lineSpacing: ls, keepWord: true }),
20986
- paraPr(3, { align: "LEFT", spaceBefore: 400, spaceAfter: 100, lineSpacing: ls, keepWord: true }),
20987
- paraPr(4, { align: "LEFT", spaceBefore: 300, spaceAfter: 100, lineSpacing: ls, keepWord: true }),
21061
+ paraPr(1, { align: titleAlign, spaceBefore: 400, spaceAfter: 400, lineSpacing: ls, keepWord: true, outlineLevel: 0 }),
21062
+ paraPr(2, { align: "LEFT", spaceBefore: 600, spaceAfter: 150, lineSpacing: ls, keepWord: true, outlineLevel: 1 }),
21063
+ paraPr(3, { align: "LEFT", spaceBefore: 400, spaceAfter: 100, lineSpacing: ls, keepWord: true, outlineLevel: 2 }),
21064
+ paraPr(4, { align: "LEFT", spaceBefore: 300, spaceAfter: 100, lineSpacing: ls, keepWord: true, outlineLevel: 3 }),
20988
21065
  paraPr(5, { align: "LEFT", lineSpacing: 130, indent: 400, keepWord: true }),
20989
21066
  paraPr(6, { align: "LEFT", lineSpacing: ls, indent: 600, keepWord: true }),
20990
21067
  paraPr(7, { align: "LEFT", lineSpacing: ls, indent: 600, keepWord: true })
@@ -20999,6 +21076,17 @@ ${base2.join("\n")}
20999
21076
  ${base.join("\n")}
21000
21077
  </hh:paraProperties>`;
21001
21078
  }
21079
+ function buildNumberings() {
21080
+ const heads = Array.from(
21081
+ { length: 7 },
21082
+ (_, i) => ` <hh:paraHead start="1" level="${i + 1}" align="LEFT" useInstWidth="1" autoIndent="1" widthAdjust="0" textOffsetType="PERCENT" textOffset="50" numFormat="DIGIT" charPrIDRef="4294967295" checkable="0"/>`
21083
+ ).join("\n");
21084
+ return `<hh:numberings itemCnt="1">
21085
+ <hh:numbering id="1" start="0">
21086
+ ${heads}
21087
+ </hh:numbering>
21088
+ </hh:numberings>`;
21089
+ }
21002
21090
  function generateHeaderXml(theme, gongmun, ratioVariants = []) {
21003
21091
  const bodyFace = gongmun?.bodyFont === "gothic" ? "\uB9D1\uC740 \uACE0\uB515" : "\uD568\uCD08\uB86C\uBC14\uD0D5";
21004
21092
  const charPropsXml = buildCharProperties(theme, gongmun, ratioVariants);
@@ -21076,7 +21164,7 @@ function generateHeaderXml(theme, gongmun, ratioVariants = []) {
21076
21164
  </hh:borderFills>
21077
21165
  ${charPropsXml}
21078
21166
  <hh:tabProperties itemCnt="0"/>
21079
- <hh:numberings itemCnt="0"/>
21167
+ ${buildNumberings()}
21080
21168
  <hh:bullets itemCnt="0"/>
21081
21169
  ${paraPropsXml}
21082
21170
  <hh:styles itemCnt="1">
@@ -21139,6 +21227,7 @@ function precomputeGongmunList(blocks, gongmun) {
21139
21227
  i++;
21140
21228
  continue;
21141
21229
  }
21230
+ const passThrough = (t) => t === "table" || t === "html_table" || t === "equation";
21142
21231
  const run = [];
21143
21232
  while (i < blocks.length) {
21144
21233
  const t = blocks[i].type;
@@ -21147,9 +21236,9 @@ function precomputeGongmunList(blocks, gongmun) {
21147
21236
  i++;
21148
21237
  continue;
21149
21238
  }
21150
- if (t === "table" || t === "html_table") {
21239
+ if (passThrough(t)) {
21151
21240
  let j = i + 1;
21152
- while (j < blocks.length && (blocks[j].type === "table" || blocks[j].type === "html_table")) j++;
21241
+ while (j < blocks.length && passThrough(blocks[j].type)) j++;
21153
21242
  if (j < blocks.length && blocks[j].type === "list_item") {
21154
21243
  i = j;
21155
21244
  continue;
@@ -21341,7 +21430,7 @@ function bestSimInRange(arr, from, to, target) {
21341
21430
  return best;
21342
21431
  }
21343
21432
  function escapeGfm(text) {
21344
- return text.replace(/~/g, "\\~");
21433
+ return text.replace(/([~*])/g, "\\$1");
21345
21434
  }
21346
21435
  var HWP_SHAPE_ALT_TEXT_RE = /(?:모서리가 둥근 |둥근 )?(?:사각형|직사각형|정사각형|원|타원|삼각형|이등변 삼각형|직각 삼각형|선|직선|곡선|화살표|굵은 화살표|이중 화살표|오각형|육각형|팔각형|별|[4-8]점별|십자|십자형|구름|구름형|마름모|도넛|평행사변형|사다리꼴|부채꼴|호|반원|물결|번개|하트|빗금|블록 화살표|수식|표|그림|개체|그리기\s?개체|묶음\s?개체|글상자|수식\s?개체|OLE\s?개체)\s?입니다\.?/g;
21347
21436
  function sanitizeText(text) {
@@ -21359,7 +21448,7 @@ function normForMatch(text) {
21359
21448
  return sanitizeText(text).replace(/\s+/g, " ").trim();
21360
21449
  }
21361
21450
  function unescapeGfm(text) {
21362
- return text.replace(/\\~/g, "~");
21451
+ return text.replace(/\\([~*])/g, "$1");
21363
21452
  }
21364
21453
  function summarize(text) {
21365
21454
  const t = text.replace(/\s+/g, " ").trim();
@@ -21426,7 +21515,7 @@ function parseGfmTable(lines) {
21426
21515
  return rows;
21427
21516
  }
21428
21517
  function unescapeGfmCell(text) {
21429
- return text.replace(/<br\s*\/?>/gi, "\n").replace(/\\\|/g, "|").replace(/\\~/g, "~");
21518
+ return text.replace(/<br\s*\/?>/gi, "\n").replace(/\\\|/g, "|").replace(/\\([~*])/g, "$1");
21430
21519
  }
21431
21520
  function replicateCellInnerHtml(cell) {
21432
21521
  if (cell.blocks?.length) {
@@ -21675,6 +21764,280 @@ function generateHtmlTableXml(rawHtml, theme, totalWidth = 44e3) {
21675
21764
  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>`;
21676
21765
  }
21677
21766
 
21767
+ // src/hwpx/equation-generate.ts
21768
+ var MAX_EQUATION_SOURCE = 1e4;
21769
+ var MAX_GROUP_DEPTH = 64;
21770
+ var COMMAND_MAP = {
21771
+ alpha: "alpha",
21772
+ beta: "beta",
21773
+ gamma: "gamma",
21774
+ delta: "delta",
21775
+ epsilon: "epsilon",
21776
+ zeta: "zeta",
21777
+ eta: "eta",
21778
+ theta: "theta",
21779
+ iota: "iota",
21780
+ kappa: "kappa",
21781
+ lambda: "lambda",
21782
+ mu: "mu",
21783
+ nu: "nu",
21784
+ xi: "xi",
21785
+ pi: "pi",
21786
+ rho: "rho",
21787
+ sigma: "sigma",
21788
+ tau: "tau",
21789
+ upsilon: "upsilon",
21790
+ phi: "phi",
21791
+ chi: "chi",
21792
+ psi: "psi",
21793
+ omega: "omega",
21794
+ Gamma: "GAMMA",
21795
+ Delta: "DELTA",
21796
+ Theta: "THETA",
21797
+ Lambda: "LAMBDA",
21798
+ Xi: "XI",
21799
+ Pi: "PI",
21800
+ Sigma: "SIGMA",
21801
+ Upsilon: "UPSILON",
21802
+ Phi: "PHI",
21803
+ Psi: "PSI",
21804
+ Omega: "OMEGA",
21805
+ le: "LEQ",
21806
+ leq: "LEQ",
21807
+ ge: "GEQ",
21808
+ geq: "GEQ",
21809
+ ne: "!=",
21810
+ neq: "!=",
21811
+ pm: "+-",
21812
+ mp: "-+",
21813
+ times: "TIMES",
21814
+ cdot: "cdot",
21815
+ ast: "AST",
21816
+ circ: "CIRC",
21817
+ bullet: "BULLET",
21818
+ in: "IN",
21819
+ notin: "NOTIN",
21820
+ subset: "SUBSET",
21821
+ subseteq: "SUBSETEQ",
21822
+ supset: "SUPERSET",
21823
+ supseteq: "SUPSETEQ",
21824
+ cup: "CUP",
21825
+ cap: "SMALLINTER",
21826
+ emptyset: "EMPTYSET",
21827
+ forall: "FORALL",
21828
+ exists: "EXIST",
21829
+ infinity: "INF",
21830
+ infty: "INF",
21831
+ partial: "Partial",
21832
+ nabla: "NABLA",
21833
+ int: "int",
21834
+ iint: "dint",
21835
+ iiint: "tint",
21836
+ oint: "oint",
21837
+ sum: "sum",
21838
+ prod: "prod",
21839
+ lim: "lim",
21840
+ to: "->",
21841
+ rightarrow: "->",
21842
+ leftarrow: "larrow",
21843
+ leftrightarrow: "<->",
21844
+ Rightarrow: "RARROW",
21845
+ Leftarrow: "LARROW",
21846
+ Leftrightarrow: "LRARROW",
21847
+ cdots: "CDOTS",
21848
+ ldots: "LDOTS",
21849
+ vdots: "VDOTS",
21850
+ ddots: "DDOTS"
21851
+ };
21852
+ var ACCENT_COMMANDS = {
21853
+ bar: "bar",
21854
+ overline: "bar",
21855
+ vec: "vec",
21856
+ overrightarrow: "vec",
21857
+ hat: "hat",
21858
+ widehat: "hat",
21859
+ tilde: "tilde",
21860
+ widetilde: "tilde",
21861
+ dot: "dot",
21862
+ ddot: "ddot",
21863
+ underline: "under"
21864
+ };
21865
+ var RESERVED_WORDS = new Set(
21866
+ [...Object.keys(CONVERT_MAP), ...Object.keys(MIDDLE_CONVERT_MAP), "over", "root", "of"].filter((w) => /^[A-Za-z]+$/.test(w))
21867
+ );
21868
+ function skipSpaces(input, idx) {
21869
+ while (idx < input.length && /\s/.test(input[idx])) idx++;
21870
+ return idx;
21871
+ }
21872
+ function normalizeEqEdit(input) {
21873
+ return input.replace(/\s+/g, " ").trim();
21874
+ }
21875
+ function stripMathDelimiters(input) {
21876
+ let s = input.trim();
21877
+ if (s.startsWith("$$") && s.endsWith("$$")) s = s.slice(2, -2).trim();
21878
+ if (s.startsWith("\\[") && s.endsWith("\\]")) s = s.slice(2, -2).trim();
21879
+ return s;
21880
+ }
21881
+ function readBalanced(input, idx, open, close) {
21882
+ let depth = 1;
21883
+ let cursor = idx + 1;
21884
+ while (cursor < input.length) {
21885
+ const ch = input[cursor];
21886
+ if (ch === "\\") {
21887
+ cursor += 2;
21888
+ continue;
21889
+ }
21890
+ if (ch === open) depth++;
21891
+ else if (ch === close) depth--;
21892
+ if (depth === 0) {
21893
+ return { value: input.slice(idx + 1, cursor), next: cursor + 1 };
21894
+ }
21895
+ cursor++;
21896
+ }
21897
+ return { value: input.slice(idx + 1), next: input.length };
21898
+ }
21899
+ function readGroupOrToken(input, idx, depth) {
21900
+ const start = skipSpaces(input, idx);
21901
+ if (depth > MAX_GROUP_DEPTH) return { value: input.slice(start), next: input.length };
21902
+ if (input[start] === "{") {
21903
+ const group = readBalanced(input, start, "{", "}");
21904
+ return { value: convertLatexFragment(group.value, depth + 1), next: group.next };
21905
+ }
21906
+ if (input[start] === "\\") {
21907
+ const cmd = readCommand(input, start, depth + 1);
21908
+ return { value: cmd.value, next: cmd.next };
21909
+ }
21910
+ return { value: input[start] ?? "", next: Math.min(start + 1, input.length) };
21911
+ }
21912
+ function readCommandName(input, idx) {
21913
+ if (input[idx + 1] === "\\") return { value: "\\", next: idx + 2 };
21914
+ const match = /^[A-Za-z]+/.exec(input.slice(idx + 1));
21915
+ if (match) return { value: match[0], next: idx + 1 + match[0].length };
21916
+ return { value: input[idx + 1] ?? "", next: Math.min(idx + 2, input.length) };
21917
+ }
21918
+ function readCommand(input, idx, depth) {
21919
+ const name = readCommandName(input, idx);
21920
+ const command = name.value;
21921
+ if (command === "\\") return { value: "#", next: name.next };
21922
+ if (command === "frac") {
21923
+ const num = readGroupOrToken(input, name.next, depth);
21924
+ const den = readGroupOrToken(input, num.next, depth);
21925
+ return { value: `{${num.value}} over {${den.value}}`, next: den.next };
21926
+ }
21927
+ if (command === "sqrt") {
21928
+ let cursor = skipSpaces(input, name.next);
21929
+ let root = null;
21930
+ if (input[cursor] === "[") {
21931
+ const opt = readBalanced(input, cursor, "[", "]");
21932
+ root = { value: convertLatexFragment(opt.value, depth + 1), next: opt.next };
21933
+ cursor = opt.next;
21934
+ }
21935
+ const body = readGroupOrToken(input, cursor, depth);
21936
+ if (root) return { value: `root {${root.value}} of {${body.value}}`, next: body.next };
21937
+ return { value: `sqrt{${body.value}}`, next: body.next };
21938
+ }
21939
+ if (command === "begin") {
21940
+ const env = readGroupOrToken(input, name.next, depth);
21941
+ const endTag = `\\end{${env.value}}`;
21942
+ const endIdx = input.indexOf(endTag, env.next);
21943
+ if (endIdx === -1) return { value: env.value, next: env.next };
21944
+ const body = convertLatexFragment(input.slice(env.next, endIdx), depth + 1);
21945
+ if (env.value === "matrix" || env.value === "pmatrix" || env.value === "bmatrix") {
21946
+ return { value: `{${env.value}{${body}}}`, next: endIdx + endTag.length };
21947
+ }
21948
+ return { value: body, next: endIdx + endTag.length };
21949
+ }
21950
+ if (command === "left" || command === "right") {
21951
+ const kw = command === "left" ? "LEFT" : "RIGHT";
21952
+ const cursor = skipSpaces(input, name.next);
21953
+ let delimiter = input[cursor] ?? "";
21954
+ let next = delimiter ? cursor + 1 : cursor;
21955
+ if (delimiter === "\\") {
21956
+ const escaped = readCommandName(input, cursor);
21957
+ delimiter = escaped.value === "\\" ? "\\" : COMMAND_MAP[escaped.value] ?? escaped.value;
21958
+ next = escaped.next;
21959
+ }
21960
+ return { value: delimiter ? `${kw} ${delimiter}` : kw, next };
21961
+ }
21962
+ if (command in ACCENT_COMMANDS) {
21963
+ const body = readGroupOrToken(input, name.next, depth);
21964
+ return { value: `${ACCENT_COMMANDS[command]}{${body.value}}`, next: body.next };
21965
+ }
21966
+ if (command === "mathrm" || command === "text") {
21967
+ const start = skipSpaces(input, name.next);
21968
+ if (input[start] === "{") {
21969
+ const group = readBalanced(input, start, "{", "}");
21970
+ return { value: `"${group.value}"`, next: group.next };
21971
+ }
21972
+ const tok = readGroupOrToken(input, start, depth);
21973
+ return { value: `"${tok.value}"`, next: tok.next };
21974
+ }
21975
+ return { value: COMMAND_MAP[command] ?? command, next: name.next };
21976
+ }
21977
+ function convertLatexFragment(input, depth) {
21978
+ if (depth > MAX_GROUP_DEPTH) return normalizeEqEdit(input);
21979
+ let out = "";
21980
+ let idx = 0;
21981
+ while (idx < input.length) {
21982
+ const ch = input[idx];
21983
+ if (ch === "\\") {
21984
+ const cmd = readCommand(input, idx, depth + 1);
21985
+ out += ` ${cmd.value} `;
21986
+ idx = cmd.next;
21987
+ continue;
21988
+ }
21989
+ if (ch === "{") {
21990
+ const group = readBalanced(input, idx, "{", "}");
21991
+ out += `{${convertLatexFragment(group.value, depth + 1)}}`;
21992
+ idx = group.next;
21993
+ continue;
21994
+ }
21995
+ if (ch === "_" || ch === "^") {
21996
+ const script = readGroupOrToken(input, idx + 1, depth);
21997
+ out += ` ${ch}{${script.value}}`;
21998
+ idx = script.next;
21999
+ continue;
22000
+ }
22001
+ if (ch === "&") {
22002
+ out += " & ";
22003
+ idx++;
22004
+ continue;
22005
+ }
22006
+ out += ch;
22007
+ idx++;
22008
+ }
22009
+ return normalizeEqEdit(out);
22010
+ }
22011
+ function quoteReservedKeywords(latex) {
22012
+ return latex.replace(/([_^])\s*\{\s*([A-Za-z]+)\s*\}/g, (match, op, word) => RESERVED_WORDS.has(word) ? `${op}{"${word}"}` : match);
22013
+ }
22014
+ function latexLikeToEqEdit(input) {
22015
+ const src = stripMathDelimiters(input);
22016
+ if (src.length > MAX_EQUATION_SOURCE) return normalizeEqEdit(src);
22017
+ return convertLatexFragment(quoteReservedKeywords(src), 0);
22018
+ }
22019
+ function estimateEquationMetrics(script) {
22020
+ const cleaned = script.replace(/[{}\\^_]/g, "").replace(/\s+/g, " ").trim();
22021
+ const width = Math.min(Math.max(cleaned.length, 5) * 700 + 2e3, 4e4);
22022
+ const rowCount = Math.max(1, (script.match(/#/g) ?? []).length + 1);
22023
+ if (/\bmatrix\b|#/.test(script)) {
22024
+ if (rowCount >= 4) return { width, height: 5500, baseline: 55 };
22025
+ if (rowCount === 3) return { width, height: 4500, baseline: 60 };
22026
+ return { width, height: 3260, baseline: 63 };
22027
+ }
22028
+ if (/\bover\b|\broot\b|\bsqrt\b/.test(script)) return { width, height: 3010, baseline: 69 };
22029
+ return { width, height: 1450, baseline: 71 };
22030
+ }
22031
+ function generateEquationXml(script, zOrder = 0) {
22032
+ const { width, height, baseline } = estimateEquationMetrics(script);
22033
+ const eqId = 2000000001 + zOrder;
22034
+ 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>`;
22035
+ }
22036
+ function generateEquationParagraph(input, zOrder = 0) {
22037
+ const script = latexLikeToEqEdit(input);
22038
+ return `<hp:p paraPrIDRef="${PARA_NORMAL}" styleIDRef="0"><hp:run charPrIDRef="${CHAR_NORMAL}">${generateEquationXml(script, zOrder)}</hp:run></hp:p>`;
22039
+ }
22040
+
21678
22041
  // src/hwpx/gen-section.ts
21679
22042
  function generateSecPr(gongmun) {
21680
22043
  const m = gongmun ? {
@@ -21685,7 +22048,7 @@ function generateSecPr(gongmun) {
21685
22048
  header: 0,
21686
22049
  footer: 0
21687
22050
  } : { top: 8504, bottom: 4252, left: 5670, right: 4252, header: 2835, footer: 2835 };
21688
- return `<hp:secPr textDirection="HORIZONTAL" spaceColumns="1134" tabStop="8000" outlineShapeIDRef="0" memoShapeIDRef="0" textVerticalWidthHead="0" masterPageCnt="0"><hp:grid lineGrid="0" charGrid="0" wonggojiFormat="0"/><hp:startNum pageStartsOn="BOTH" page="0" pic="0" tbl="0" equation="0"/><hp:visibility hideFirstHeader="0" hideFirstFooter="0" hideFirstMasterPage="0" border="SHOW_ALL" fill="SHOW_ALL" hideFirstPageNum="0" hideFirstEmptyLine="0" showLineNumber="0"/><hp:pagePr landscape="WIDELY" width="59528" height="84188" gutterType="LEFT_ONLY"><hp:margin header="${m.header}" footer="${m.footer}" gutter="0" left="${m.left}" right="${m.right}" top="${m.top}" bottom="${m.bottom}"/></hp:pagePr><hp:footNotePr><hp:autoNumFormat type="DIGIT" userChar="" prefixChar="" suffixChar=")" supscript="0"/><hp:noteLine length="-1" type="SOLID" width="0.12 mm" color="#000000"/><hp:noteSpacing betweenNotes="283" belowLine="567" aboveLine="850"/><hp:numbering type="CONTINUOUS" newNum="1"/><hp:placement place="EACH_COLUMN" beneathText="0"/></hp:footNotePr><hp:endNotePr><hp:autoNumFormat type="DIGIT" userChar="" prefixChar="" suffixChar=")" supscript="0"/><hp:noteLine length="14692344" type="SOLID" width="0.12 mm" color="#000000"/><hp:noteSpacing betweenNotes="0" belowLine="567" aboveLine="850"/><hp:numbering type="CONTINUOUS" newNum="1"/><hp:placement place="END_OF_DOCUMENT" beneathText="0"/></hp:endNotePr></hp:secPr>`;
22051
+ return `<hp:secPr textDirection="HORIZONTAL" spaceColumns="1134" tabStop="8000" outlineShapeIDRef="1" memoShapeIDRef="0" textVerticalWidthHead="0" masterPageCnt="0"><hp:grid lineGrid="0" charGrid="0" wonggojiFormat="0"/><hp:startNum pageStartsOn="BOTH" page="0" pic="0" tbl="0" equation="0"/><hp:visibility hideFirstHeader="0" hideFirstFooter="0" hideFirstMasterPage="0" border="SHOW_ALL" fill="SHOW_ALL" hideFirstPageNum="0" hideFirstEmptyLine="0" showLineNumber="0"/><hp:pagePr landscape="WIDELY" width="59528" height="84188" gutterType="LEFT_ONLY"><hp:margin header="${m.header}" footer="${m.footer}" gutter="0" left="${m.left}" right="${m.right}" top="${m.top}" bottom="${m.bottom}"/></hp:pagePr><hp:footNotePr><hp:autoNumFormat type="DIGIT" userChar="" prefixChar="" suffixChar=")" supscript="0"/><hp:noteLine length="-1" type="SOLID" width="0.12 mm" color="#000000"/><hp:noteSpacing betweenNotes="283" belowLine="567" aboveLine="850"/><hp:numbering type="CONTINUOUS" newNum="1"/><hp:placement place="EACH_COLUMN" beneathText="0"/></hp:footNotePr><hp:endNotePr><hp:autoNumFormat type="DIGIT" userChar="" prefixChar="" suffixChar=")" supscript="0"/><hp:noteLine length="14692344" type="SOLID" width="0.12 mm" color="#000000"/><hp:noteSpacing betweenNotes="0" belowLine="567" aboveLine="850"/><hp:numbering type="CONTINUOUS" newNum="1"/><hp:placement place="END_OF_DOCUMENT" beneathText="0"/></hp:endNotePr></hp:secPr>`;
21689
22052
  }
21690
22053
  function blocksToSectionXml(blocks, theme, gongmun, gongmunList = gongmun ? precomputeGongmunList(blocks, gongmun) : null, fit = null) {
21691
22054
  const paraXmls = [];
@@ -21722,6 +22085,15 @@ function blocksToSectionXml(blocks, theme, gongmun, gongmunList = gongmun ? prec
21722
22085
  xml = codeLines.map((line) => generateParagraph(line || " ", PARA_CODE)).join("\n ");
21723
22086
  break;
21724
22087
  }
22088
+ case "equation": {
22089
+ if (isFirst) {
22090
+ const secRun = `<hp:run charPrIDRef="0">${generateSecPr(gongmun)}<hp:t></hp:t></hp:run>`;
22091
+ paraXmls.push(`<hp:p paraPrIDRef="0" styleIDRef="0">${secRun}</hp:p>`);
22092
+ isFirst = false;
22093
+ }
22094
+ xml = generateEquationParagraph(block.text || "", blockIdx);
22095
+ break;
22096
+ }
21725
22097
  case "blockquote":
21726
22098
  xml = generateParagraph(
21727
22099
  block.text || "",
@@ -21742,7 +22114,10 @@ function blocksToSectionXml(blocks, theme, gongmun, gongmunList = gongmun ? prec
21742
22114
  }
21743
22115
  const indent = block.indent || 0;
21744
22116
  let marker;
21745
- if (block.ordered) {
22117
+ if (block.marker) {
22118
+ marker = `${block.marker} `;
22119
+ prevWasOrdered = !!block.ordered;
22120
+ } else if (block.ordered) {
21746
22121
  orderedCounters[indent] = (orderedCounters[indent] || 0) + 1;
21747
22122
  for (const k of Object.keys(orderedCounters)) {
21748
22123
  if (+k > indent) delete orderedCounters[+k];
@@ -24550,7 +24925,7 @@ async function parseHwp(buffer, options) {
24550
24925
  async function parsePdf(buffer, options) {
24551
24926
  let parsePdfDocument;
24552
24927
  try {
24553
- const mod = await import("./parser-TM3AS25T.js");
24928
+ const mod = await import("./parser-NCNME2Z6.js");
24554
24929
  parsePdfDocument = mod.parsePdfDocument;
24555
24930
  } catch {
24556
24931
  return {