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.
@@ -25,7 +25,7 @@ import {
25
25
  sanitizeHref,
26
26
  stripDtd,
27
27
  toArrayBuffer
28
- } from "./chunk-KIWKBRCJ.js";
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);
@@ -905,14 +911,14 @@ function resolveParaHeading(paraEl, ctx) {
905
911
  const head = numDef.heads.get(level);
906
912
  counters[level] = counters[level] === 0 ? head?.start ?? 1 : counters[level] + 1;
907
913
  for (let l = level + 1; l <= 10; l++) counters[l] = 0;
908
- const fmtText = head?.text?.trim() || `^${level}.`;
914
+ const fmtText = head ? head.text.trim() : `^${level}.`;
909
915
  const prefix = fmtText.replace(/\^(10|[1-9])/g, (_, d) => {
910
916
  const lv = parseInt(d, 10);
911
917
  const refHead = numDef.heads.get(lv);
912
918
  const n = counters[lv] || refHead?.start || 1;
913
919
  return formatHeadNumber(n, refHead?.numFormat || "DIGIT");
914
920
  });
915
- return { prefix, headingLevel };
921
+ return { prefix: prefix || void 0, headingLevel };
916
922
  }
917
923
 
918
924
  // src/hwpx/table-build.ts
@@ -18091,74 +18097,79 @@ function parseParagraph2(p, styles, numbering, footnotes, rels) {
18091
18097
  if (footnoteText) block.footnoteText = footnoteText;
18092
18098
  return block;
18093
18099
  }
