@clazic/kordoc 2.1.4 → 2.1.6
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/{chunk-N2UPMKGJ.js → chunk-H7HMKSLX.js} +2 -2
- package/dist/{chunk-N2UPMKGJ.js.map → chunk-H7HMKSLX.js.map} +1 -1
- package/dist/{chunk-NNYD6QUN.js → chunk-TFYOEQE2.js} +2 -2
- package/dist/cli.js +4 -4
- package/dist/index.cjs +189 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +189 -25
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +2 -2
- package/dist/{utils-7VR5ORIC.js → utils-7JE5SKSL.js} +2 -2
- package/dist/{watch-5RZ4YQPC.js → watch-XALC6VOR.js} +3 -3
- package/package.json +1 -1
- /package/dist/{chunk-NNYD6QUN.js.map → chunk-TFYOEQE2.js.map} +0 -0
- /package/dist/{utils-7VR5ORIC.js.map → utils-7JE5SKSL.js.map} +0 -0
- /package/dist/{watch-5RZ4YQPC.js.map → watch-XALC6VOR.js.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/utils.ts
|
|
4
|
-
var VERSION = true ? "2.1.
|
|
4
|
+
var VERSION = true ? "2.1.6" : "0.0.0-dev";
|
|
5
5
|
function toArrayBuffer(buf) {
|
|
6
6
|
if (buf.byteOffset === 0 && buf.byteLength === buf.buffer.byteLength) {
|
|
7
7
|
return buf.buffer;
|
|
@@ -90,4 +90,4 @@ export {
|
|
|
90
90
|
sanitizeHref,
|
|
91
91
|
classifyError
|
|
92
92
|
};
|
|
93
|
-
//# sourceMappingURL=chunk-
|
|
93
|
+
//# sourceMappingURL=chunk-TFYOEQE2.js.map
|
package/dist/cli.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import {
|
|
3
3
|
detectFormat,
|
|
4
4
|
parse
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-H7HMKSLX.js";
|
|
6
6
|
import {
|
|
7
7
|
VERSION,
|
|
8
8
|
toArrayBuffer
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-TFYOEQE2.js";
|
|
10
10
|
import "./chunk-MOL7MDBG.js";
|
|
11
11
|
|
|
12
12
|
// src/cli.ts
|
|
@@ -92,7 +92,7 @@ program.name("kordoc").description("\uBAA8\uB450 \uD30C\uC2F1\uD574\uBC84\uB9AC\
|
|
|
92
92
|
process.stdout.write(output + "\n");
|
|
93
93
|
}
|
|
94
94
|
} catch (err) {
|
|
95
|
-
const { sanitizeError } = await import("./utils-
|
|
95
|
+
const { sanitizeError } = await import("./utils-7JE5SKSL.js");
|
|
96
96
|
process.stderr.write(`
|
|
97
97
|
[kordoc] ERROR: ${fileName} \u2014 ${sanitizeError(err)}
|
|
98
98
|
`);
|
|
@@ -101,7 +101,7 @@ program.name("kordoc").description("\uBAA8\uB450 \uD30C\uC2F1\uD574\uBC84\uB9AC\
|
|
|
101
101
|
}
|
|
102
102
|
});
|
|
103
103
|
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) => {
|
|
104
|
-
const { watchDirectory } = await import("./watch-
|
|
104
|
+
const { watchDirectory } = await import("./watch-XALC6VOR.js");
|
|
105
105
|
await watchDirectory({
|
|
106
106
|
dir,
|
|
107
107
|
outDir: opts.outDir,
|
package/dist/index.cjs
CHANGED
|
@@ -181,7 +181,7 @@ var import_jszip2 = __toESM(require("jszip"), 1);
|
|
|
181
181
|
var import_xmldom = require("@xmldom/xmldom");
|
|
182
182
|
|
|
183
183
|
// src/utils.ts
|
|
184
|
-
var VERSION = true ? "2.1.
|
|
184
|
+
var VERSION = true ? "2.1.6" : "0.0.0-dev";
|
|
185
185
|
function toArrayBuffer(buf) {
|
|
186
186
|
if (buf.byteOffset === 0 && buf.byteLength === buf.buffer.byteLength) {
|
|
187
187
|
return buf.buffer;
|
|
@@ -5644,7 +5644,7 @@ var HEADER_XML = `<?xml version='1.0' encoding='UTF-8'?>
|
|
|
5644
5644
|
<hh:diagonal type="SOLID" width="0.1 mm" color="#000000"/>
|
|
5645
5645
|
</hh:borderFill>
|
|
5646
5646
|
</hh:borderFills>
|
|
5647
|
-
<hh:charProperties itemCnt="
|
|
5647
|
+
<hh:charProperties itemCnt="15">
|
|
5648
5648
|
<hh:charPr id="0" height="1000" textColor="#000000" shadeColor="none" useFontSpace="0" useKerning="0" symMark="NONE" borderFillIDRef="2">
|
|
5649
5649
|
<hh:fontRef hangul="1" latin="1" hanja="1" japanese="1" other="1" symbol="1" user="1"/>
|
|
5650
5650
|
<hh:ratio hangul="100" latin="100" hanja="100" japanese="100" other="100" symbol="100" user="100"/>
|
|
@@ -5795,6 +5795,30 @@ var HEADER_XML = `<?xml version='1.0' encoding='UTF-8'?>
|
|
|
5795
5795
|
<hh:outline type="NONE"/>
|
|
5796
5796
|
<hh:shadow type="NONE" color="#C0C0C0" offsetX="10" offsetY="10"/>
|
|
5797
5797
|
</hh:charPr>
|
|
5798
|
+
<hh:charPr id="13" height="1000" textColor="#000000" shadeColor="none" useFontSpace="0" useKerning="0" symMark="NONE" borderFillIDRef="2">
|
|
5799
|
+
<hh:fontRef hangul="1" latin="1" hanja="1" japanese="1" other="1" symbol="1" user="1"/>
|
|
5800
|
+
<hh:ratio hangul="100" latin="100" hanja="100" japanese="100" other="100" symbol="100" user="100"/>
|
|
5801
|
+
<hh:spacing hangul="0" latin="0" hanja="0" japanese="0" other="0" symbol="0" user="0"/>
|
|
5802
|
+
<hh:relSz hangul="100" latin="100" hanja="100" japanese="100" other="100" symbol="100" user="100"/>
|
|
5803
|
+
<hh:offset hangul="0" latin="0" hanja="0" japanese="0" other="0" symbol="0" user="0"/>
|
|
5804
|
+
<hh:bold/>
|
|
5805
|
+
<hh:italic/>
|
|
5806
|
+
<hh:underline type="NONE" shape="SOLID" color="#000000"/>
|
|
5807
|
+
<hh:strikeout shape="NONE" color="#000000"/>
|
|
5808
|
+
<hh:outline type="NONE"/>
|
|
5809
|
+
<hh:shadow type="NONE" color="#C0C0C0" offsetX="10" offsetY="10"/>
|
|
5810
|
+
</hh:charPr>
|
|
5811
|
+
<hh:charPr id="14" height="900" textColor="#333333" shadeColor="#F0F0F0" useFontSpace="0" useKerning="0" symMark="NONE" borderFillIDRef="2">
|
|
5812
|
+
<hh:fontRef hangul="1" latin="1" hanja="1" japanese="1" other="1" symbol="1" user="1"/>
|
|
5813
|
+
<hh:ratio hangul="100" latin="100" hanja="100" japanese="100" other="100" symbol="100" user="100"/>
|
|
5814
|
+
<hh:spacing hangul="0" latin="0" hanja="0" japanese="0" other="0" symbol="0" user="0"/>
|
|
5815
|
+
<hh:relSz hangul="100" latin="100" hanja="100" japanese="100" other="100" symbol="100" user="100"/>
|
|
5816
|
+
<hh:offset hangul="0" latin="0" hanja="0" japanese="0" other="0" symbol="0" user="0"/>
|
|
5817
|
+
<hh:underline type="NONE" shape="SOLID" color="#000000"/>
|
|
5818
|
+
<hh:strikeout shape="NONE" color="#000000"/>
|
|
5819
|
+
<hh:outline type="NONE"/>
|
|
5820
|
+
<hh:shadow type="NONE" color="#C0C0C0" offsetX="10" offsetY="10"/>
|
|
5821
|
+
</hh:charPr>
|
|
5798
5822
|
</hh:charProperties>
|
|
5799
5823
|
<hh:tabProperties itemCnt="3">
|
|
5800
5824
|
<hh:tabPr id="0" autoTabLeft="0" autoTabRight="0"/>
|
|
@@ -6717,6 +6741,8 @@ var CHAR_H3 = "9";
|
|
|
6717
6741
|
var CHAR_H456 = "10";
|
|
6718
6742
|
var CHAR_BOLD = "11";
|
|
6719
6743
|
var CHAR_ITALIC = "12";
|
|
6744
|
+
var CHAR_BOLD_ITALIC = "13";
|
|
6745
|
+
var CHAR_CODE = "14";
|
|
6720
6746
|
var PARA_NORMAL = "0";
|
|
6721
6747
|
var SEC_NS = [
|
|
6722
6748
|
`xmlns:ha="http://www.hancom.co.kr/hwpml/2011/app"`,
|
|
@@ -6744,7 +6770,7 @@ function escapeXml(text) {
|
|
|
6744
6770
|
}
|
|
6745
6771
|
function parseInlineRuns(text) {
|
|
6746
6772
|
const runs = [];
|
|
6747
|
-
const re = /\*\*\*(.+?)\*\*\*|\*\*(.+?)\*\*|\*(.+?)\*|_(.+?)_|`(.+?)
|
|
6773
|
+
const re = /\*\*\*(.+?)\*\*\*|\*\*(.+?)\*\*|\*(.+?)\*|_(.+?)_|`(.+?)`|\[([^\]]+)\]\(([^)]+)\)/g;
|
|
6748
6774
|
let last = 0;
|
|
6749
6775
|
let m;
|
|
6750
6776
|
while ((m = re.exec(text)) !== null) {
|
|
@@ -6753,13 +6779,16 @@ function parseInlineRuns(text) {
|
|
|
6753
6779
|
else if (m[2]) runs.push({ text: m[2], bold: true });
|
|
6754
6780
|
else if (m[3]) runs.push({ text: m[3], italic: true });
|
|
6755
6781
|
else if (m[4]) runs.push({ text: m[4], italic: true });
|
|
6756
|
-
else if (m[5]) runs.push({ text: m[5] });
|
|
6782
|
+
else if (m[5]) runs.push({ text: m[5], code: true });
|
|
6783
|
+
else if (m[6]) runs.push({ text: m[6], url: m[7] });
|
|
6757
6784
|
last = m.index + m[0].length;
|
|
6758
6785
|
}
|
|
6759
6786
|
if (last < text.length) runs.push({ text: text.slice(last) });
|
|
6760
6787
|
return runs.filter((r) => r.text.length > 0);
|
|
6761
6788
|
}
|
|
6762
6789
|
function charPrForRun(run) {
|
|
6790
|
+
if (run.code) return CHAR_CODE;
|
|
6791
|
+
if (run.bold && run.italic) return CHAR_BOLD_ITALIC;
|
|
6763
6792
|
if (run.bold) return CHAR_BOLD;
|
|
6764
6793
|
if (run.italic) return CHAR_ITALIC;
|
|
6765
6794
|
return CHAR_NORMAL;
|
|
@@ -6767,19 +6796,41 @@ function charPrForRun(run) {
|
|
|
6767
6796
|
function makeRun(text, charPrId) {
|
|
6768
6797
|
return `<hp:run charPrIDRef="${charPrId}"><hp:t${text ? `>${escapeXml(text)}</hp:t` : "/"}></hp:run>`;
|
|
6769
6798
|
}
|
|
6770
|
-
function
|
|
6799
|
+
function makeHyperlinkRun(text, url, charPrId, nextId) {
|
|
6800
|
+
const subId = nextId();
|
|
6801
|
+
const paraId = nextId();
|
|
6802
|
+
return [
|
|
6803
|
+
`<hp:run charPrIDRef="${charPrId}">`,
|
|
6804
|
+
` <hp:ctrl>`,
|
|
6805
|
+
` <hp:hyperLink url="${escapeXml(url)}" macro="" visitedStyle="UNKNOWN" visitedStyleIDRef="4294967295">`,
|
|
6806
|
+
` <hp:subList id="${subId}" textDirection="HORIZONTAL" lineWrap="BREAK" vertAlign="TOP"`,
|
|
6807
|
+
` linkListIDRef="0" linkListNextIDRef="0" textWidth="0" textHeight="0"`,
|
|
6808
|
+
` hasTextRef="0" hasNumRef="0">`,
|
|
6809
|
+
` <hp:p id="${paraId}" paraPrIDRef="0" styleIDRef="0" pageBreak="0" columnBreak="0" merged="0">`,
|
|
6810
|
+
` <hp:run charPrIDRef="${charPrId}"><hp:t>${escapeXml(text)}</hp:t></hp:run>`,
|
|
6811
|
+
` </hp:p>`,
|
|
6812
|
+
` </hp:subList>`,
|
|
6813
|
+
` </hp:hyperLink>`,
|
|
6814
|
+
` </hp:ctrl>`,
|
|
6815
|
+
`</hp:run>`
|
|
6816
|
+
].join("\n");
|
|
6817
|
+
}
|
|
6818
|
+
function makeRunsFromText(text, defaultCharPr, nextId) {
|
|
6771
6819
|
const runs = parseInlineRuns(text);
|
|
6772
6820
|
if (runs.length === 0) return makeRun("", defaultCharPr);
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
return runs.map((r) =>
|
|
6821
|
+
const isPlain = runs.length === 1 && !runs[0].bold && !runs[0].italic && !runs[0].code && !runs[0].url;
|
|
6822
|
+
if (isPlain) return makeRun(runs[0].text, defaultCharPr);
|
|
6823
|
+
return runs.map((r) => {
|
|
6824
|
+
if (r.url && nextId) return makeHyperlinkRun(r.text, r.url, CHAR_NORMAL, nextId);
|
|
6825
|
+
return makeRun(r.text, charPrForRun(r));
|
|
6826
|
+
}).join("");
|
|
6776
6827
|
}
|
|
6777
6828
|
var LINESEG = ` <hp:linesegarray>
|
|
6778
6829
|
<hp:lineseg textpos="0" vertpos="0" vertsize="1000" textheight="1000" baseline="850" spacing="600" horzpos="0" horzsize="42520" flags="393216"/>
|
|
6779
6830
|
</hp:linesegarray>`;
|
|
6780
6831
|
function makeParagraph(text, charPrId, paraPrId, nextId) {
|
|
6781
6832
|
const id = nextId();
|
|
6782
|
-
const runs = makeRunsFromText(text, charPrId);
|
|
6833
|
+
const runs = makeRunsFromText(text, charPrId, nextId);
|
|
6783
6834
|
return [
|
|
6784
6835
|
`<hp:p id="${id}" paraPrIDRef="${paraPrId}" styleIDRef="0" pageBreak="0" columnBreak="0" merged="0">`,
|
|
6785
6836
|
` ${runs}`,
|
|
@@ -6865,6 +6916,15 @@ ${row.map((cell, colIdx) => makeTableCell(cell, colIdx, rowIdx, colWidth, rowIdx
|
|
|
6865
6916
|
`</hp:p>`
|
|
6866
6917
|
].join("\n");
|
|
6867
6918
|
}
|
|
6919
|
+
function getIndent(line) {
|
|
6920
|
+
let spaces = 0;
|
|
6921
|
+
for (const ch of line) {
|
|
6922
|
+
if (ch === " ") spaces++;
|
|
6923
|
+
else if (ch === " ") spaces += 2;
|
|
6924
|
+
else break;
|
|
6925
|
+
}
|
|
6926
|
+
return Math.floor(spaces / 2);
|
|
6927
|
+
}
|
|
6868
6928
|
function parseMarkdownToBlocks(md) {
|
|
6869
6929
|
const lines = md.split("\n");
|
|
6870
6930
|
const blocks = [];
|
|
@@ -6883,6 +6943,12 @@ function parseMarkdownToBlocks(md) {
|
|
|
6883
6943
|
i++;
|
|
6884
6944
|
continue;
|
|
6885
6945
|
}
|
|
6946
|
+
const imgm = trimmed.match(/^!\[([^\]]*)\]\(([^)]+)\)$/);
|
|
6947
|
+
if (imgm) {
|
|
6948
|
+
blocks.push({ type: "image", alt: imgm[1], src: imgm[2] });
|
|
6949
|
+
i++;
|
|
6950
|
+
continue;
|
|
6951
|
+
}
|
|
6886
6952
|
if (trimmed.startsWith("|")) {
|
|
6887
6953
|
const tableRows = [];
|
|
6888
6954
|
while (i < lines.length && lines[i].trim().startsWith("|")) {
|
|
@@ -6898,35 +6964,84 @@ function parseMarkdownToBlocks(md) {
|
|
|
6898
6964
|
if (tableRows.length > 0) blocks.push({ type: "table", rows: tableRows });
|
|
6899
6965
|
continue;
|
|
6900
6966
|
}
|
|
6901
|
-
if (
|
|
6967
|
+
if (/^\s*[-*+]\s/.test(line)) {
|
|
6902
6968
|
const items = [];
|
|
6903
|
-
while (i < lines.length && /^\s*[-*+]\s/.test(lines[i]))
|
|
6904
|
-
|
|
6969
|
+
while (i < lines.length && /^\s*[-*+]\s/.test(lines[i])) {
|
|
6970
|
+
const indent = getIndent(lines[i]);
|
|
6971
|
+
const text = lines[i].trim().replace(/^[-*+]\s+/, "");
|
|
6972
|
+
items.push({ text, indent });
|
|
6973
|
+
i++;
|
|
6974
|
+
}
|
|
6905
6975
|
blocks.push({ type: "list", listType: "unordered", items });
|
|
6906
6976
|
continue;
|
|
6907
6977
|
}
|
|
6908
|
-
if (/^\d+\.\s/.test(
|
|
6978
|
+
if (/^\s*\d+\.\s/.test(line)) {
|
|
6909
6979
|
const items = [];
|
|
6910
|
-
while (i < lines.length && /^\s*\d+\.\s/.test(lines[i]))
|
|
6911
|
-
|
|
6980
|
+
while (i < lines.length && /^\s*\d+\.\s/.test(lines[i])) {
|
|
6981
|
+
const indent = getIndent(lines[i]);
|
|
6982
|
+
const text = lines[i].trim().replace(/^\d+\.\s+/, "");
|
|
6983
|
+
items.push({ text, indent });
|
|
6984
|
+
i++;
|
|
6985
|
+
}
|
|
6912
6986
|
blocks.push({ type: "list", listType: "ordered", items });
|
|
6913
6987
|
continue;
|
|
6914
6988
|
}
|
|
6915
6989
|
if (trimmed.startsWith("```")) {
|
|
6990
|
+
const lang = trimmed.slice(3).trim();
|
|
6916
6991
|
i++;
|
|
6917
6992
|
const codeLines = [];
|
|
6918
6993
|
while (i < lines.length && !lines[i].trim().startsWith("```")) codeLines.push(lines[i++]);
|
|
6919
6994
|
if (i < lines.length) i++;
|
|
6920
|
-
if (codeLines.length > 0) blocks.push({ type: "
|
|
6995
|
+
if (codeLines.length > 0) blocks.push({ type: "code", text: codeLines.join("\n"), lang });
|
|
6921
6996
|
continue;
|
|
6922
6997
|
}
|
|
6923
6998
|
const paraLines = [];
|
|
6924
|
-
while (i < lines.length && lines[i].trim() && !lines[i].trim().startsWith("#") && !lines[i].trim().startsWith("|") && !/^\s*[-*+]\s/.test(lines[i]) && !/^\s*\d+\.\s/.test(lines[i]) && !lines[i].trim().startsWith("```")) paraLines.push(lines[i++].trim());
|
|
6999
|
+
while (i < lines.length && lines[i].trim() && !lines[i].trim().startsWith("#") && !lines[i].trim().startsWith("|") && !/^\s*[-*+]\s/.test(lines[i]) && !/^\s*\d+\.\s/.test(lines[i]) && !lines[i].trim().startsWith("```") && !lines[i].trim().match(/^!\[[^\]]*\]\([^)]+\)$/)) paraLines.push(lines[i++].trim());
|
|
6925
7000
|
if (paraLines.length > 0) blocks.push({ type: "paragraph", text: paraLines.join(" ") });
|
|
6926
7001
|
}
|
|
6927
7002
|
return blocks;
|
|
6928
7003
|
}
|
|
6929
|
-
function
|
|
7004
|
+
function mimeToFormat(mimeType) {
|
|
7005
|
+
if (mimeType.includes("jpeg") || mimeType.includes("jpg")) return "JPG";
|
|
7006
|
+
if (mimeType.includes("gif")) return "GIF";
|
|
7007
|
+
if (mimeType.includes("bmp")) return "BMP";
|
|
7008
|
+
return "PNG";
|
|
7009
|
+
}
|
|
7010
|
+
function makeImageParagraph(binDataId, nextId, widthHwp = 28346, heightHwp = 19843) {
|
|
7011
|
+
const paraId = nextId();
|
|
7012
|
+
return [
|
|
7013
|
+
`<hp:p id="${paraId}" paraPrIDRef="0" styleIDRef="0" pageBreak="0" columnBreak="0" merged="0">`,
|
|
7014
|
+
` <hp:run charPrIDRef="0">`,
|
|
7015
|
+
` <hp:pic name="" zOrder="0" numberingType="NONE" textWrap="TOP_AND_BOTTOM" textFlow="BOTH_SIDES"`,
|
|
7016
|
+
` lock="0" dropcapstyle="None" pageBreak="CELL">`,
|
|
7017
|
+
` <hp:instSz width="${widthHwp}" height="${heightHwp}" widthRelTo="ABSOLUTE" heightRelTo="ABSOLUTE" protect="0"/>`,
|
|
7018
|
+
` <hp:pos treatAsChar="1" affectLSpacing="0" flowWithText="1" allowOverlap="0"`,
|
|
7019
|
+
` holdAnchorAndSO="0" vertRelTo="PARA" horzRelTo="COLUMN"`,
|
|
7020
|
+
` vertAlign="TOP" horzAlign="LEFT" vertOffset="0" horzOffset="0"/>`,
|
|
7021
|
+
` <hp:outMargin left="0" right="0" top="0" bottom="0"/>`,
|
|
7022
|
+
` <hp:content binaryItemIDRef="${binDataId}"/>`,
|
|
7023
|
+
` <hp:imgRect left="0" top="0" right="${widthHwp}" bottom="${heightHwp}"/>`,
|
|
7024
|
+
` <hp:imgClip left="0" top="0" right="${widthHwp}" bottom="${heightHwp}"/>`,
|
|
7025
|
+
` </hp:pic>`,
|
|
7026
|
+
` </hp:run>`,
|
|
7027
|
+
LINESEG,
|
|
7028
|
+
`</hp:p>`
|
|
7029
|
+
].join("\n");
|
|
7030
|
+
}
|
|
7031
|
+
function makeCodeParagraphs(code, nextId) {
|
|
7032
|
+
const lines = code.split("\n");
|
|
7033
|
+
return lines.map((line) => {
|
|
7034
|
+
const id = nextId();
|
|
7035
|
+
const safe = escapeXml(line || " ");
|
|
7036
|
+
return [
|
|
7037
|
+
`<hp:p id="${id}" paraPrIDRef="0" styleIDRef="0" pageBreak="0" columnBreak="0" merged="0">`,
|
|
7038
|
+
` <hp:run charPrIDRef="${CHAR_CODE}"><hp:t>${safe}</hp:t></hp:run>`,
|
|
7039
|
+
LINESEG,
|
|
7040
|
+
`</hp:p>`
|
|
7041
|
+
].join("\n");
|
|
7042
|
+
}).join("\n");
|
|
7043
|
+
}
|
|
7044
|
+
function generateSectionXml(blocks, styleMap, imageMap) {
|
|
6930
7045
|
const nextId = makeIdGen();
|
|
6931
7046
|
const firstId = nextId();
|
|
6932
7047
|
const defaultCharPr = styleMap ? styleMap.body.charPr : CHAR_NORMAL;
|
|
@@ -6975,11 +7090,12 @@ function generateSectionXml(blocks, styleMap) {
|
|
|
6975
7090
|
`</hp:p>`
|
|
6976
7091
|
].join("\n");
|
|
6977
7092
|
const bodyParts = [];
|
|
7093
|
+
const orderedCounters = /* @__PURE__ */ new Map();
|
|
6978
7094
|
for (const block of blocks) {
|
|
7095
|
+
if (block.type !== "list") orderedCounters.clear();
|
|
6979
7096
|
switch (block.type) {
|
|
6980
7097
|
case "heading": {
|
|
6981
7098
|
const level = block.level || 1;
|
|
6982
|
-
const headingKey = `h${level}`;
|
|
6983
7099
|
let charPrId;
|
|
6984
7100
|
let paraPrId;
|
|
6985
7101
|
if (styleMap) {
|
|
@@ -7004,21 +7120,51 @@ function generateSectionXml(blocks, styleMap) {
|
|
|
7004
7120
|
}
|
|
7005
7121
|
break;
|
|
7006
7122
|
}
|
|
7123
|
+
case "code": {
|
|
7124
|
+
bodyParts.push(makeCodeParagraphs(block.text || "", nextId));
|
|
7125
|
+
break;
|
|
7126
|
+
}
|
|
7007
7127
|
case "empty":
|
|
7008
7128
|
bodyParts.push(makeEmptyParagraph(nextId));
|
|
7009
7129
|
break;
|
|
7010
7130
|
case "list": {
|
|
7011
7131
|
const charPrId = styleMap ? styleMap.body.charPr : CHAR_NORMAL;
|
|
7012
7132
|
const paraPrId = styleMap ? styleMap.body.paraPr : PARA_NORMAL;
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
|
|
7133
|
+
const items = block.items || [];
|
|
7134
|
+
if (block.listType === "ordered") {
|
|
7135
|
+
for (const item of items) {
|
|
7136
|
+
const cnt = (orderedCounters.get(item.indent) || 0) + 1;
|
|
7137
|
+
orderedCounters.set(item.indent, cnt);
|
|
7138
|
+
for (const [k] of orderedCounters) {
|
|
7139
|
+
if (k > item.indent) orderedCounters.set(k, 0);
|
|
7140
|
+
}
|
|
7141
|
+
const indent = " ".repeat(item.indent);
|
|
7142
|
+
bodyParts.push(makeParagraph(`${indent}${cnt}. ${item.text}`, charPrId, paraPrId, nextId));
|
|
7143
|
+
}
|
|
7144
|
+
} else {
|
|
7145
|
+
for (const item of items) {
|
|
7146
|
+
const bullets = ["\u2022", "\u25E6", "\u25AA"];
|
|
7147
|
+
const bullet = bullets[Math.min(item.indent, bullets.length - 1)];
|
|
7148
|
+
const indent = " ".repeat(item.indent);
|
|
7149
|
+
bodyParts.push(makeParagraph(`${indent}${bullet} ${item.text}`, charPrId, paraPrId, nextId));
|
|
7150
|
+
}
|
|
7016
7151
|
}
|
|
7017
7152
|
break;
|
|
7018
7153
|
}
|
|
7019
7154
|
case "table":
|
|
7020
7155
|
if (block.rows?.length) bodyParts.push(makeTable(block.rows, nextId, styleMap));
|
|
7021
7156
|
break;
|
|
7157
|
+
case "image": {
|
|
7158
|
+
const src = block.src || "";
|
|
7159
|
+
const binId = imageMap?.get(src);
|
|
7160
|
+
if (binId !== void 0) {
|
|
7161
|
+
bodyParts.push(makeImageParagraph(binId, nextId));
|
|
7162
|
+
} else {
|
|
7163
|
+
const alt = block.alt || src || "(\uC774\uBBF8\uC9C0)";
|
|
7164
|
+
bodyParts.push(makeParagraph(`[\uC774\uBBF8\uC9C0: ${alt}]`, CHAR_NORMAL, PARA_NORMAL, nextId));
|
|
7165
|
+
}
|
|
7166
|
+
break;
|
|
7167
|
+
}
|
|
7022
7168
|
}
|
|
7023
7169
|
}
|
|
7024
7170
|
return [
|
|
@@ -7055,9 +7201,28 @@ async function markdownToHwpx(markdown, options) {
|
|
|
7055
7201
|
warnings.push(`[warn] \uD15C\uD50C\uB9BF \uCC98\uB9AC \uC2E4\uD328: ${msg}. \uAE30\uBCF8 \uC2A4\uD0C0\uC77C \uC0AC\uC6A9`);
|
|
7056
7202
|
}
|
|
7057
7203
|
}
|
|
7204
|
+
const imageMap = /* @__PURE__ */ new Map();
|
|
7205
|
+
const binDataEntries = [];
|
|
7206
|
+
if (opts.images && opts.images.length > 0) {
|
|
7207
|
+
for (let idx = 0; idx < opts.images.length; idx++) {
|
|
7208
|
+
const img = opts.images[idx];
|
|
7209
|
+
const binId = idx + 1;
|
|
7210
|
+
const format = mimeToFormat(img.mimeType);
|
|
7211
|
+
const nameWithoutExt = img.filename.replace(/\.[^.]+$/, "");
|
|
7212
|
+
const binFilename = `BinData/${nameWithoutExt}`;
|
|
7213
|
+
imageMap.set(img.filename, binId);
|
|
7214
|
+
binDataEntries.push({ id: binId, format, filename: binFilename });
|
|
7215
|
+
}
|
|
7216
|
+
}
|
|
7217
|
+
if (binDataEntries.length > 0) {
|
|
7218
|
+
const binXml = binDataEntries.map((e) => ` <hh:binData id="${e.id}" type="LINK" format="${e.format}" compress="NO" access="PUBLIC"><hh:sourceFile href="${e.filename}"/></hh:binData>`).join("\n");
|
|
7219
|
+
headerXml = headerXml.replace("</hh:refList>", `${binXml}
|
|
7220
|
+
</hh:refList>`);
|
|
7221
|
+
}
|
|
7058
7222
|
const sectionXml = generateSectionXml(
|
|
7059
7223
|
parseMarkdownToBlocks(markdown),
|
|
7060
|
-
styleMap || void 0
|
|
7224
|
+
styleMap || void 0,
|
|
7225
|
+
imageMap.size > 0 ? imageMap : void 0
|
|
7061
7226
|
);
|
|
7062
7227
|
const zip = new import_jszip6.default();
|
|
7063
7228
|
zip.file("mimetype", "application/hwp+zip", { compression: "STORE" });
|
|
@@ -7073,8 +7238,7 @@ async function markdownToHwpx(markdown, options) {
|
|
|
7073
7238
|
if (opts.images && opts.images.length > 0) {
|
|
7074
7239
|
for (const img of opts.images) {
|
|
7075
7240
|
const nameWithoutExt = img.filename.replace(/\.[^.]+$/, "");
|
|
7076
|
-
|
|
7077
|
-
zip.file(binDataPath, img.data);
|
|
7241
|
+
zip.file(`BinData/${nameWithoutExt}`, img.data);
|
|
7078
7242
|
}
|
|
7079
7243
|
}
|
|
7080
7244
|
return await zip.generateAsync({ type: "arraybuffer" });
|