@v1hz/md2docx 2.6.0 → 2.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +125 -376
- package/dist/index.js +273 -106
- package/dist-electron/main.js +152518 -0
- package/package.json +24 -3
package/dist/index.js
CHANGED
|
@@ -579,42 +579,113 @@ var require_browser = __commonJS((exports, module) => {
|
|
|
579
579
|
};
|
|
580
580
|
});
|
|
581
581
|
|
|
582
|
+
// node_modules/has-flag/index.js
|
|
583
|
+
var require_has_flag = __commonJS((exports, module) => {
|
|
584
|
+
module.exports = (flag, argv = process.argv) => {
|
|
585
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
586
|
+
const position2 = argv.indexOf(prefix + flag);
|
|
587
|
+
const terminatorPosition = argv.indexOf("--");
|
|
588
|
+
return position2 !== -1 && (terminatorPosition === -1 || position2 < terminatorPosition);
|
|
589
|
+
};
|
|
590
|
+
});
|
|
591
|
+
|
|
582
592
|
// node_modules/supports-color/index.js
|
|
583
593
|
var require_supports_color = __commonJS((exports, module) => {
|
|
584
|
-
var
|
|
585
|
-
var
|
|
586
|
-
var hasFlag =
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
+
var os = __require("os");
|
|
595
|
+
var tty = __require("tty");
|
|
596
|
+
var hasFlag = require_has_flag();
|
|
597
|
+
var { env } = process;
|
|
598
|
+
var forceColor;
|
|
599
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
600
|
+
forceColor = 0;
|
|
601
|
+
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
602
|
+
forceColor = 1;
|
|
603
|
+
}
|
|
604
|
+
if ("FORCE_COLOR" in env) {
|
|
605
|
+
if (env.FORCE_COLOR === "true") {
|
|
606
|
+
forceColor = 1;
|
|
607
|
+
} else if (env.FORCE_COLOR === "false") {
|
|
608
|
+
forceColor = 0;
|
|
609
|
+
} else {
|
|
610
|
+
forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
|
|
594
611
|
}
|
|
595
|
-
|
|
612
|
+
}
|
|
613
|
+
function translateLevel(level) {
|
|
614
|
+
if (level === 0) {
|
|
596
615
|
return false;
|
|
597
616
|
}
|
|
598
|
-
|
|
599
|
-
|
|
617
|
+
return {
|
|
618
|
+
level,
|
|
619
|
+
hasBasic: true,
|
|
620
|
+
has256: level >= 2,
|
|
621
|
+
has16m: level >= 3
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
function supportsColor(haveStream, streamIsTTY) {
|
|
625
|
+
if (forceColor === 0) {
|
|
626
|
+
return 0;
|
|
600
627
|
}
|
|
601
|
-
if (
|
|
602
|
-
return
|
|
628
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
629
|
+
return 3;
|
|
630
|
+
}
|
|
631
|
+
if (hasFlag("color=256")) {
|
|
632
|
+
return 2;
|
|
633
|
+
}
|
|
634
|
+
if (haveStream && !streamIsTTY && forceColor === undefined) {
|
|
635
|
+
return 0;
|
|
636
|
+
}
|
|
637
|
+
const min = forceColor || 0;
|
|
638
|
+
if (env.TERM === "dumb") {
|
|
639
|
+
return min;
|
|
603
640
|
}
|
|
604
641
|
if (process.platform === "win32") {
|
|
605
|
-
|
|
642
|
+
const osRelease = os.release().split(".");
|
|
643
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
644
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
645
|
+
}
|
|
646
|
+
return 1;
|
|
606
647
|
}
|
|
607
|
-
if ("
|
|
608
|
-
|
|
648
|
+
if ("CI" in env) {
|
|
649
|
+
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE"].some((sign) => (sign in env)) || env.CI_NAME === "codeship") {
|
|
650
|
+
return 1;
|
|
651
|
+
}
|
|
652
|
+
return min;
|
|
609
653
|
}
|
|
610
|
-
if (
|
|
611
|
-
return
|
|
654
|
+
if ("TEAMCITY_VERSION" in env) {
|
|
655
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
612
656
|
}
|
|
613
|
-
if (
|
|
614
|
-
return
|
|
657
|
+
if (env.COLORTERM === "truecolor") {
|
|
658
|
+
return 3;
|
|
615
659
|
}
|
|
616
|
-
|
|
617
|
-
|
|
660
|
+
if ("TERM_PROGRAM" in env) {
|
|
661
|
+
const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
662
|
+
switch (env.TERM_PROGRAM) {
|
|
663
|
+
case "iTerm.app":
|
|
664
|
+
return version >= 3 ? 3 : 2;
|
|
665
|
+
case "Apple_Terminal":
|
|
666
|
+
return 2;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
670
|
+
return 2;
|
|
671
|
+
}
|
|
672
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
673
|
+
return 1;
|
|
674
|
+
}
|
|
675
|
+
if ("COLORTERM" in env) {
|
|
676
|
+
return 1;
|
|
677
|
+
}
|
|
678
|
+
return min;
|
|
679
|
+
}
|
|
680
|
+
function getSupportLevel(stream) {
|
|
681
|
+
const level = supportsColor(stream, stream && stream.isTTY);
|
|
682
|
+
return translateLevel(level);
|
|
683
|
+
}
|
|
684
|
+
module.exports = {
|
|
685
|
+
supportsColor: getSupportLevel,
|
|
686
|
+
stdout: translateLevel(supportsColor(true, tty.isatty(1))),
|
|
687
|
+
stderr: translateLevel(supportsColor(true, tty.isatty(2)))
|
|
688
|
+
};
|
|
618
689
|
});
|
|
619
690
|
|
|
620
691
|
// node_modules/debug/src/node.js
|
|
@@ -1079,13 +1150,13 @@ var require_elk_bundled = __commonJS((exports, module) => {
|
|
|
1079
1150
|
this.id = id + 1;
|
|
1080
1151
|
msg.id = id;
|
|
1081
1152
|
var self2 = this;
|
|
1082
|
-
return new Promise(function(
|
|
1153
|
+
return new Promise(function(resolve5, reject) {
|
|
1083
1154
|
self2.resolvers[id] = function(err, res) {
|
|
1084
1155
|
if (err) {
|
|
1085
1156
|
self2.convertGwtStyleError(err);
|
|
1086
1157
|
reject(err);
|
|
1087
1158
|
} else {
|
|
1088
|
-
|
|
1159
|
+
resolve5(res);
|
|
1089
1160
|
}
|
|
1090
1161
|
};
|
|
1091
1162
|
self2.worker.postMessage(msg);
|
|
@@ -96120,7 +96191,7 @@ var init_dist = __esm(() => {
|
|
|
96120
96191
|
return ret;
|
|
96121
96192
|
}
|
|
96122
96193
|
function once(emitter, name2) {
|
|
96123
|
-
return new Promise(function(
|
|
96194
|
+
return new Promise(function(resolve6, reject) {
|
|
96124
96195
|
function errorListener(err) {
|
|
96125
96196
|
emitter.removeListener(name2, resolver2);
|
|
96126
96197
|
reject(err);
|
|
@@ -96128,7 +96199,7 @@ var init_dist = __esm(() => {
|
|
|
96128
96199
|
function resolver2() {
|
|
96129
96200
|
if (typeof emitter.removeListener === "function")
|
|
96130
96201
|
emitter.removeListener("error", errorListener);
|
|
96131
|
-
|
|
96202
|
+
resolve6([].slice.call(arguments));
|
|
96132
96203
|
}
|
|
96133
96204
|
eventTargetAgnosticAddListener(emitter, name2, resolver2, { once: true });
|
|
96134
96205
|
if (name2 !== "error")
|
|
@@ -99412,8 +99483,8 @@ var init_dist = __esm(() => {
|
|
|
99412
99483
|
}
|
|
99413
99484
|
function fn2() {
|
|
99414
99485
|
var promiseResolve, promiseReject;
|
|
99415
|
-
var promise = new Promise(function(
|
|
99416
|
-
promiseResolve =
|
|
99486
|
+
var promise = new Promise(function(resolve6, reject) {
|
|
99487
|
+
promiseResolve = resolve6;
|
|
99417
99488
|
promiseReject = reject;
|
|
99418
99489
|
});
|
|
99419
99490
|
var args = [];
|
|
@@ -100948,14 +101019,14 @@ var init_dist = __esm(() => {
|
|
|
100948
101019
|
};
|
|
100949
101020
|
}
|
|
100950
101021
|
function readAndResolve(iter) {
|
|
100951
|
-
var
|
|
100952
|
-
if (
|
|
101022
|
+
var resolve6 = iter[kLastResolve];
|
|
101023
|
+
if (resolve6 !== null) {
|
|
100953
101024
|
var data = iter[kStream].read();
|
|
100954
101025
|
if (data !== null) {
|
|
100955
101026
|
iter[kLastPromise] = null;
|
|
100956
101027
|
iter[kLastResolve] = null;
|
|
100957
101028
|
iter[kLastReject] = null;
|
|
100958
|
-
|
|
101029
|
+
resolve6(createIterResult(data, false));
|
|
100959
101030
|
}
|
|
100960
101031
|
}
|
|
100961
101032
|
}
|
|
@@ -100963,13 +101034,13 @@ var init_dist = __esm(() => {
|
|
|
100963
101034
|
process$1.nextTick(readAndResolve, iter);
|
|
100964
101035
|
}
|
|
100965
101036
|
function wrapForNext(lastPromise, iter) {
|
|
100966
|
-
return function(
|
|
101037
|
+
return function(resolve6, reject) {
|
|
100967
101038
|
lastPromise.then(function() {
|
|
100968
101039
|
if (iter[kEnded]) {
|
|
100969
|
-
|
|
101040
|
+
resolve6(createIterResult(undefined, true));
|
|
100970
101041
|
return;
|
|
100971
101042
|
}
|
|
100972
|
-
iter[kHandlePromise](
|
|
101043
|
+
iter[kHandlePromise](resolve6, reject);
|
|
100973
101044
|
}, reject);
|
|
100974
101045
|
};
|
|
100975
101046
|
}
|
|
@@ -100986,12 +101057,12 @@ var init_dist = __esm(() => {
|
|
|
100986
101057
|
if (this[kEnded])
|
|
100987
101058
|
return Promise.resolve(createIterResult(undefined, true));
|
|
100988
101059
|
if (this[kStream].destroyed)
|
|
100989
|
-
return new Promise(function(
|
|
101060
|
+
return new Promise(function(resolve6, reject) {
|
|
100990
101061
|
process$1.nextTick(function() {
|
|
100991
101062
|
if (_this[kError])
|
|
100992
101063
|
reject(_this[kError]);
|
|
100993
101064
|
else
|
|
100994
|
-
|
|
101065
|
+
resolve6(createIterResult(undefined, true));
|
|
100995
101066
|
});
|
|
100996
101067
|
});
|
|
100997
101068
|
var lastPromise = this[kLastPromise];
|
|
@@ -101011,13 +101082,13 @@ var init_dist = __esm(() => {
|
|
|
101011
101082
|
return this;
|
|
101012
101083
|
}), _defineProperty2(_Object$setPrototypeO, "return", function _return() {
|
|
101013
101084
|
var _this2 = this;
|
|
101014
|
-
return new Promise(function(
|
|
101085
|
+
return new Promise(function(resolve6, reject) {
|
|
101015
101086
|
_this2[kStream].destroy(null, function(err) {
|
|
101016
101087
|
if (err) {
|
|
101017
101088
|
reject(err);
|
|
101018
101089
|
return;
|
|
101019
101090
|
}
|
|
101020
|
-
|
|
101091
|
+
resolve6(createIterResult(undefined, true));
|
|
101021
101092
|
});
|
|
101022
101093
|
});
|
|
101023
101094
|
}), _Object$setPrototypeO), AsyncIteratorPrototype);
|
|
@@ -101039,15 +101110,15 @@ var init_dist = __esm(() => {
|
|
|
101039
101110
|
value: stream._readableState.endEmitted,
|
|
101040
101111
|
writable: true
|
|
101041
101112
|
}), _defineProperty2(_Object$create, kHandlePromise, {
|
|
101042
|
-
value: function value2(
|
|
101113
|
+
value: function value2(resolve6, reject) {
|
|
101043
101114
|
var data = iterator[kStream].read();
|
|
101044
101115
|
if (data) {
|
|
101045
101116
|
iterator[kLastPromise] = null;
|
|
101046
101117
|
iterator[kLastResolve] = null;
|
|
101047
101118
|
iterator[kLastReject] = null;
|
|
101048
|
-
|
|
101119
|
+
resolve6(createIterResult(data, false));
|
|
101049
101120
|
} else {
|
|
101050
|
-
iterator[kLastResolve] =
|
|
101121
|
+
iterator[kLastResolve] = resolve6;
|
|
101051
101122
|
iterator[kLastReject] = reject;
|
|
101052
101123
|
}
|
|
101053
101124
|
},
|
|
@@ -101066,12 +101137,12 @@ var init_dist = __esm(() => {
|
|
|
101066
101137
|
iterator[kError] = err;
|
|
101067
101138
|
return;
|
|
101068
101139
|
}
|
|
101069
|
-
var
|
|
101070
|
-
if (
|
|
101140
|
+
var resolve6 = iterator[kLastResolve];
|
|
101141
|
+
if (resolve6 !== null) {
|
|
101071
101142
|
iterator[kLastPromise] = null;
|
|
101072
101143
|
iterator[kLastResolve] = null;
|
|
101073
101144
|
iterator[kLastReject] = null;
|
|
101074
|
-
|
|
101145
|
+
resolve6(createIterResult(undefined, true));
|
|
101075
101146
|
}
|
|
101076
101147
|
iterator[kEnded] = true;
|
|
101077
101148
|
});
|
|
@@ -113877,7 +113948,7 @@ Actual: ` + parser.attribValue);
|
|
|
113877
113948
|
}
|
|
113878
113949
|
}
|
|
113879
113950
|
function add(value2, last) {
|
|
113880
|
-
format(append,
|
|
113951
|
+
format(append, resolve6(value2, indent2, indent2 ? 1 : 0), last);
|
|
113881
113952
|
}
|
|
113882
113953
|
function end() {
|
|
113883
113954
|
if (stream) {
|
|
@@ -113921,13 +113992,13 @@ Actual: ` + parser.attribValue);
|
|
|
113921
113992
|
return output;
|
|
113922
113993
|
}
|
|
113923
113994
|
function element() {
|
|
113924
|
-
var self2 = { _elem:
|
|
113995
|
+
var self2 = { _elem: resolve6(Array.prototype.slice.call(arguments)) };
|
|
113925
113996
|
self2.push = function(input) {
|
|
113926
113997
|
if (!this.append)
|
|
113927
113998
|
throw new Error("not assigned to a parent!");
|
|
113928
113999
|
var that = this;
|
|
113929
114000
|
var indent2 = this._elem.indent;
|
|
113930
|
-
format(this.append,
|
|
114001
|
+
format(this.append, resolve6(input, indent2, this._elem.icount + (indent2 ? 1 : 0)), function() {
|
|
113931
114002
|
that.append(true);
|
|
113932
114003
|
});
|
|
113933
114004
|
};
|
|
@@ -113942,7 +114013,7 @@ Actual: ` + parser.attribValue);
|
|
|
113942
114013
|
function create_indent(character, count) {
|
|
113943
114014
|
return new Array(count || 0).join(character || "");
|
|
113944
114015
|
}
|
|
113945
|
-
function
|
|
114016
|
+
function resolve6(data, indent2, indent_count) {
|
|
113946
114017
|
indent_count = indent_count || 0;
|
|
113947
114018
|
var indent_spaces = create_indent(indent2, indent_count);
|
|
113948
114019
|
var name2;
|
|
@@ -113983,7 +114054,7 @@ Actual: ` + parser.attribValue);
|
|
|
113983
114054
|
if (Object.keys(value2)[0] == "_attr")
|
|
113984
114055
|
get_attributes(value2._attr);
|
|
113985
114056
|
else
|
|
113986
|
-
content3.push(
|
|
114057
|
+
content3.push(resolve6(value2, indent2, indent_count + 1));
|
|
113987
114058
|
else {
|
|
113988
114059
|
content3.pop();
|
|
113989
114060
|
isStringContent = true;
|
|
@@ -128401,7 +128472,7 @@ import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
|
128401
128472
|
// package.json
|
|
128402
128473
|
var package_default = {
|
|
128403
128474
|
name: "@v1hz/md2docx",
|
|
128404
|
-
version: "2.
|
|
128475
|
+
version: "2.7.1",
|
|
128405
128476
|
description: "基于 pandoc 的 Markdown 转 Word 工具,自动格式化 Markdown,支持自定义样式,AI 友好,用户友好。",
|
|
128406
128477
|
keywords: [
|
|
128407
128478
|
"converter",
|
|
@@ -128431,6 +128502,7 @@ var package_default = {
|
|
|
128431
128502
|
"LICENSE"
|
|
128432
128503
|
],
|
|
128433
128504
|
type: "module",
|
|
128505
|
+
main: "dist-electron/main.js",
|
|
128434
128506
|
module: "dist/index.js",
|
|
128435
128507
|
scripts: {
|
|
128436
128508
|
cli: "bun run src/index.ts",
|
|
@@ -128439,7 +128511,16 @@ var package_default = {
|
|
|
128439
128511
|
"build:exe": "bun run clean:dist && bun build src/index.ts --compile --outfile dist/md2docx.exe",
|
|
128440
128512
|
prepack: "bun run build",
|
|
128441
128513
|
test: "bun test",
|
|
128442
|
-
check: "bun tsc --noEmit && bun run oxlint && bun run oxfmt"
|
|
128514
|
+
check: "bun tsc --noEmit && bun run oxlint && bun run oxfmt",
|
|
128515
|
+
"build:electron": "bun build --target=node --format=esm --outdir=dist-electron --asset-naming=[name].[ext] -e electron ./electron/main.ts && bun build --target=node --format=cjs --outfile=dist-electron/preload.cjs -e electron ./electron/preload.ts",
|
|
128516
|
+
"build:frontend": "bun run scripts/generate-icon.ts && vite build --config frontend/vite.config.ts",
|
|
128517
|
+
electron: "bun run build:electron && bun run build:frontend && electron .",
|
|
128518
|
+
"dev:frontend": "vite --config frontend/vite.config.ts",
|
|
128519
|
+
"dev:electron": "bun run build:electron && electron .",
|
|
128520
|
+
dev: "bun run scripts/dev.ts",
|
|
128521
|
+
pack: "bun run build:electron && bun run build:frontend && electron-builder --win nsis",
|
|
128522
|
+
"pack:setup": "bun run pack",
|
|
128523
|
+
"pack:portable": "bun run build:electron && bun run build:frontend && electron-builder --win portable"
|
|
128443
128524
|
},
|
|
128444
128525
|
dependencies: {
|
|
128445
128526
|
"@resvg/resvg-wasm": "2.6.2",
|
|
@@ -128447,21 +128528,32 @@ var package_default = {
|
|
|
128447
128528
|
"beautiful-mermaid": "^1.1.3",
|
|
128448
128529
|
commander: "^15.0.0",
|
|
128449
128530
|
docx: "^9.7.1",
|
|
128531
|
+
"electron-updater": "^6.8.9",
|
|
128532
|
+
"lucide-vue-next": "^1.0.0",
|
|
128450
128533
|
pizzip: "^3.2.0",
|
|
128451
128534
|
"remark-frontmatter": "^5.0.0",
|
|
128452
128535
|
"remark-gfm": "^4.0.1",
|
|
128453
128536
|
"remark-parse": "^11.0.0",
|
|
128454
128537
|
"remark-stringify": "^11.0.0",
|
|
128455
128538
|
unified: "^11.0.5",
|
|
128539
|
+
vue: "^3.5.40",
|
|
128456
128540
|
xpath: "^0.0.34"
|
|
128457
128541
|
},
|
|
128458
128542
|
devDependencies: {
|
|
128543
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
128459
128544
|
"@types/bun": "^1.3.14",
|
|
128460
128545
|
"@types/node": "^24.0.0",
|
|
128546
|
+
"@vitejs/plugin-vue": "^6.0.8",
|
|
128547
|
+
"@vue/test-utils": "^2.4.11",
|
|
128548
|
+
electron: "^43.2.0",
|
|
128549
|
+
"electron-builder": "^26.15.3",
|
|
128550
|
+
"happy-dom": "^20.11.1",
|
|
128461
128551
|
oxfmt: "^0.58.0",
|
|
128462
128552
|
oxlint: "^1.73.0",
|
|
128463
128553
|
sharp: "^0.35.3",
|
|
128464
|
-
|
|
128554
|
+
tailwindcss: "^4.3.3",
|
|
128555
|
+
typescript: "^7.0.2",
|
|
128556
|
+
vite: "^8.1.5"
|
|
128465
128557
|
},
|
|
128466
128558
|
engines: {
|
|
128467
128559
|
node: ">=22.12.0"
|
|
@@ -128511,8 +128603,8 @@ function createProgram(version, actions) {
|
|
|
128511
128603
|
presetSaveCommand.exitOverride();
|
|
128512
128604
|
const formatCommand = program2.command("format").description("预处理并格式化 Markdown").helpOption("-h, --help", "显示帮助").requiredOption("-f, --file <path>", "Markdown 文件").option("--preset <name>", "使用指定预设中的 Markdown 处理配置").option("-c, --config <path>", "自定义配置文件").option("-o, --output <path>", "输出 Markdown 文件").action(actions.format);
|
|
128513
128605
|
formatCommand.exitOverride();
|
|
128514
|
-
const cleanCommand = program2.command("clean").description("清除 ~/.md2docx 中的预处理文件和样式缓存").helpOption("-h, --help", "显示帮助").action(async () => {
|
|
128515
|
-
await actions.clean();
|
|
128606
|
+
const cleanCommand = program2.command("clean").description("清除 ~/.md2docx 中的预处理文件和样式缓存").option("--all", "清除所有用户数据(预设、设置和缓存)").helpOption("-h, --help", "显示帮助").action(async (options) => {
|
|
128607
|
+
await actions.clean({ all: options.all ?? false });
|
|
128516
128608
|
});
|
|
128517
128609
|
cleanCommand.exitOverride();
|
|
128518
128610
|
return program2;
|
|
@@ -128545,9 +128637,7 @@ function styleTemplateDocx(hash) {
|
|
|
128545
128637
|
}
|
|
128546
128638
|
|
|
128547
128639
|
// src/commands/clean.ts
|
|
128548
|
-
function
|
|
128549
|
-
const home = resolve2(paths.homeDir);
|
|
128550
|
-
const target = resolve2(paths.targetDir);
|
|
128640
|
+
function validateTarget(target, home) {
|
|
128551
128641
|
const expected = resolve2(home, ".md2docx");
|
|
128552
128642
|
if (target !== expected || dirname(target) !== home) {
|
|
128553
128643
|
throw new Error(`拒绝清理非预期目录:${target}`);
|
|
@@ -128559,6 +128649,18 @@ function cleanIntermediateFiles(paths = { targetDir: TMP_DIR, homeDir: homedir2(
|
|
|
128559
128649
|
if (lstatSync(target).isSymbolicLink()) {
|
|
128560
128650
|
throw new Error(`拒绝清理符号链接目录:${target}`);
|
|
128561
128651
|
}
|
|
128652
|
+
}
|
|
128653
|
+
function cleanIntermediateFiles(paths = {}) {
|
|
128654
|
+
const home = resolve2(paths.homeDir ?? homedir2());
|
|
128655
|
+
const target = resolve2(paths.targetDir ?? TMP_DIR);
|
|
128656
|
+
validateTarget(target, home);
|
|
128657
|
+
if (!existsSync(target))
|
|
128658
|
+
return;
|
|
128659
|
+
if (paths.all) {
|
|
128660
|
+
rmSync(target, { recursive: true, force: true });
|
|
128661
|
+
console.log(`已清除所有用户数据:${target}`);
|
|
128662
|
+
return;
|
|
128663
|
+
}
|
|
128562
128664
|
for (const name2 of ["preprocess", "resources", "style"]) {
|
|
128563
128665
|
const cachePath = resolve2(target, name2);
|
|
128564
128666
|
if (dirname(cachePath) !== target)
|
|
@@ -128576,7 +128678,7 @@ function cleanIntermediateFiles(paths = { targetDir: TMP_DIR, homeDir: homedir2(
|
|
|
128576
128678
|
// src/commands/convert.ts
|
|
128577
128679
|
import { existsSync as existsSync7, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
128578
128680
|
import { spawn } from "node:child_process";
|
|
128579
|
-
import { dirname as dirname7, parse as parse4, resolve as
|
|
128681
|
+
import { dirname as dirname7, parse as parse4, resolve as resolve6 } from "node:path";
|
|
128580
128682
|
|
|
128581
128683
|
// src/config.ts
|
|
128582
128684
|
import { access, readFile } from "node:fs/promises";
|
|
@@ -128594,16 +128696,26 @@ async function loadConfig(path2) {
|
|
|
128594
128696
|
throw new Error(`配置文件不是有效的 JSON:${path2}
|
|
128595
128697
|
${message}`);
|
|
128596
128698
|
}
|
|
128597
|
-
|
|
128598
|
-
delete raw.$schema;
|
|
128599
|
-
return raw;
|
|
128699
|
+
return validateConfigValue(raw, path2);
|
|
128600
128700
|
}
|
|
128601
|
-
function
|
|
128701
|
+
function validateConfigValue(value, path2) {
|
|
128602
128702
|
const root = expectRecord(value, path2, "配置");
|
|
128703
|
+
rejectUnknown(root, [
|
|
128704
|
+
"$schema",
|
|
128705
|
+
"figureCaption",
|
|
128706
|
+
"tableCaption",
|
|
128707
|
+
"normalizeHeadings",
|
|
128708
|
+
"numberHeadings",
|
|
128709
|
+
"renderMermaid",
|
|
128710
|
+
"imageSize",
|
|
128711
|
+
"detectTitle",
|
|
128712
|
+
"removeThematicBreaks"
|
|
128713
|
+
], path2, "配置");
|
|
128603
128714
|
validateCaption(root.figureCaption, path2, "figureCaption");
|
|
128604
128715
|
validateCaption(root.tableCaption, path2, "tableCaption");
|
|
128605
128716
|
validateEnabled(root.normalizeHeadings, path2, "normalizeHeadings");
|
|
128606
128717
|
const numbering = expectRecord(root.numberHeadings, path2, "numberHeadings");
|
|
128718
|
+
rejectUnknown(numbering, ["enabled", "detectExisting", "existingPattern", "useBuiltinRules"], path2, "numberHeadings");
|
|
128607
128719
|
expectBoolean(numbering.enabled, path2, "numberHeadings.enabled");
|
|
128608
128720
|
expectBoolean(numbering.detectExisting, path2, "numberHeadings.detectExisting");
|
|
128609
128721
|
if (numbering.existingPattern !== undefined) {
|
|
@@ -128613,31 +128725,39 @@ function validateConfig(value, path2) {
|
|
|
128613
128725
|
expectBoolean(numbering.useBuiltinRules, path2, "numberHeadings.useBuiltinRules");
|
|
128614
128726
|
}
|
|
128615
128727
|
const mermaid = expectRecord(root.renderMermaid, path2, "renderMermaid");
|
|
128728
|
+
rejectUnknown(mermaid, ["enabled", "theme", "density"], path2, "renderMermaid");
|
|
128616
128729
|
expectBoolean(mermaid.enabled, path2, "renderMermaid.enabled");
|
|
128617
128730
|
expectString(mermaid.theme, path2, "renderMermaid.theme");
|
|
128618
128731
|
if (!Number.isInteger(mermaid.density) || mermaid.density < 72) {
|
|
128619
128732
|
invalidConfig(path2, "renderMermaid.density", "必须是不小于 72 的整数");
|
|
128620
128733
|
}
|
|
128621
128734
|
const imageSize = expectRecord(root.imageSize, path2, "imageSize");
|
|
128735
|
+
rejectUnknown(imageSize, ["enabled", "maxWidthCm", "maxHeightCm"], path2, "imageSize");
|
|
128622
128736
|
expectBoolean(imageSize.enabled, path2, "imageSize.enabled");
|
|
128623
128737
|
expectPositiveNumber(imageSize.maxWidthCm, path2, "imageSize.maxWidthCm");
|
|
128624
128738
|
expectPositiveNumber(imageSize.maxHeightCm, path2, "imageSize.maxHeightCm");
|
|
128625
128739
|
validateEnabled(root.removeThematicBreaks, path2, "removeThematicBreaks");
|
|
128626
128740
|
const title = expectRecord(root.detectTitle, path2, "detectTitle");
|
|
128741
|
+
rejectUnknown(title, ["enabled", "strategy"], path2, "detectTitle");
|
|
128627
128742
|
expectBoolean(title.enabled, path2, "detectTitle.enabled");
|
|
128628
128743
|
const strategy = expectString(title.strategy, path2, "detectTitle.strategy");
|
|
128629
128744
|
if (!["first-h1", "single-h1", "filename", "none"].includes(strategy)) {
|
|
128630
128745
|
invalidConfig(path2, "detectTitle.strategy", "不是支持的标题提取策略");
|
|
128631
128746
|
}
|
|
128747
|
+
const result = structuredClone(root);
|
|
128748
|
+
delete result.$schema;
|
|
128749
|
+
return result;
|
|
128632
128750
|
}
|
|
128633
128751
|
function validateCaption(value, path2, field) {
|
|
128634
128752
|
const caption = expectRecord(value, path2, field);
|
|
128753
|
+
rejectUnknown(caption, ["enabled", "format", "separator"], path2, field);
|
|
128635
128754
|
expectBoolean(caption.enabled, path2, `${field}.enabled`);
|
|
128636
128755
|
expectString(caption.format, path2, `${field}.format`);
|
|
128637
128756
|
expectString(caption.separator, path2, `${field}.separator`);
|
|
128638
128757
|
}
|
|
128639
128758
|
function validateEnabled(value, path2, field) {
|
|
128640
128759
|
const config = expectRecord(value, path2, field);
|
|
128760
|
+
rejectUnknown(config, ["enabled"], path2, field);
|
|
128641
128761
|
expectBoolean(config.enabled, path2, `${field}.enabled`);
|
|
128642
128762
|
}
|
|
128643
128763
|
function expectRecord(value, path2, field) {
|
|
@@ -128662,6 +128782,11 @@ function expectPositiveNumber(value, path2, field) {
|
|
|
128662
128782
|
}
|
|
128663
128783
|
return value;
|
|
128664
128784
|
}
|
|
128785
|
+
function rejectUnknown(value, allowed, path2, field) {
|
|
128786
|
+
const unknown = Object.keys(value).find((key) => !allowed.includes(key));
|
|
128787
|
+
if (unknown !== undefined)
|
|
128788
|
+
invalidConfig(path2, `${field}.${unknown}`, "不是支持的配置项");
|
|
128789
|
+
}
|
|
128665
128790
|
function invalidConfig(path2, field, reason) {
|
|
128666
128791
|
throw new Error(`配置文件无效:${path2}
|
|
128667
128792
|
位置:${field}
|
|
@@ -128672,6 +128797,7 @@ function invalidConfig(path2, field, reason) {
|
|
|
128672
128797
|
import {
|
|
128673
128798
|
copyFileSync,
|
|
128674
128799
|
existsSync as existsSync4,
|
|
128800
|
+
lstatSync as lstatSync2,
|
|
128675
128801
|
mkdirSync as mkdirSync3,
|
|
128676
128802
|
mkdtempSync,
|
|
128677
128803
|
readdirSync,
|
|
@@ -128682,7 +128808,7 @@ import {
|
|
|
128682
128808
|
writeFileSync as writeFileSync2
|
|
128683
128809
|
} from "node:fs";
|
|
128684
128810
|
import { randomUUID } from "node:crypto";
|
|
128685
|
-
import { dirname as dirname4, join as join3 } from "node:path";
|
|
128811
|
+
import { basename, dirname as dirname4, join as join3, resolve as resolve4 } from "node:path";
|
|
128686
128812
|
|
|
128687
128813
|
// src/output.ts
|
|
128688
128814
|
import { existsSync as existsSync2, mkdirSync, statSync } from "node:fs";
|
|
@@ -129897,7 +130023,7 @@ import { readFileSync as readFileSync2 } from "node:fs";
|
|
|
129897
130023
|
// src/style/config.ts
|
|
129898
130024
|
function validateStyleConfig(value, path2) {
|
|
129899
130025
|
const root = expectRecord2(value, path2, "样式配置");
|
|
129900
|
-
|
|
130026
|
+
rejectUnknown2(root, ["$schema", "schemaVersion", "options"], path2, "样式配置");
|
|
129901
130027
|
if (root.$schema !== undefined)
|
|
129902
130028
|
expectString2(root.$schema, path2, "$schema");
|
|
129903
130029
|
if (root.schemaVersion !== 1)
|
|
@@ -129908,10 +130034,10 @@ function validateStyleConfig(value, path2) {
|
|
|
129908
130034
|
}
|
|
129909
130035
|
function validateOptions(value, path2) {
|
|
129910
130036
|
const options = expectRecord2(value, path2, "options");
|
|
129911
|
-
|
|
130037
|
+
rejectUnknown2(options, ["body", "headings", "inlineCode", "codeBlock"], path2, "options");
|
|
129912
130038
|
if (options.body !== undefined) {
|
|
129913
130039
|
const body = expectRecord2(options.body, path2, "options.body");
|
|
129914
|
-
|
|
130040
|
+
rejectUnknown2(body, ["firstLineIndent", "lineSpacing"], path2, "options.body");
|
|
129915
130041
|
if (body.firstLineIndent !== undefined) {
|
|
129916
130042
|
expectBoolean2(body.firstLineIndent, path2, "options.body.firstLineIndent");
|
|
129917
130043
|
}
|
|
@@ -129923,7 +130049,7 @@ function validateOptions(value, path2) {
|
|
|
129923
130049
|
}
|
|
129924
130050
|
if (options.headings !== undefined) {
|
|
129925
130051
|
const headings = expectRecord2(options.headings, path2, "options.headings");
|
|
129926
|
-
|
|
130052
|
+
rejectUnknown2(headings, ["1", "2", "3", "4", "5", "6"], path2, "options.headings");
|
|
129927
130053
|
validateHeading(headings, "1", ["startOnNewPage", "alignment", "bold"], path2);
|
|
129928
130054
|
validateHeading(headings, "2", ["bold"], path2);
|
|
129929
130055
|
validateHeading(headings, "3", ["bold"], path2);
|
|
@@ -129933,14 +130059,14 @@ function validateOptions(value, path2) {
|
|
|
129933
130059
|
}
|
|
129934
130060
|
if (options.inlineCode !== undefined) {
|
|
129935
130061
|
const inlineCode = expectRecord2(options.inlineCode, path2, "options.inlineCode");
|
|
129936
|
-
|
|
130062
|
+
rejectUnknown2(inlineCode, ["background"], path2, "options.inlineCode");
|
|
129937
130063
|
if (inlineCode.background !== undefined) {
|
|
129938
130064
|
expectBoolean2(inlineCode.background, path2, "options.inlineCode.background");
|
|
129939
130065
|
}
|
|
129940
130066
|
}
|
|
129941
130067
|
if (options.codeBlock !== undefined) {
|
|
129942
130068
|
const codeBlock = expectRecord2(options.codeBlock, path2, "options.codeBlock");
|
|
129943
|
-
|
|
130069
|
+
rejectUnknown2(codeBlock, ["border"], path2, "options.codeBlock");
|
|
129944
130070
|
if (codeBlock.border !== undefined) {
|
|
129945
130071
|
expectBoolean2(codeBlock.border, path2, "options.codeBlock.border");
|
|
129946
130072
|
}
|
|
@@ -129951,7 +130077,7 @@ function validateHeading(headings, level, allowed, path2) {
|
|
|
129951
130077
|
return;
|
|
129952
130078
|
const field = `options.headings["${level}"]`;
|
|
129953
130079
|
const heading = expectRecord2(headings[level], path2, field);
|
|
129954
|
-
|
|
130080
|
+
rejectUnknown2(heading, allowed, path2, field);
|
|
129955
130081
|
if (heading.startOnNewPage !== undefined) {
|
|
129956
130082
|
expectBoolean2(heading.startOnNewPage, path2, `${field}.startOnNewPage`);
|
|
129957
130083
|
}
|
|
@@ -129963,7 +130089,7 @@ function validateHeading(headings, level, allowed, path2) {
|
|
|
129963
130089
|
if (heading.italic !== undefined)
|
|
129964
130090
|
expectBoolean2(heading.italic, path2, `${field}.italic`);
|
|
129965
130091
|
}
|
|
129966
|
-
function
|
|
130092
|
+
function rejectUnknown2(value, allowed, path2, field) {
|
|
129967
130093
|
const unknown = Object.keys(value).find((key) => !allowed.includes(key));
|
|
129968
130094
|
if (unknown !== undefined)
|
|
129969
130095
|
invalidStyleConfig(path2, `${field}.${unknown}`, "不是支持的配置项");
|
|
@@ -130000,6 +130126,9 @@ var HEADING_LEVELS = ["1", "2", "3", "4", "5", "6"];
|
|
|
130000
130126
|
function resolveEffectiveStyles(sources, defaults) {
|
|
130001
130127
|
const rawPath = sources.styleRawPath ?? defaults?.styleRawPath ?? materializeDefaultStyleRaw();
|
|
130002
130128
|
const rawStyle = loadStyleRaw(rawPath);
|
|
130129
|
+
if (sources.styleConfig) {
|
|
130130
|
+
return compileStyleConfig(rawStyle, sources.styleConfig);
|
|
130131
|
+
}
|
|
130003
130132
|
if (sources.styleConfigPath) {
|
|
130004
130133
|
return compileStyleConfig(rawStyle, loadStyleConfig(sources.styleConfigPath));
|
|
130005
130134
|
}
|
|
@@ -130190,10 +130319,12 @@ function readCurrentPresetName(paths = DEFAULT_STORAGE_PATHS) {
|
|
|
130190
130319
|
throw new Error(`预设设置不是有效的 JSON:${paths.settingsPath}
|
|
130191
130320
|
${message}`);
|
|
130192
130321
|
}
|
|
130322
|
+
if (isLegacyDesktopSettings(value))
|
|
130323
|
+
return DEFAULT_PRESET_NAME;
|
|
130193
130324
|
if (!isRecord3(value) || value.schemaVersion !== 1 || typeof value.preset !== "string") {
|
|
130194
130325
|
throw new Error(`预设设置无效:${paths.settingsPath}`);
|
|
130195
130326
|
}
|
|
130196
|
-
const unknownKeys = Object.keys(value).filter((key) => key !== "schemaVersion" && key !== "preset");
|
|
130327
|
+
const unknownKeys = Object.keys(value).filter((key) => key !== "schemaVersion" && key !== "preset" && key !== "desktop");
|
|
130197
130328
|
if (unknownKeys.length > 0) {
|
|
130198
130329
|
throw new Error(`预设设置无效:${paths.settingsPath}
|
|
130199
130330
|
未知字段:${unknownKeys.join(", ")}`);
|
|
@@ -130277,7 +130408,12 @@ async function usePreset(name2, paths = DEFAULT_STORAGE_PATHS) {
|
|
|
130277
130408
|
await resolvePresetByName(name2, paths);
|
|
130278
130409
|
mkdirSync3(dirname4(paths.settingsPath), { recursive: true });
|
|
130279
130410
|
const temporary = `${paths.settingsPath}.${process.pid}.${randomUUID()}.tmp`;
|
|
130280
|
-
|
|
130411
|
+
const desktop = readExistingDesktopSettings(paths.settingsPath);
|
|
130412
|
+
writeFileSync2(temporary, `${JSON.stringify({
|
|
130413
|
+
schemaVersion: 1,
|
|
130414
|
+
preset: name2,
|
|
130415
|
+
...desktop ? { desktop } : {}
|
|
130416
|
+
}, null, 2)}
|
|
130281
130417
|
`, "utf-8");
|
|
130282
130418
|
try {
|
|
130283
130419
|
renameSync(temporary, paths.settingsPath);
|
|
@@ -130286,6 +130422,18 @@ async function usePreset(name2, paths = DEFAULT_STORAGE_PATHS) {
|
|
|
130286
130422
|
throw error;
|
|
130287
130423
|
}
|
|
130288
130424
|
}
|
|
130425
|
+
function readExistingDesktopSettings(settingsPath) {
|
|
130426
|
+
if (!existsSync4(settingsPath))
|
|
130427
|
+
return;
|
|
130428
|
+
try {
|
|
130429
|
+
const value = JSON.parse(readFileSync3(settingsPath, "utf-8"));
|
|
130430
|
+
if (isLegacyDesktopSettings(value))
|
|
130431
|
+
return value;
|
|
130432
|
+
return isRecord3(value) && isRecord3(value.desktop) ? value.desktop : undefined;
|
|
130433
|
+
} catch {
|
|
130434
|
+
return;
|
|
130435
|
+
}
|
|
130436
|
+
}
|
|
130289
130437
|
async function savePreset(input, paths = DEFAULT_STORAGE_PATHS) {
|
|
130290
130438
|
assertPresetName(input.name);
|
|
130291
130439
|
if (input.name === DEFAULT_PRESET_NAME)
|
|
@@ -130372,6 +130520,12 @@ function assertPresetName(name2) {
|
|
|
130372
130520
|
function isRecord3(value) {
|
|
130373
130521
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
130374
130522
|
}
|
|
130523
|
+
function isLegacyDesktopSettings(value) {
|
|
130524
|
+
if (!isRecord3(value))
|
|
130525
|
+
return false;
|
|
130526
|
+
const keys = Object.keys(value);
|
|
130527
|
+
return keys.length === 3 && keys.every((key) => ["outputMode", "outputFolder", "conflictAction"].includes(key)) && ["source", "folder", "ask"].includes(String(value.outputMode)) && typeof value.outputFolder === "string" && ["overwrite", "rename", "ask"].includes(String(value.conflictAction));
|
|
130528
|
+
}
|
|
130375
130529
|
|
|
130376
130530
|
// src/preprocess/index.ts
|
|
130377
130531
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
@@ -130664,10 +130818,10 @@ class VFile {
|
|
|
130664
130818
|
get basename() {
|
|
130665
130819
|
return typeof this.path === "string" ? default2.basename(this.path) : undefined;
|
|
130666
130820
|
}
|
|
130667
|
-
set basename(
|
|
130668
|
-
assertNonEmpty(
|
|
130669
|
-
assertPart(
|
|
130670
|
-
this.path = default2.join(this.dirname || "",
|
|
130821
|
+
set basename(basename2) {
|
|
130822
|
+
assertNonEmpty(basename2, "basename");
|
|
130823
|
+
assertPart(basename2, "basename");
|
|
130824
|
+
this.path = default2.join(this.dirname || "", basename2);
|
|
130671
130825
|
}
|
|
130672
130826
|
get dirname() {
|
|
130673
130827
|
return typeof this.path === "string" ? default2.dirname(this.path) : undefined;
|
|
@@ -130851,7 +131005,7 @@ class Processor extends CallableInstance {
|
|
|
130851
131005
|
assertParser("process", this.parser || this.Parser);
|
|
130852
131006
|
assertCompiler("process", this.compiler || this.Compiler);
|
|
130853
131007
|
return done ? executor(undefined, done) : new Promise(executor);
|
|
130854
|
-
function executor(
|
|
131008
|
+
function executor(resolve5, reject) {
|
|
130855
131009
|
const realFile = vfile(file);
|
|
130856
131010
|
const parseTree = self2.parse(realFile);
|
|
130857
131011
|
self2.run(parseTree, realFile, function(error, tree, file2) {
|
|
@@ -130870,8 +131024,8 @@ class Processor extends CallableInstance {
|
|
|
130870
131024
|
function realDone(error, file2) {
|
|
130871
131025
|
if (error || !file2) {
|
|
130872
131026
|
reject(error);
|
|
130873
|
-
} else if (
|
|
130874
|
-
|
|
131027
|
+
} else if (resolve5) {
|
|
131028
|
+
resolve5(file2);
|
|
130875
131029
|
} else {
|
|
130876
131030
|
ok(done, "`done` is defined if `resolve` is not");
|
|
130877
131031
|
done(undefined, file2);
|
|
@@ -130904,7 +131058,7 @@ class Processor extends CallableInstance {
|
|
|
130904
131058
|
file = undefined;
|
|
130905
131059
|
}
|
|
130906
131060
|
return done ? executor(undefined, done) : new Promise(executor);
|
|
130907
|
-
function executor(
|
|
131061
|
+
function executor(resolve5, reject) {
|
|
130908
131062
|
ok(typeof file !== "function", "`file` can’t be a `done` anymore, we checked");
|
|
130909
131063
|
const realFile = vfile(file);
|
|
130910
131064
|
transformers.run(tree, realFile, realDone);
|
|
@@ -130912,8 +131066,8 @@ class Processor extends CallableInstance {
|
|
|
130912
131066
|
const resultingTree = outputTree || tree;
|
|
130913
131067
|
if (error) {
|
|
130914
131068
|
reject(error);
|
|
130915
|
-
} else if (
|
|
130916
|
-
|
|
131069
|
+
} else if (resolve5) {
|
|
131070
|
+
resolve5(resultingTree);
|
|
130917
131071
|
} else {
|
|
130918
131072
|
ok(done, "`done` is defined if `resolve` is not");
|
|
130919
131073
|
done(undefined, resultingTree, file2);
|
|
@@ -133993,10 +134147,10 @@ function resolveAll(constructs2, events, context) {
|
|
|
133993
134147
|
const called = [];
|
|
133994
134148
|
let index2 = -1;
|
|
133995
134149
|
while (++index2 < constructs2.length) {
|
|
133996
|
-
const
|
|
133997
|
-
if (
|
|
133998
|
-
events =
|
|
133999
|
-
called.push(
|
|
134150
|
+
const resolve5 = constructs2[index2].resolveAll;
|
|
134151
|
+
if (resolve5 && !called.includes(resolve5)) {
|
|
134152
|
+
events = resolve5(events, context);
|
|
134153
|
+
called.push(resolve5);
|
|
134000
134154
|
}
|
|
134001
134155
|
}
|
|
134002
134156
|
return events;
|
|
@@ -142096,7 +142250,7 @@ function stripPictureNum(text5, format) {
|
|
|
142096
142250
|
import { existsSync as existsSync5, mkdirSync as mkdirSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
142097
142251
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
142098
142252
|
import { homedir as homedir3 } from "node:os";
|
|
142099
|
-
import { dirname as dirname5, isAbsolute, join as join5, resolve as
|
|
142253
|
+
import { dirname as dirname5, isAbsolute, join as join5, resolve as resolve5 } from "node:path";
|
|
142100
142254
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
142101
142255
|
|
|
142102
142256
|
// node_modules/@resvg/resvg-wasm/index.mjs
|
|
@@ -147497,7 +147651,7 @@ function renderMermaidSVG(text5, options = {}) {
|
|
|
147497
147651
|
// src/preprocess/mermaid.ts
|
|
147498
147652
|
var wasmInitialization;
|
|
147499
147653
|
var fontLoading;
|
|
147500
|
-
var RESVG_WASM_PATH = isAbsolute(index_bg_default) ? index_bg_default :
|
|
147654
|
+
var RESVG_WASM_PATH = isAbsolute(index_bg_default) ? index_bg_default : resolve5(dirname5(fileURLToPath2(import.meta.url)), index_bg_default);
|
|
147501
147655
|
function initializeResvg() {
|
|
147502
147656
|
const wasm2 = typeof Bun === "undefined" ? readFile2(RESVG_WASM_PATH) : Bun.file(RESVG_WASM_PATH).arrayBuffer();
|
|
147503
147657
|
wasmInitialization ??= initWasm(wasm2);
|
|
@@ -147508,7 +147662,7 @@ function loadSystemFonts() {
|
|
|
147508
147662
|
return fontLoading;
|
|
147509
147663
|
}
|
|
147510
147664
|
async function loadSystemFontsUncached() {
|
|
147511
|
-
const fontPaths = process.platform === "win32" ? ["msyh.ttc", "msyhbd.ttc", "arial.ttf", "consola.ttf"].map((name2) =>
|
|
147665
|
+
const fontPaths = process.platform === "win32" ? ["msyh.ttc", "msyhbd.ttc", "arial.ttf", "consola.ttf"].map((name2) => resolve5(process.env.WINDIR ?? "C:/Windows", "Fonts", name2)) : process.platform === "darwin" ? [
|
|
147512
147666
|
"/System/Library/Fonts/PingFang.ttc",
|
|
147513
147667
|
"/System/Library/Fonts/Helvetica.ttc",
|
|
147514
147668
|
"/System/Library/Fonts/Menlo.ttc"
|
|
@@ -147837,7 +147991,7 @@ async function ensureTemplateDocx(rawStyle) {
|
|
|
147837
147991
|
}
|
|
147838
147992
|
|
|
147839
147993
|
// src/commands/convert.ts
|
|
147840
|
-
async function convertMarkdown(options) {
|
|
147994
|
+
async function convertMarkdown(options, overrides = {}) {
|
|
147841
147995
|
if (!options.file)
|
|
147842
147996
|
throw new Error("缺少必填参数:--file");
|
|
147843
147997
|
const input = resolveInputPath(options.file, [".md", ".markdown"], "Markdown 文件");
|
|
@@ -147848,13 +148002,19 @@ async function convertMarkdown(options) {
|
|
|
147848
148002
|
const baseName = parse4(input).name;
|
|
147849
148003
|
const output = resolveOutputPath(options.output, `${baseName}.docx`, [".docx"], "DOCX 输出文件");
|
|
147850
148004
|
prepareOutput(output);
|
|
147851
|
-
const config = await loadConfig(configPath);
|
|
148005
|
+
const config = overrides.config ? validateConfigValue(structuredClone(overrides.config), "桌面转换设置") : await loadConfig(configPath);
|
|
147852
148006
|
const outDir = preprocessDir(input);
|
|
147853
148007
|
mkdirSync6(outDir, { recursive: true });
|
|
147854
148008
|
const formatted = await preprocess2(input, config, outDir);
|
|
147855
148009
|
const markdownOutput = formattedMdPath(input);
|
|
147856
148010
|
writeFileSync4(markdownOutput, formatted, "utf-8");
|
|
147857
|
-
const effectiveStyles = resolveEffectiveStyles({
|
|
148011
|
+
const effectiveStyles = resolveEffectiveStyles({
|
|
148012
|
+
styleRawPath,
|
|
148013
|
+
styleConfigPath,
|
|
148014
|
+
...overrides.styleConfig ? {
|
|
148015
|
+
styleConfig: validateStyleConfig(structuredClone(overrides.styleConfig), "桌面转换样式")
|
|
148016
|
+
} : {}
|
|
148017
|
+
}, { styleRawPath: preset.styleRawPath, styleConfigPath: preset.styleConfigPath });
|
|
147858
148018
|
const templatePath = await ensureTemplateDocx(effectiveStyles);
|
|
147859
148019
|
const inlineCodeFilter = materializeInlineCodeFilter();
|
|
147860
148020
|
const imageSizeArgs = config.imageSize.enabled ? buildImageSizePandocArgs(config.imageSize, materializeImageSizeFilter()) : [];
|
|
@@ -147867,9 +148027,16 @@ async function convertMarkdown(options) {
|
|
|
147867
148027
|
...existsSync7(inlineCodeFilter) ? [`--lua-filter=${inlineCodeFilter}`] : [],
|
|
147868
148028
|
...imageSizeArgs
|
|
147869
148029
|
];
|
|
147870
|
-
|
|
147871
|
-
|
|
147872
|
-
|
|
148030
|
+
try {
|
|
148031
|
+
const { exitCode, stderr } = await runProcess("pandoc", pandocArgs);
|
|
148032
|
+
if (exitCode !== 0) {
|
|
148033
|
+
throw new Error(`pandoc 转换失败 (exit code ${exitCode}):${stderr.trim()}`);
|
|
148034
|
+
}
|
|
148035
|
+
} catch (error) {
|
|
148036
|
+
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
|
|
148037
|
+
throw new Error("未找到 pandoc,请安装 pandoc (https://pandoc.org/installing.html) " + "并将其添加到系统 PATH 环境变量后重试");
|
|
148038
|
+
}
|
|
148039
|
+
throw error;
|
|
147873
148040
|
}
|
|
147874
148041
|
console.log(`已生成:${output}`);
|
|
147875
148042
|
}
|
|
@@ -147883,13 +148050,13 @@ function buildImageSizePandocArgs(config, filterPath) {
|
|
|
147883
148050
|
];
|
|
147884
148051
|
}
|
|
147885
148052
|
function buildPandocResourcePathArgs(inputPath, workingDirectory = process.cwd()) {
|
|
147886
|
-
const workingDir =
|
|
147887
|
-
const sourceDir = dirname7(
|
|
148053
|
+
const workingDir = resolve6(workingDirectory);
|
|
148054
|
+
const sourceDir = dirname7(resolve6(inputPath));
|
|
147888
148055
|
const searchDirs = workingDir === sourceDir ? [sourceDir] : [workingDir, sourceDir];
|
|
147889
148056
|
return searchDirs.map((directory) => `--resource-path=${directory}`);
|
|
147890
148057
|
}
|
|
147891
148058
|
function runProcess(command, args) {
|
|
147892
|
-
return new Promise((
|
|
148059
|
+
return new Promise((resolve7, reject) => {
|
|
147893
148060
|
const child = spawn(command, args, { stdio: ["ignore", "ignore", "pipe"], windowsHide: true });
|
|
147894
148061
|
let stderr = "";
|
|
147895
148062
|
child.stderr.setEncoding("utf-8");
|
|
@@ -147897,7 +148064,7 @@ function runProcess(command, args) {
|
|
|
147897
148064
|
stderr += chunk;
|
|
147898
148065
|
});
|
|
147899
148066
|
child.once("error", reject);
|
|
147900
|
-
child.once("close", (exitCode) =>
|
|
148067
|
+
child.once("close", (exitCode) => resolve7({ exitCode: exitCode ?? 1, stderr }));
|
|
147901
148068
|
});
|
|
147902
148069
|
}
|
|
147903
148070
|
|
|
@@ -148555,7 +148722,7 @@ async function exportStyleConfig(options) {
|
|
|
148555
148722
|
|
|
148556
148723
|
// src/commands/format.ts
|
|
148557
148724
|
import { existsSync as existsSync8, rmSync as rmSync3, writeFileSync as writeFileSync6 } from "node:fs";
|
|
148558
|
-
import { basename, dirname as dirname8, parse as parse6, resolve as
|
|
148725
|
+
import { basename as basename2, dirname as dirname8, parse as parse6, resolve as resolve7 } from "node:path";
|
|
148559
148726
|
async function formatMarkdown(options) {
|
|
148560
148727
|
const input = resolveInputPath(options.file, [".md", ".markdown"], "Markdown 文件");
|
|
148561
148728
|
const preset = await resolvePresetConfig(options.preset);
|
|
@@ -148566,14 +148733,14 @@ async function formatMarkdown(options) {
|
|
|
148566
148733
|
const config = await loadConfig(configPath);
|
|
148567
148734
|
const outputName = parse6(output).name;
|
|
148568
148735
|
const assetsName = `${outputName}_assets`;
|
|
148569
|
-
const assetsDir =
|
|
148736
|
+
const assetsDir = resolve7(dirname8(output), assetsName);
|
|
148570
148737
|
if (config.renderMermaid.enabled && existsSync8(assetsDir)) {
|
|
148571
|
-
const parent =
|
|
148738
|
+
const parent = resolve7(dirname8(output));
|
|
148572
148739
|
if (dirname8(assetsDir) !== parent)
|
|
148573
148740
|
throw new Error(`拒绝清理非输出目录:${assetsDir}`);
|
|
148574
148741
|
rmSync3(assetsDir, { recursive: true, force: true });
|
|
148575
148742
|
}
|
|
148576
|
-
const formatted = await preprocess2(input, config, assetsDir,
|
|
148743
|
+
const formatted = await preprocess2(input, config, assetsDir, basename2(assetsDir));
|
|
148577
148744
|
writeFileSync6(output, formatted, "utf-8");
|
|
148578
148745
|
console.log(`已格式化:${output}`);
|
|
148579
148746
|
}
|