18100
+ function collectTextboxParagraphs(node, inTxbx = false, out = [], depth = 0) {
18101
+ if (depth > 40) return out;
18102
+ for (const el of effectiveChildElements(node)) {
18103
+ if (matchesLocal(el, "Fallback")) continue;
18104
+ const nowIn = inTxbx || matchesLocal(el, "txbxContent");
18105
+ if (nowIn && matchesLocal(el, "p")) out.push(el);
18106
+ collectTextboxParagraphs(el, nowIn, out, depth + 1);
18107
+ }
18108
+ return out;
18109
+ }
18094
18110
  function parseTable(tbl, styles, numbering, footnotes, rels) {
18095
18111
  const trElements = getChildElements(tbl, "tr");
18096
18112
  if (trElements.length === 0) return null;
18097
- const rows = [];
18098
- let maxCols = 0;
18113
+ const rawRows = [];
18099
18114
  for (const tr of trElements) {
18100
- const tcElements = getChildElements(tr, "tc");
18101
18115
  const row = [];
18102
- for (const tc of tcElements) {
18116
+ let col = 0;
18117
+ for (const tc of getChildElements(tr, "tc")) {
18103
18118
  let colSpan = 1;
18104
- let rowSpan = 1;
18119
+ let vMerge = null;
18105
18120
  const tcPrEls = getChildElements(tc, "tcPr");
18106
18121
  if (tcPrEls.length > 0) {
18107
18122
  const gridSpanEls = getChildElements(tcPrEls[0], "gridSpan");
18108
18123
  if (gridSpanEls.length > 0) {
18109
- colSpan = parseInt(getAttr(gridSpanEls[0], "val") ?? "1", 10);
18124
+ colSpan = parseInt(getAttr(gridSpanEls[0], "val") ?? "1", 10) || 1;
18110
18125
  }
18111
18126
  const vMergeEls = getChildElements(tcPrEls[0], "vMerge");
18112
18127
  if (vMergeEls.length > 0) {
18113
- const val = getAttr(vMergeEls[0], "val");
18114
- if (val !== "restart" && val !== null) {
18115
- row.push({ text: "", colSpan, rowSpan: 0 });
18116
- continue;
18117
- }
18128
+ vMerge = getAttr(vMergeEls[0], "val") === "restart" ? "restart" : "continue";
18129
+ }
18130
+ }
18131
+ const text = vMerge === "continue" ? "" : collectCellText(tc, styles, numbering, footnotes, rels, 0).join("\n");
18132
+ row.push({ col, colSpan, vMerge, text });
18133
+ col += colSpan;
18134
+ }
18135
+ rawRows.push(row);
18136
+ }
18137
+ const cellRows = rawRows.map(
18138
+ (row, r) => row.filter((cell) => cell.vMerge !== "continue").map((cell) => {
18139
+ let rowSpan = 1;
18140
+ if (cell.vMerge === "restart") {
18141
+ for (let nr = r + 1; nr < rawRows.length; nr++) {
18142
+ if (!rawRows[nr].some((nc) => nc.col === cell.col && nc.vMerge === "continue")) break;
18143
+ rowSpan++;
18118
18144
  }
18119
18145
  }
18120
- const cellTexts = [];
18121
- const pElements = getChildElements(tc, "p");
18122
- for (const p of pElements) {
18123
- const block = parseParagraph2(p, styles, numbering, footnotes, rels);
18124
- if (block?.text) cellTexts.push(block.text);
18146
+ return { text: cell.text, colSpan: cell.colSpan, rowSpan, colAddr: cell.col, rowAddr: r };
18147
+ })
18148
+ );
18149
+ const table = buildTable(cellRows);
18150
+ if (table.rows === 0 || table.cols === 0) return null;
18151
+ return { type: "table", table };
18152
+ }
18153
+ function collectCellText(tc, styles, numbering, footnotes, rels, depth) {
18154
+ const parts = [];
18155
+ if (depth > 20) return parts;
18156
+ for (const el of effectiveChildElements(tc)) {
18157
+ if (matchesLocal(el, "p")) {
18158
+ const block = parseParagraph2(el, styles, numbering, footnotes, rels);
18159
+ if (block?.text) parts.push(block.text);
18160
+ for (const tp of collectTextboxParagraphs(el)) {
18161
+ const tb = parseParagraph2(tp, styles, numbering, footnotes, rels);
18162
+ if (tb?.text) parts.push(tb.text);
18125
18163
  }
18126
- row.push({ text: cellTexts.join("\n"), colSpan, rowSpan });
18127
- }
18128
- rows.push(row);
18129
- if (row.length > maxCols) maxCols = row.length;
18130
- }
18131
- for (let c = 0; c < maxCols; c++) {
18132
- for (let r = 0; r < rows.length; r++) {
18133
- const cell = rows[r][c];
18134
- if (!cell || cell.rowSpan === 0) continue;
18135
- let span = 1;
18136
- for (let nr = r + 1; nr < rows.length; nr++) {
18137
- if (rows[nr][c]?.rowSpan === 0) span++;
18138
- else break;
18164
+ } else if (matchesLocal(el, "tbl")) {
18165
+ for (const tr of getChildElements(el, "tr")) {
18166
+ for (const nestedTc of getChildElements(tr, "tc")) {
18167
+ parts.push(...collectCellText(nestedTc, styles, numbering, footnotes, rels, depth + 1));
18168
+ }
18139
18169
  }
18140
- cell.rowSpan = span;
18141
18170
  }
18142
18171
  }
18143
- const cleanRows = [];
18144
- for (const row of rows) {
18145
- const clean = row.filter((cell) => cell.rowSpan !== 0);
18146
- cleanRows.push(clean);
18147
- }
18148
- if (cleanRows.length === 0) return null;
18149
- let cols = 0;
18150
- for (const row of cleanRows) {
18151
- let c = 0;
18152
- for (const cell of row) c += cell.colSpan;
18153
- if (c > cols) cols = c;
18154
- }
18155
- const table = {
18156
- rows: cleanRows.length,
18157
- cols,
18158
- cells: cleanRows,
18159
- hasHeader: cleanRows.length > 1
18160
- };
18161
- return { type: "table", table };
18172
+ return parts;
18162
18173
  }
18163
18174
  async function extractImages(zip, rels, doc, warnings) {
18164
18175
  const blocks = [];
@@ -18264,6 +18275,10 @@ async function parseDocxDocument(buffer, options) {
18264
18275
  if (localName2 === "p") {
18265
18276
  const block = parseParagraph2(el, styles, numbering, footnotes, rels);
18266
18277
  if (block) blocks.push(block);
18278
+ for (const tp of collectTextboxParagraphs(el)) {
18279
+ const tb = parseParagraph2(tp, styles, numbering, footnotes, rels);
18280
+ if (tb) blocks.push(tb);
18281
+ }
18267
18282
  } else if (localName2 === "tbl") {
18268
18283
  const block = parseTable(el, styles, numbering, footnotes, rels);
18269
18284
  if (block) blocks.push(block);
@@ -18521,10 +18536,10 @@ function parseTable2(el, blocks, paraShapeMap, sectionNum, warnings) {
18521
18536
  }
18522
18537
  function extractCellText(cellEl) {
18523
18538
  const textParts = [];
18524
- collectCellText(cellEl, textParts, 0);
18539
+ collectCellText2(cellEl, textParts, 0);
18525
18540
  return textParts.filter(Boolean).join("\n").trim();
18526
18541
  }
18527
- function collectCellText(node, parts, depth) {
18542
+ function collectCellText2(node, parts, depth) {
18528
18543
  if (depth > 20) return;
18529
18544
  const children = node.childNodes;
18530
18545
  for (let i = 0; i < children.length; i++) {
@@ -18536,9 +18551,9 @@ function collectCellText(node, parts, depth) {
18536
18551
  if (t) parts.push(t);
18537
18552
  collectNestedTableText(el, parts, depth + 1);
18538
18553
  } else if (tag === "TABLE") {
18539
- collectCellText(el, parts, depth + 1);
18554
+ collectCellText2(el, parts, depth + 1);
18540
18555
  } else {
18541
- collectCellText(el, parts, depth + 1);
18556
+ collectCellText2(el, parts, depth + 1);
18542
18557
  }
18543
18558
  }
18544
18559
  }
@@ -18550,7 +18565,7 @@ function collectNestedTableText(node, parts, depth) {
18550
18565
  if (el.nodeType !== 1) continue;
18551
18566
  const tag = localName(el);
18552
18567
  if (tag === "TABLE") {
18553
- collectCellText(el, parts, depth + 1);
18568
+ collectCellText2(el, parts, depth + 1);
18554
18569
  continue;
18555
18570
  }
18556
18571
  if (tag === "FOOTNOTE" || tag === "ENDNOTE" || tag === "HEADER" || tag === "FOOTER") continue;
@@ -20509,12 +20524,13 @@ function charPr(id, height, bold, italic, fontId = 0, textColor = DEFAULT_TEXT_C
20509
20524
  </hh:charPr>`;
20510
20525
  }
20511
20526
  function paraPr(id, opts = {}) {
20512
- const { align = "JUSTIFY", spaceBefore = 0, spaceAfter = 0, lineSpacing = 160, indent = 0, left = 0, keepWord = false } = opts;
20527
+ const { align = "JUSTIFY", spaceBefore = 0, spaceAfter = 0, lineSpacing = 160, indent = 0, left = 0, keepWord = false, outlineLevel } = opts;
20513
20528
  const breakNonLatin = keepWord ? "KEEP_WORD" : "BREAK_WORD";
20514
20529
  const snapGrid = keepWord ? "0" : "1";
20530
+ const heading = outlineLevel !== void 0 ? `<hh:heading type="OUTLINE" idRef="0" level="${outlineLevel}"/>` : `<hh:heading type="NONE" idRef="0" level="0"/>`;
20515
20531
  return ` <hh:paraPr id="${id}" tabPrIDRef="0" condense="0" fontLineHeight="0" snapToGrid="${snapGrid}" suppressLineNumbers="0" checked="0" textDir="AUTO">
20516
20532
  <hh:align horizontal="${align}" vertical="BASELINE"/>
20517
- <hh:heading type="NONE" idRef="0" level="0"/>
20533
+ ${heading}
20518
20534
  <hh:breakSetting breakLatinWord="KEEP_WORD" breakNonLatinWord="${breakNonLatin}" widowOrphan="0" keepWithNext="0" keepLines="0" pageBreakBefore="0" lineWrap="BREAK"/>
20519
20535
  <hh:autoSpacing eAsianEng="0" eAsianNum="0"/>
20520
20536
  <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>
@@ -20542,6 +20558,16 @@ function buildPrvText(blocks) {
20542
20558
  }
20543
20559
  return lines.join("\n").slice(0, 1024);
20544
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
+ }
20545
20571
  function parseMarkdownToBlocks(md2) {
20546
20572
  const lines = md2.split("\n");
20547
20573
  const blocks = [];
@@ -20552,6 +20578,45 @@ function parseMarkdownToBlocks(md2) {
20552
20578
  i++;
20553
20579
  continue;
20554
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
+ }
20555
20620
  const fenceMatch = line.match(/^(`{3,}|~{3,})(.*)$/);
20556
20621
  if (fenceMatch) {
20557
20622
  const fence = fenceMatch[1];
@@ -20621,7 +20686,7 @@ function parseMarkdownToBlocks(md2) {
20621
20686
  if (listMatch) {
20622
20687
  const indent = Math.floor(listMatch[1].length / 2);
20623
20688
  const ordered = /\d/.test(listMatch[2]);
20624
- blocks.push({ type: "list_item", text: listMatch[3].trim(), ordered, indent });
20689
+ blocks.push({ type: "list_item", text: listMatch[3].trim(), ordered, indent, marker: listMatch[2] });
20625
20690
  i++;
20626
20691
  continue;
20627
20692
  }
@@ -20631,6 +20696,11 @@ function parseMarkdownToBlocks(md2) {
20631
20696
  return blocks;
20632
20697
  }
20633
20698
  function parseInlineMarkdown(text) {
20699
+ const literals = [];
20700
+ text = text.replace(/\x00/g, "").replace(/\\([\\`*_{}[\]()#+\-.!|>~])/g, (_, c) => {
20701
+ literals.push(c);
20702
+ return `\0${literals.length - 1}\0`;
20703
+ });
20634
20704
  text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1");
20635
20705
  text = text.replace(/\[([^\]]*)\]\(([^)]*)\)/g, (_, t, u) => t || u);
20636
20706
  text = text.replace(/~~([^~]+)~~/g, "$1");
@@ -20660,6 +20730,13 @@ function parseInlineMarkdown(text) {
20660
20730
  if (spans.length === 0) {
20661
20731
  spans.push({ text, bold: false, italic: false, code: false });
20662
20732
  }
20733
+ for (const span of spans) {
20734
+ if (!span.text.includes("\0")) continue;
20735
+ span.text = span.text.replace(/\x00(\d+)\x00/g, (_, i) => {
20736
+ const c = literals[+i] ?? "";
20737
+ return span.code ? "\\" + c : c;
20738
+ });
20739
+ }
20663
20740
  return spans;
20664
20741
  }
20665
20742
  function spanToCharPrId(span) {
@@ -20747,10 +20824,10 @@ function buildParaProperties(gongmun) {
20747
20824
  if (!gongmun) {
20748
20825
  const base2 = [
20749
20826
  paraPr(0),
20750
- paraPr(1, { align: "LEFT", spaceBefore: 800, spaceAfter: 200, lineSpacing: 180 }),
20751
- paraPr(2, { align: "LEFT", spaceBefore: 600, spaceAfter: 150, lineSpacing: 170 }),
20752
- paraPr(3, { align: "LEFT", spaceBefore: 400, spaceAfter: 100, lineSpacing: 160 }),
20753
- paraPr(4, { align: "LEFT", spaceBefore: 300, spaceAfter: 100, lineSpacing: 160 }),
20827
+ paraPr(1, { align: "LEFT", spaceBefore: 800, spaceAfter: 200, lineSpacing: 180, outlineLevel: 0 }),
20828
+ paraPr(2, { align: "LEFT", spaceBefore: 600, spaceAfter: 150, lineSpacing: 170, outlineLevel: 1 }),
20829
+ paraPr(3, { align: "LEFT", spaceBefore: 400, spaceAfter: 100, lineSpacing: 160, outlineLevel: 2 }),
20830
+ paraPr(4, { align: "LEFT", spaceBefore: 300, spaceAfter: 100, lineSpacing: 160, outlineLevel: 3 }),
20754
20831
  paraPr(5, { align: "LEFT", lineSpacing: 130, indent: 400 }),
20755
20832
  paraPr(6, { align: "LEFT", lineSpacing: 150, indent: 600 }),
20756
20833
  paraPr(7, { align: "LEFT", lineSpacing: 160, indent: 600 })
@@ -20763,10 +20840,10 @@ ${base2.join("\n")}
20763
20840
  const titleAlign = gongmun.centerTitle ? "CENTER" : "LEFT";
20764
20841
  const base = [
20765
20842
  paraPr(0, { lineSpacing: ls, keepWord: true }),
20766
- paraPr(1, { align: titleAlign, spaceBefore: 400, spaceAfter: 400, lineSpacing: ls, keepWord: true }),
20767
- paraPr(2, { align: "LEFT", spaceBefore: 600, spaceAfter: 150, lineSpacing: ls, keepWord: true }),
20768
- paraPr(3, { align: "LEFT", spaceBefore: 400, spaceAfter: 100, lineSpacing: ls, keepWord: true }),
20769
- paraPr(4, { align: "LEFT", spaceBefore: 300, spaceAfter: 100, lineSpacing: ls, keepWord: true }),
20843
+ paraPr(1, { align: titleAlign, spaceBefore: 400, spaceAfter: 400, lineSpacing: ls, keepWord: true, outlineLevel: 0 }),
20844
+ paraPr(2, { align: "LEFT", spaceBefore: 600, spaceAfter: 150, lineSpacing: ls, keepWord: true, outlineLevel: 1 }),
20845
+ paraPr(3, { align: "LEFT", spaceBefore: 400, spaceAfter: 100, lineSpacing: ls, keepWord: true, outlineLevel: 2 }),
20846
+ paraPr(4, { align: "LEFT", spaceBefore: 300, spaceAfter: 100, lineSpacing: ls, keepWord: true, outlineLevel: 3 }),
20770
20847
  paraPr(5, { align: "LEFT", lineSpacing: 130, indent: 400, keepWord: true }),
20771
20848
  paraPr(6, { align: "LEFT", lineSpacing: ls, indent: 600, keepWord: true }),
20772
20849
  paraPr(7, { align: "LEFT", lineSpacing: ls, indent: 600, keepWord: true })
@@ -20781,6 +20858,17 @@ ${base2.join("\n")}
20781
20858
  ${base.join("\n")}
20782
20859
  </hh:paraProperties>`;
20783
20860
  }
20861
+ function buildNumberings() {
20862
+ const heads = Array.from(
20863
+ { length: 7 },
20864
+ (_, 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"/>`
20865
+ ).join("\n");
20866
+ return `<hh:numberings itemCnt="1">
20867
+ <hh:numbering id="1" start="0">
20868
+ ${heads}
20869
+ </hh:numbering>
20870
+ </hh:numberings>`;
20871
+ }
20784
20872
  function generateHeaderXml(theme, gongmun, ratioVariants = []) {
20785
20873
  const bodyFace = gongmun?.bodyFont === "gothic" ? "\uB9D1\uC740 \uACE0\uB515" : "\uD568\uCD08\uB86C\uBC14\uD0D5";
20786
20874
  const charPropsXml = buildCharProperties(theme, gongmun, ratioVariants);
@@ -20858,7 +20946,7 @@ function generateHeaderXml(theme, gongmun, ratioVariants = []) {
20858
20946
  </hh:borderFills>
20859
20947
  ${charPropsXml}
20860
20948
  <hh:tabProperties itemCnt="0"/>
20861
- <hh:numberings itemCnt="0"/>
20949
+ ${buildNumberings()}
20862
20950
  <hh:bullets itemCnt="0"/>
20863
20951
  ${paraPropsXml}
20864
20952
  <hh:styles itemCnt="1">
@@ -20921,6 +21009,7 @@ function precomputeGongmunList(blocks, gongmun) {
20921
21009
  i++;
20922
21010
  continue;
20923
21011
  }
21012
+ const passThrough = (t) => t === "table" || t === "html_table" || t === "equation";
20924
21013
  const run = [];
20925
21014
  while (i < blocks.length) {
20926
21015
  const t = blocks[i].type;
@@ -20929,9 +21018,9 @@ function precomputeGongmunList(blocks, gongmun) {
20929
21018
  i++;
20930
21019
  continue;
20931
21020
  }
20932
- if (t === "table" || t === "html_table") {
21021
+ if (passThrough(t)) {
20933
21022
  let j = i + 1;
20934
- while (j < blocks.length && (blocks[j].type === "table" || blocks[j].type === "html_table")) j++;
21023
+ while (j < blocks.length && passThrough(blocks[j].type)) j++;
20935
21024
  if (j < blocks.length && blocks[j].type === "list_item") {
20936
21025
  i = j;
20937
21026
  continue;
@@ -21123,7 +21212,7 @@ function bestSimInRange(arr, from, to, target) {
21123
21212
  return best;
21124
21213
  }
21125
21214
  function escapeGfm(text) {
21126
- return text.replace(/~/g, "\\~");
21215
+ return text.replace(/([~*])/g, "\\$1");
21127
21216
  }
21128
21217
  var HWP_SHAPE_ALT_TEXT_RE = /(?:모서리가 둥근 |둥근 )?(?:사각형|직사각형|정사각형|원|타원|삼각형|이등변 삼각형|직각 삼각형|선|직선|곡선|화살표|굵은 화살표|이중 화살표|오각형|육각형|팔각형|별|[4-8]점별|십자|십자형|구름|구름형|마름모|도넛|평행사변형|사다리꼴|부채꼴|호|반원|물결|번개|하트|빗금|블록 화살표|수식|표|그림|개체|그리기\s?개체|묶음\s?개체|글상자|수식\s?개체|OLE\s?개체)\s?입니다\.?/g;
21129
21218
  function sanitizeText(text) {
@@ -21141,7 +21230,7 @@ function normForMatch(text) {
21141
21230
  return sanitizeText(text).replace(/\s+/g, " ").trim();
21142
21231
  }
21143
21232
  function unescapeGfm(text) {
21144
- return text.replace(/\\~/g, "~");
21233
+ return text.replace(/\\([~*])/g, "$1");
21145
21234
  }
21146
21235
  function summarize(text) {
21147
21236
  const t = text.replace(/\s+/g, " ").trim();
@@ -21208,7 +21297,7 @@ function parseGfmTable(lines) {
21208
21297
  return rows;
21209
21298
  }
21210
21299
  function unescapeGfmCell(text) {
21211
- return text.replace(/<br\s*\/?>/gi, "\n").replace(/\\\|/g, "|").replace(/\\~/g, "~");
21300
+ return text.replace(/<br\s*\/?>/gi, "\n").replace(/\\\|/g, "|").replace(/\\([~*])/g, "$1");
21212
21301
  }
21213
21302
  function replicateCellInnerHtml(cell) {
21214
21303
  if (cell.blocks?.length) {
@@ -21457,6 +21546,280 @@ function generateHtmlTableXml(rawHtml, theme, totalWidth = 44e3) {
21457
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>`;
21458
21547
  }
21459
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
+
21460
21823
  // src/hwpx/gen-section.ts
21461
21824
  function generateSecPr(gongmun) {
21462
21825
  const m = gongmun ? {
@@ -21467,7 +21830,7 @@ function generateSecPr(gongmun) {
21467
21830
  header: 0,
21468
21831
  footer: 0
21469
21832
  } : { top: 8504, bottom: 4252, left: 5670, right: 4252, header: 2835, footer: 2835 };
21470
- 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>`;
21833
+ 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>`;
21471
21834
  }
21472
21835
  function blocksToSectionXml(blocks, theme, gongmun, gongmunList = gongmun ? precomputeGongmunList(blocks, gongmun) : null, fit = null) {
21473
21836
  const paraXmls = [];
@@ -21504,6 +21867,15 @@ function blocksToSectionXml(blocks, theme, gongmun, gongmunList = gongmun ? prec
21504
21867
  xml = codeLines.map((line) => generateParagraph(line || " ", PARA_CODE)).join("\n ");
21505
21868
  break;
21506
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
+ }
21507
21879
  case "blockquote":
21508
21880
  xml = generateParagraph(
21509
21881
  block.text || "",
@@ -21524,7 +21896,10 @@ function blocksToSectionXml(blocks, theme, gongmun, gongmunList = gongmun ? prec
21524
21896
  }
21525
21897
  const indent = block.indent || 0;
21526
21898
  let marker;
21527
- if (block.ordered) {
21899
+ if (block.marker) {
21900
+ marker = `${block.marker} `;
21901
+ prevWasOrdered = !!block.ordered;
21902
+ } else if (block.ordered) {
21528
21903
  orderedCounters[indent] = (orderedCounters[indent] || 0) + 1;
21529
21904
  for (const k of Object.keys(orderedCounters)) {
21530
21905
  if (+k > indent) delete orderedCounters[+k];
@@ -24332,7 +24707,7 @@ async function parseHwp(buffer, options) {
24332
24707
  async function parsePdf(buffer, options) {
24333
24708
  let parsePdfDocument;
24334
24709
  try {
24335
- const mod = await import("./parser-6GP535ZB.js");
24710
+ const mod = await import("./parser-LVI45MVF.js");
24336
24711
  parsePdfDocument = mod.parsePdfDocument;
24337
24712
  } catch {
24338
24713
  return {
@@ -24467,4 +24842,4 @@ export {
24467
24842
  parseHwpml,
24468
24843
  fillForm
24469
24844
  };
24470
- //# sourceMappingURL=chunk-B27QMVL7.js.map
24845
+ //# sourceMappingURL=chunk-ITPZD7XK.js.map