kordoc 2.2.0 → 2.2.2

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/cli.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  parse,
5
5
  sanitizeError,
6
6
  toArrayBuffer
7
- } from "./chunk-LYFG7AUT.js";
7
+ } from "./chunk-R34CFFNV.js";
8
8
  import {
9
9
  detectFormat
10
10
  } from "./chunk-5Y2Q3BRW.js";
@@ -105,7 +105,7 @@ program.name("kordoc").description("\uBAA8\uB450 \uD30C\uC2F1\uD574\uBC84\uB9AC\
105
105
  }
106
106
  });
107
107
  program.command("watch <dir>").description("\uB514\uB809\uD1A0\uB9AC \uAC10\uC2DC \u2014 \uC0C8 \uBB38\uC11C \uC790\uB3D9 \uBCC0\uD658").option("--webhook <url>", "\uACB0\uACFC \uC804\uC1A1 \uC6F9\uD6C5 URL").option("-d, --out-dir <dir>", "\uBCC0\uD658 \uACB0\uACFC \uCD9C\uB825 \uB514\uB809\uD1A0\uB9AC").option("-p, --pages <range>", "\uD398\uC774\uC9C0/\uC139\uC158 \uBC94\uC704").option("--format <type>", "\uCD9C\uB825 \uD615\uC2DD: markdown \uB610\uB294 json", "markdown").option("--silent", "\uC9C4\uD589 \uBA54\uC2DC\uC9C0 \uC228\uAE30\uAE30").action(async (dir, opts) => {
108
- const { watchDirectory } = await import("./watch-Q5OXA73S.js");
108
+ const { watchDirectory } = await import("./watch-VNJDVUVQ.js");
109
109
  await watchDirectory({
110
110
  dir,
111
111
  outDir: opts.outDir,
package/dist/index.cjs CHANGED
@@ -183,7 +183,7 @@ var import_zlib = require("zlib");
183
183
  var import_xmldom = require("@xmldom/xmldom");
184
184
 
185
185
  // src/utils.ts
186
- var VERSION = true ? "2.2.0" : "0.0.0-dev";
186
+ var VERSION = true ? "2.2.2" : "0.0.0-dev";
187
187
  function toArrayBuffer(buf) {
188
188
  if (buf.byteOffset === 0 && buf.byteLength === buf.buffer.byteLength) {
189
189
  return buf.buffer;
@@ -372,9 +372,12 @@ function trimAndReturn(grid, numRows, maxCols) {
372
372
  }
373
373
  function convertTableToText(rows) {
374
374
  return rows.map(
375
- (row) => row.map((c) => c.text.trim().replace(/\n/g, " ")).filter(Boolean).join(" | ")
375
+ (row) => row.map((c) => c.text.trim().replace(/\n/g, " ").replace(/\|/g, "\\|")).filter(Boolean).join(" / ")
376
376
  ).filter(Boolean).join("\n");
377
377
  }
378
+ function escapeGfm(text) {
379
+ return text.replace(/~/g, "\\~");
380
+ }
378
381
  var HWP_SHAPE_ALT_TEXT_RE = /(?:모서리가 둥근 |둥근 )?(?:사각형|직사각형|정사각형|원|타원|삼각형|이등변 삼각형|직각 삼각형|선|직선|곡선|화살표|굵은 화살표|이중 화살표|오각형|육각형|팔각형|별|[4-8]점별|십자|십자형|구름|구름형|마름모|도넛|평행사변형|사다리꼴|부채꼴|호|반원|물결|번개|하트|빗금|블록 화살표|수식|표|그림|개체|그리기\s?개체|묶음\s?개체|글상자|수식\s?개체|OLE\s?개체)\s?입니다\.?/g;
379
382
  function sanitizeText(text) {
380
383
  let result = text.replace(/[\u{F0000}-\u{FFFFD}]/gu, "").replace(HWP_SHAPE_ALT_TEXT_RE, "").replace(/ +/g, " ").trim();
@@ -484,7 +487,7 @@ function blocksToMarkdown(blocks) {
484
487
  if (block.footnoteText) {
485
488
  text += ` (\uC8FC: ${block.footnoteText})`;
486
489
  }
487
- lines.push(text);
490
+ lines.push(escapeGfm(text), "");
488
491
  } else if (block.type === "table" && block.table) {
489
492
  if (lines.length > 0 && lines[lines.length - 1] !== "") {
490
493
  lines.push("");
@@ -507,13 +510,13 @@ function tableToMarkdown(table) {
507
510
  return content.split(/\n/).map((line) => {
508
511
  const trimmed = line.trim();
509
512
  if (!trimmed) return "";
510
- if (/^\d+\.\s/.test(trimmed)) return `**${trimmed}**`;
511
- if (/^[가-힣]\.\s/.test(trimmed)) return ` ${trimmed}`;
512
- return trimmed;
513
+ if (/^\d+\.\s/.test(trimmed)) return `**${escapeGfm(trimmed)}**`;
514
+ if (/^[가-힣]\.\s/.test(trimmed)) return ` ${escapeGfm(trimmed)}`;
515
+ return escapeGfm(trimmed);
513
516
  }).filter(Boolean).join("\n");
514
517
  }
515
518
  if (numCols === 1 && numRows >= 2) {
516
- return cells.map((row) => sanitizeText(row[0].text).replace(/\n/g, " ")).filter(Boolean).join("\n");
519
+ return cells.map((row) => escapeGfm(sanitizeText(row[0].text)).replace(/\n/g, " ")).filter(Boolean).join("\n");
517
520
  }
518
521
  const display = Array.from({ length: numRows }, () => Array(numCols).fill(""));
519
522
  const skip = /* @__PURE__ */ new Set();
@@ -522,7 +525,7 @@ function tableToMarkdown(table) {
522
525
  if (skip.has(`${r},${c}`)) continue;
523
526
  const cell = cells[r]?.[c];
524
527
  if (!cell) continue;
525
- display[r][c] = sanitizeText(cell.text).replace(/\n/g, "<br>");
528
+ display[r][c] = escapeGfm(sanitizeText(cell.text)).replace(/\|/g, "\\|").replace(/\n/g, "<br>");
526
529
  for (let dr = 0; dr < cell.rowSpan; dr++) {
527
530
  for (let dc = 0; dc < cell.colSpan; dc++) {
528
531
  if (dr === 0 && dc === 0) continue;
@@ -6303,6 +6306,23 @@ var NS_HEAD = "http://www.hancom.co.kr/hwpml/2011/head";
6303
6306
  var NS_OPF = "http://www.idpf.org/2007/opf/";
6304
6307
  var NS_HPF = "http://www.hancom.co.kr/schema/2011/hpf";
6305
6308
  var NS_OCF = "urn:oasis:names:tc:opendocument:xmlns:container";
6309
+ var CHAR_NORMAL = 0;
6310
+ var CHAR_BOLD = 1;
6311
+ var CHAR_ITALIC = 2;
6312
+ var CHAR_BOLD_ITALIC = 3;
6313
+ var CHAR_CODE = 4;
6314
+ var CHAR_H1 = 5;
6315
+ var CHAR_H2 = 6;
6316
+ var CHAR_H3 = 7;
6317
+ var CHAR_H4 = 8;
6318
+ var PARA_NORMAL = 0;
6319
+ var PARA_H1 = 1;
6320
+ var PARA_H2 = 2;
6321
+ var PARA_H3 = 3;
6322
+ var PARA_H4 = 4;
6323
+ var PARA_CODE = 5;
6324
+ var PARA_QUOTE = 6;
6325
+ var PARA_LIST = 7;
6306
6326
  async function markdownToHwpx(markdown) {
6307
6327
  const blocks = parseMarkdownToBlocks(markdown);
6308
6328
  const sectionXml = blocksToSectionXml(blocks);
@@ -6324,6 +6344,25 @@ function parseMarkdownToBlocks(md) {
6324
6344
  i++;
6325
6345
  continue;
6326
6346
  }
6347
+ const fenceMatch = line.match(/^(`{3,}|~{3,})(.*)$/);
6348
+ if (fenceMatch) {
6349
+ const fence = fenceMatch[1];
6350
+ const lang = fenceMatch[2].trim();
6351
+ const codeLines = [];
6352
+ i++;
6353
+ while (i < lines.length && !lines[i].startsWith(fence)) {
6354
+ codeLines.push(lines[i]);
6355
+ i++;
6356
+ }
6357
+ if (i < lines.length) i++;
6358
+ blocks.push({ type: "code_block", text: codeLines.join("\n"), lang });
6359
+ continue;
6360
+ }
6361
+ if (/^(\*{3,}|-{3,}|_{3,})\s*$/.test(line.trim())) {
6362
+ blocks.push({ type: "hr" });
6363
+ i++;
6364
+ continue;
6365
+ }
6327
6366
  const headingMatch = line.match(/^(#{1,6})\s+(.+)$/);
6328
6367
  if (headingMatch) {
6329
6368
  blocks.push({ type: "heading", text: headingMatch[2].trim(), level: headingMatch[1].length });
@@ -6342,19 +6381,101 @@ function parseMarkdownToBlocks(md) {
6342
6381
  if (cells.length > 0) tableRows.push(cells);
6343
6382
  i++;
6344
6383
  }
6345
- if (tableRows.length > 0) {
6346
- blocks.push({ type: "table", rows: tableRows });
6384
+ if (tableRows.length > 0) blocks.push({ type: "table", rows: tableRows });
6385
+ continue;
6386
+ }
6387
+ if (line.trimStart().startsWith("> ")) {
6388
+ const quoteLines = [];
6389
+ while (i < lines.length && (lines[i].trimStart().startsWith("> ") || lines[i].trimStart().startsWith(">"))) {
6390
+ quoteLines.push(lines[i].replace(/^>\s?/, ""));
6391
+ i++;
6392
+ }
6393
+ for (const ql of quoteLines) {
6394
+ blocks.push({ type: "blockquote", text: ql.trim() || "" });
6347
6395
  }
6348
6396
  continue;
6349
6397
  }
6398
+ const listMatch = line.match(/^(\s*)([-*+]|\d+[.)]) (.+)$/);
6399
+ if (listMatch) {
6400
+ const indent = Math.floor(listMatch[1].length / 2);
6401
+ const ordered = /\d/.test(listMatch[2]);
6402
+ blocks.push({ type: "list_item", text: listMatch[3].trim(), ordered, indent });
6403
+ i++;
6404
+ continue;
6405
+ }
6350
6406
  blocks.push({ type: "paragraph", text: line.trim() });
6351
6407
  i++;
6352
6408
  }
6353
6409
  return blocks;
6354
6410
  }
6411
+ function parseInlineMarkdown(text) {
6412
+ text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1");
6413
+ text = text.replace(/\[([^\]]*)\]\(([^)]*)\)/g, (_, t, u) => t || u);
6414
+ text = text.replace(/~~([^~]+)~~/g, "$1");
6415
+ const spans = [];
6416
+ const regex = /(`[^`]+`|\*{3}[^*]+\*{3}|\*{2}[^*]+\*{2}|\*[^*]+\*|_{2}[^_]+_{2}|_[^_]+_)/g;
6417
+ let lastIdx = 0;
6418
+ for (const match of text.matchAll(regex)) {
6419
+ const idx = match.index;
6420
+ if (idx > lastIdx) {
6421
+ spans.push({ text: text.slice(lastIdx, idx), bold: false, italic: false, code: false });
6422
+ }
6423
+ const raw = match[0];
6424
+ if (raw.startsWith("`")) {
6425
+ spans.push({ text: raw.slice(1, -1), bold: false, italic: false, code: true });
6426
+ } else if (raw.startsWith("***") || raw.startsWith("___")) {
6427
+ spans.push({ text: raw.slice(3, -3), bold: true, italic: true, code: false });
6428
+ } else if (raw.startsWith("**") || raw.startsWith("__")) {
6429
+ spans.push({ text: raw.slice(2, -2), bold: true, italic: false, code: false });
6430
+ } else {
6431
+ spans.push({ text: raw.slice(1, -1), bold: false, italic: true, code: false });
6432
+ }
6433
+ lastIdx = idx + raw.length;
6434
+ }
6435
+ if (lastIdx < text.length) {
6436
+ spans.push({ text: text.slice(lastIdx), bold: false, italic: false, code: false });
6437
+ }
6438
+ if (spans.length === 0) {
6439
+ spans.push({ text, bold: false, italic: false, code: false });
6440
+ }
6441
+ return spans;
6442
+ }
6443
+ function spanToCharPrId(span) {
6444
+ if (span.code) return CHAR_CODE;
6445
+ if (span.bold && span.italic) return CHAR_BOLD_ITALIC;
6446
+ if (span.bold) return CHAR_BOLD;
6447
+ if (span.italic) return CHAR_ITALIC;
6448
+ return CHAR_NORMAL;
6449
+ }
6355
6450
  function escapeXml(text) {
6356
6451
  return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
6357
6452
  }
6453
+ function generateRuns(text, defaultCharPr = CHAR_NORMAL) {
6454
+ const spans = parseInlineMarkdown(text);
6455
+ return spans.map((span) => {
6456
+ const charId = span.code || span.bold || span.italic ? spanToCharPrId(span) : defaultCharPr;
6457
+ return `<hp:run charPrIDRef="${charId}"><hp:t>${escapeXml(span.text)}</hp:t></hp:run>`;
6458
+ }).join("");
6459
+ }
6460
+ function generateParagraph(text, paraPrId = PARA_NORMAL, charPrId = CHAR_NORMAL) {
6461
+ if (paraPrId === PARA_CODE) {
6462
+ return `<hp:p paraPrIDRef="${paraPrId}" styleIDRef="0"><hp:run charPrIDRef="${CHAR_CODE}"><hp:t>${escapeXml(text)}</hp:t></hp:run></hp:p>`;
6463
+ }
6464
+ const runs = generateRuns(text, charPrId);
6465
+ return `<hp:p paraPrIDRef="${paraPrId}" styleIDRef="0">${runs}</hp:p>`;
6466
+ }
6467
+ function headingParaPrId(level) {
6468
+ if (level === 1) return PARA_H1;
6469
+ if (level === 2) return PARA_H2;
6470
+ if (level === 3) return PARA_H3;
6471
+ return PARA_H4;
6472
+ }
6473
+ function headingCharPrId(level) {
6474
+ if (level === 1) return CHAR_H1;
6475
+ if (level === 2) return CHAR_H2;
6476
+ if (level === 3) return CHAR_H3;
6477
+ return CHAR_H4;
6478
+ }
6358
6479
  function generateContainerXml() {
6359
6480
  return `<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
6360
6481
  <ocf:container xmlns:ocf="${NS_OCF}" xmlns:hpf="${NS_HPF}">
@@ -6376,21 +6497,50 @@ function generateManifest() {
6376
6497
  </opf:spine>
6377
6498
  </opf:package>`;
6378
6499
  }
6500
+ function charPr(id, height, bold, italic, fontId = 0) {
6501
+ const boldAttr = bold ? ` bold="1"` : "";
6502
+ const italicAttr = italic ? ` italic="1"` : "";
6503
+ return ` <hh:charPr id="${id}" height="${height}" textColor="#000000" shadeColor="none" useFontSpace="0" useKerning="0" symMark="NONE" borderFillIDRef="0"${boldAttr}${italicAttr}>
6504
+ <hh:fontRef hangul="${fontId}" latin="${fontId}" hanja="${fontId}" japanese="${fontId}" other="${fontId}" symbol="${fontId}" user="${fontId}"/>
6505
+ <hh:ratio hangul="100" latin="100" hanja="100" japanese="100" other="100" symbol="100" user="100"/>
6506
+ <hh:spacing hangul="0" latin="0" hanja="0" japanese="0" other="0" symbol="0" user="0"/>
6507
+ <hh:relSz hangul="100" latin="100" hanja="100" japanese="100" other="100" symbol="100" user="100"/>
6508
+ <hh:offset hangul="0" latin="0" hanja="0" japanese="0" other="0" symbol="0" user="0"/>
6509
+ </hh:charPr>`;
6510
+ }
6511
+ function paraPr(id, opts = {}) {
6512
+ const { align = "JUSTIFY", spaceBefore = 0, spaceAfter = 0, lineSpacing = 160, indent = 0 } = opts;
6513
+ return ` <hh:paraPr id="${id}" tabPrIDRef="0" condense="0" fontLineHeight="0" snapToGrid="1" suppressLineNumbers="0" checked="0" textDir="AUTO">
6514
+ <hh:align horizontal="${align}" vertical="BASELINE"/>
6515
+ <hh:heading type="NONE" idRef="0" level="0"/>
6516
+ <hh:breakSetting breakLatinWord="KEEP_WORD" breakNonLatinWord="BREAK_WORD" widowOrphan="0" keepWithNext="0" keepLines="0" pageBreakBefore="0" lineWrap="BREAK"/>
6517
+ <hh:autoSpacing eAsianEng="0" eAsianNum="0"/>
6518
+ <hh:margin indent="${indent}" left="0" right="0" prev="${spaceBefore}" next="${spaceAfter}"/>
6519
+ <hh:lineSpacing type="PERCENT" value="${lineSpacing}"/>
6520
+ <hh:border borderFillIDRef="0" offsetLeft="0" offsetRight="0" offsetTop="0" offsetBottom="0" connect="0" ignoreMargin="0"/>
6521
+ </hh:paraPr>`;
6522
+ }
6379
6523
  function generateHeaderXml() {
6380
6524
  return `<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
6381
6525
  <hh:head xmlns:hh="${NS_HEAD}" xmlns:hp="${NS_PARA}" version="1.4" secCnt="1">
6382
6526
  <hh:beginNum page="1" footnote="1" endnote="1" pic="1" tbl="1" equation="1"/>
6383
6527
  <hh:refList>
6384
6528
  <hh:fontfaces itemCnt="7">
6385
- <hh:fontface lang="HANGUL" fontCnt="1">
6529
+ <hh:fontface lang="HANGUL" fontCnt="2">
6386
6530
  <hh:font id="0" face="\uD568\uCD08\uB86C\uBC14\uD0D5" type="TTF" isEmbedded="0">
6387
6531
  <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="4" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
6388
6532
  </hh:font>
6533
+ <hh:font id="1" face="\uD568\uCD08\uB86C\uB3CB\uC6C0" type="TTF" isEmbedded="0">
6534
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="4" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
6535
+ </hh:font>
6389
6536
  </hh:fontface>
6390
- <hh:fontface lang="LATIN" fontCnt="1">
6537
+ <hh:fontface lang="LATIN" fontCnt="2">
6391
6538
  <hh:font id="0" face="Times New Roman" type="TTF" isEmbedded="0">
6392
6539
  <hh:typeInfo familyType="FCAT_OLDSTYLE" weight="5" proportion="4" contrast="2" strokeVariation="0" armStyle="0" letterform="0" midline="0" xHeight="4"/>
6393
6540
  </hh:font>
6541
+ <hh:font id="1" face="Consolas" type="TTF" isEmbedded="0">
6542
+ <hh:typeInfo familyType="FCAT_MODERN" weight="5" proportion="0" contrast="0" strokeVariation="0" armStyle="0" letterform="0" midline="0" xHeight="0"/>
6543
+ </hh:font>
6394
6544
  </hh:fontface>
6395
6545
  <hh:fontface lang="HANJA" fontCnt="1">
6396
6546
  <hh:font id="0" face="\uD568\uCD08\uB86C\uBC14\uD0D5" type="TTF" isEmbedded="0">
@@ -6422,34 +6572,37 @@ function generateHeaderXml() {
6422
6572
  <hh:borderFill id="0" threeD="0" shadow="0" centerLine="0" breakCellSeparateLine="0">
6423
6573
  <hh:slash type="NONE" Crooked="0" isCounter="0"/>
6424
6574
  <hh:backSlash type="NONE" Crooked="0" isCounter="0"/>
6425
- <hh:leftBorder type="NONE" width="0.1mm" color="0"/>
6426
- <hh:rightBorder type="NONE" width="0.1mm" color="0"/>
6427
- <hh:topBorder type="NONE" width="0.1mm" color="0"/>
6428
- <hh:bottomBorder type="NONE" width="0.1mm" color="0"/>
6429
- <hh:diagonal type="NONE" width="0.1mm" color="0"/>
6575
+ <hh:leftBorder type="NONE" width="0.1mm" color="#000000"/>
6576
+ <hh:rightBorder type="NONE" width="0.1mm" color="#000000"/>
6577
+ <hh:topBorder type="NONE" width="0.1mm" color="#000000"/>
6578
+ <hh:bottomBorder type="NONE" width="0.1mm" color="#000000"/>
6579
+ <hh:diagonal type="NONE" width="0.1mm" color="#000000"/>
6430
6580
  <hh:fillInfo/>
6431
6581
  </hh:borderFill>
6432
6582
  </hh:borderFills>
6433
- <hh:charProperties itemCnt="1">
6434
- <hh:charPr id="0" height="1000" textColor="0" shadeColor="-1" useFontSpace="0" useKerning="0" symMark="NONE" borderFillIDRef="0">
6435
- <hh:fontRef hangul="0" latin="0" hanja="0" japanese="0" other="0" symbol="0" user="0"/>
6436
- <hh:ratio hangul="100" latin="100" hanja="100" japanese="100" other="100" symbol="100" user="100"/>
6437
- <hh:spacing hangul="0" latin="0" hanja="0" japanese="0" other="0" symbol="0" user="0"/>
6438
- <hh:relSz hangul="100" latin="100" hanja="100" japanese="100" other="100" symbol="100" user="100"/>
6439
- <hh:offset hangul="0" latin="0" hanja="0" japanese="0" other="0" symbol="0" user="0"/>
6440
- </hh:charPr>
6583
+ <hh:charProperties itemCnt="9">
6584
+ ${charPr(0, 1e3, false, false)}
6585
+ ${charPr(1, 1e3, true, false)}
6586
+ ${charPr(2, 1e3, false, true)}
6587
+ ${charPr(3, 1e3, true, true)}
6588
+ ${charPr(4, 900, false, false, 1)}
6589
+ ${charPr(5, 1800, true, false, 1)}
6590
+ ${charPr(6, 1400, true, false, 1)}
6591
+ ${charPr(7, 1200, true, false, 1)}
6592
+ ${charPr(8, 1100, true, false, 1)}
6441
6593
  </hh:charProperties>
6442
6594
  <hh:tabProperties itemCnt="0"/>
6443
6595
  <hh:numberings itemCnt="0"/>
6444
6596
  <hh:bullets itemCnt="0"/>
6445
- <hh:paraProperties itemCnt="1">
6446
- <hh:paraPr id="0" tabIDRef="0" condense="0" fontLineHeight="0" snapToGrid="0" suppressOverlap="0" checked="0">
6447
- <hh:parLineBreak lineBreak="BREAK_LINE" wordBreak="BREAK_WORD" breakLatinWord="BREAK_WORD" breakNonLatinWord="BREAK_WORD"/>
6448
- <hh:parMargin left="0" right="0" prev="0" next="0" indent="0"/>
6449
- <hh:parBorder borderFillIDRef="0" offsetLeft="0" offsetRight="0" offsetTop="0" offsetBottom="0" connect="0" ignoreMargin="0"/>
6450
- <hh:parShade borderFillIDRef="0"/>
6451
- <hh:parTabList/>
6452
- </hh:paraPr>
6597
+ <hh:paraProperties itemCnt="8">
6598
+ ${paraPr(0)}
6599
+ ${paraPr(1, { align: "LEFT", spaceBefore: 800, spaceAfter: 200, lineSpacing: 180 })}
6600
+ ${paraPr(2, { align: "LEFT", spaceBefore: 600, spaceAfter: 150, lineSpacing: 170 })}
6601
+ ${paraPr(3, { align: "LEFT", spaceBefore: 400, spaceAfter: 100, lineSpacing: 160 })}
6602
+ ${paraPr(4, { align: "LEFT", spaceBefore: 300, spaceAfter: 100, lineSpacing: 160 })}
6603
+ ${paraPr(5, { align: "LEFT", lineSpacing: 130, indent: 400 })}
6604
+ ${paraPr(6, { align: "LEFT", lineSpacing: 150, indent: 600 })}
6605
+ ${paraPr(7, { align: "LEFT", lineSpacing: 160, indent: 600 })}
6453
6606
  </hh:paraProperties>
6454
6607
  <hh:styles itemCnt="1">
6455
6608
  <hh:style id="0" type="PARA" name="\uBC14\uD0D5\uAE00" engName="Normal" paraPrIDRef="0" charPrIDRef="0" nextStyleIDRef="0" langIDRef="1042" lockForm="0"/>
@@ -6458,34 +6611,78 @@ function generateHeaderXml() {
6458
6611
  <hh:compatibleDocument targetProgram="HWP2018"/>
6459
6612
  </hh:head>`;
6460
6613
  }
6461
- function generateParagraph(text) {
6462
- return `<hp:p paraPrIDRef="0" styleIDRef="0"><hp:run charPrIDRef="0"><hp:t>${escapeXml(text)}</hp:t></hp:run></hp:p>`;
6614
+ function generateSecPr() {
6615
+ 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="2835" footer="2835" gutter="0" left="5670" right="4252" top="8504" bottom="4252"/></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>`;
6463
6616
  }
6464
6617
  function generateTable(rows) {
6465
6618
  const trElements = rows.map((row) => {
6466
- const tdElements = row.map(
6467
- (cell) => `<hp:tc><hp:cellSpan colSpan="1" rowSpan="1"/>${generateParagraph(cell)}</hp:tc>`
6468
- ).join("");
6619
+ const tdElements = row.map((cell) => {
6620
+ const runs = generateRuns(cell);
6621
+ return `<hp:tc><hp:cellSpan colSpan="1" rowSpan="1"/><hp:p paraPrIDRef="0" styleIDRef="0">${runs}</hp:p></hp:tc>`;
6622
+ }).join("");
6469
6623
  return `<hp:tr>${tdElements}</hp:tr>`;
6470
6624
  }).join("");
6471
6625
  return `<hp:tbl>${trElements}</hp:tbl>`;
6472
6626
  }
6473
6627
  function blocksToSectionXml(blocks) {
6474
- const body = blocks.map((block) => {
6628
+ const paraXmls = [];
6629
+ let isFirst = true;
6630
+ for (const block of blocks) {
6631
+ let xml = "";
6475
6632
  switch (block.type) {
6476
- case "heading":
6477
- return generateParagraph(block.text || "");
6478
- case "table":
6479
- return block.rows ? generateTable(block.rows) : "";
6633
+ case "heading": {
6634
+ const pId = headingParaPrId(block.level || 1);
6635
+ const cId = headingCharPrId(block.level || 1);
6636
+ xml = generateParagraph(block.text || "", pId, cId);
6637
+ break;
6638
+ }
6480
6639
  case "paragraph":
6481
- return generateParagraph(block.text || "");
6482
- default:
6483
- return "";
6640
+ xml = generateParagraph(block.text || "");
6641
+ break;
6642
+ case "code_block": {
6643
+ const codeLines = (block.text || "").split("\n");
6644
+ xml = codeLines.map((line) => generateParagraph(line || " ", PARA_CODE)).join("\n ");
6645
+ break;
6646
+ }
6647
+ case "blockquote":
6648
+ xml = generateParagraph(block.text || "", PARA_QUOTE);
6649
+ break;
6650
+ case "list_item": {
6651
+ const marker = block.ordered ? `${(block.indent || 0) + 1}. ` : "\xB7 ";
6652
+ const indentPrefix = " ".repeat(block.indent || 0);
6653
+ xml = generateParagraph(indentPrefix + marker + (block.text || ""), PARA_LIST);
6654
+ break;
6655
+ }
6656
+ case "hr":
6657
+ xml = `<hp:p paraPrIDRef="0" styleIDRef="0"><hp:run charPrIDRef="0"><hp:t>\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500</hp:t></hp:run></hp:p>`;
6658
+ break;
6659
+ case "table":
6660
+ if (block.rows) {
6661
+ if (isFirst) {
6662
+ const secRun = `<hp:run charPrIDRef="0">${generateSecPr()}<hp:t></hp:t></hp:run>`;
6663
+ paraXmls.push(`<hp:p paraPrIDRef="0" styleIDRef="0">${secRun}</hp:p>`);
6664
+ isFirst = false;
6665
+ }
6666
+ xml = generateTable(block.rows);
6667
+ }
6668
+ break;
6484
6669
  }
6485
- }).join("\n ");
6670
+ if (!xml) continue;
6671
+ if (isFirst && block.type !== "table") {
6672
+ xml = xml.replace(
6673
+ /<hp:run charPrIDRef="(\d+)">/,
6674
+ `<hp:run charPrIDRef="$1">${generateSecPr()}`
6675
+ );
6676
+ isFirst = false;
6677
+ }
6678
+ paraXmls.push(xml);
6679
+ }
6680
+ if (paraXmls.length === 0) {
6681
+ paraXmls.push(`<hp:p paraPrIDRef="0" styleIDRef="0"><hp:run charPrIDRef="0">${generateSecPr()}<hp:t></hp:t></hp:run></hp:p>`);
6682
+ }
6486
6683
  return `<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
6487
6684
  <hs:sec xmlns:hs="${NS_SECTION}" xmlns:hp="${NS_PARA}">
6488
- ${body}
6685
+ ${paraXmls.join("\n ")}
6489
6686
  </hs:sec>`;
6490
6687
  }
6491
6688