crossnote 0.9.39 → 0.9.41

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/out/cli/index.cjs CHANGED
@@ -2775,7 +2775,7 @@ var require_vega_min = __commonJS({
2775
2775
  function is(t2, e2) {
2776
2776
  null != t2 && "" !== t2 ? t2 == t2 && (++this.valid, this._ops.forEach(((n2) => n2.add(this, t2, e2)))) : ++this.missing;
2777
2777
  }
2778
- function os4(t2, e2) {
2778
+ function os5(t2, e2) {
2779
2779
  null != t2 && "" !== t2 ? t2 == t2 && (--this.valid, this._ops.forEach(((n2) => n2.rem(this, t2, e2)))) : --this.missing;
2780
2780
  }
2781
2781
  function as(t2) {
@@ -2795,7 +2795,7 @@ var require_vega_min = __commonJS({
2795
2795
  function o2(t3) {
2796
2796
  this._ops = r2, this._out = i2, this.cell = t3, this.init();
2797
2797
  }
2798
- return o2.prototype.init = rs, o2.prototype.add = is, o2.prototype.rem = os4, o2.prototype.set = as, o2.prototype.get = n2, o2.fields = t2.map(((t3) => t3.out)), o2;
2798
+ return o2.prototype.init = rs, o2.prototype.add = is, o2.prototype.rem = os5, o2.prototype.set = as, o2.prototype.get = n2, o2.fields = t2.map(((t3) => t3.out)), o2;
2799
2799
  }
2800
2800
  function ss(t2) {
2801
2801
  this._key = t2 ? l(t2) : _a, this.reset();
@@ -16102,7 +16102,7 @@ var require_vega_lite_min = __commonJS({
16102
16102
  const f2 = Va(l2, o2, r2, a2, n2.errorbar), d2 = l2.thickness, m2 = l2.size, p2 = { type: "tick", orient: s2, aria: false, ...void 0 !== d2 ? { thickness: d2 } : {}, ...void 0 !== m2 ? { size: m2 } : {} }, g2 = [...f2({ partName: "ticks", mark: p2, positionPrefix: "lower", extraEncoding: u2 }), ...f2({ partName: "ticks", mark: p2, positionPrefix: "upper", extraEncoding: u2 }), ...f2({ partName: "rule", mark: { type: "rule", ariaRoleDescription: "errorbar", ...void 0 !== d2 ? { size: d2 } : {} }, positionPrefix: "lower", endPositionPrefix: "upper", extraEncoding: u2 })];
16103
16103
  return { ...c2, transform: i2, ...g2.length > 1 ? { layer: g2 } : { ...g2[0] } };
16104
16104
  }
16105
- function os4(e2, t2) {
16105
+ function os5(e2, t2) {
16106
16106
  const { encoding: n2 } = e2;
16107
16107
  if ((function(e3) {
16108
16108
  return (Jo(e3.x) || Jo(e3.y)) && !Jo(e3.x2) && !Jo(e3.y2) && !Jo(e3.xError) && !Jo(e3.xError2) && !Jo(e3.yError) && !Jo(e3.yError2);
@@ -16145,7 +16145,7 @@ var require_vega_lite_min = __commonJS({
16145
16145
  function as(e2, t2, n2) {
16146
16146
  const { mark: i2, encoding: r2, params: o2, projection: a2, ...s2 } = e2, l2 = Zr(i2) ? i2 : { type: i2 };
16147
16147
  o2 && $i(Jn(t2));
16148
- const { orient: c2, inputType: u2 } = os4(e2, t2), { continuousAxisChannelDef: f2, continuousAxisChannelDef2: d2, continuousAxisChannelDefError: m2, continuousAxisChannelDefError2: p2, continuousAxis: g2 } = Ya(e2, c2, t2), { errorBarSpecificAggregate: h2, postAggregateCalculates: y2, tooltipSummary: v2, tooltipTitleWithFieldName: b2 } = (function(e3, t3, n3, i3, r3, o3, a3, s3) {
16148
+ const { orient: c2, inputType: u2 } = os5(e2, t2), { continuousAxisChannelDef: f2, continuousAxisChannelDef2: d2, continuousAxisChannelDefError: m2, continuousAxisChannelDefError2: p2, continuousAxis: g2 } = Ya(e2, c2, t2), { errorBarSpecificAggregate: h2, postAggregateCalculates: y2, tooltipSummary: v2, tooltipTitleWithFieldName: b2 } = (function(e3, t3, n3, i3, r3, o3, a3, s3) {
16149
16149
  let l3 = [], c3 = [];
16150
16150
  const u3 = t3.field;
16151
16151
  let f3, d3 = false;
@@ -23364,12 +23364,12 @@ __export(index_exports, {
23364
23364
  });
23365
23365
  module.exports = __toCommonJS(index_exports);
23366
23366
  var fs22 = __toESM(require("fs"));
23367
- var path26 = __toESM(require("path"));
23367
+ var path27 = __toESM(require("path"));
23368
23368
 
23369
23369
  // src/serve/index.ts
23370
23370
  var fs21 = __toESM(require("fs"));
23371
23371
  var http = __toESM(require("http"));
23372
- var path25 = __toESM(require("path"));
23372
+ var path26 = __toESM(require("path"));
23373
23373
  var import_url2 = require("url");
23374
23374
  var import_crypto_js2 = require("crypto-js");
23375
23375
 
@@ -23651,7 +23651,7 @@ async function smmsUploadImage(filePath) {
23651
23651
  }
23652
23652
  }
23653
23653
  function qiniuUploadImage(filePath, AccessKey, SecretKey, Bucket, Domain) {
23654
- return new Promise((resolve20, reject) => {
23654
+ return new Promise((resolve21, reject) => {
23655
23655
  if (!AccessKey) {
23656
23656
  return reject("Error: Qiniu AccessKey is missing");
23657
23657
  }
@@ -23684,7 +23684,7 @@ function qiniuUploadImage(filePath, AccessKey, SecretKey, Bucket, Domain) {
23684
23684
  if (respInfo.statusCode === 200) {
23685
23685
  const bucketManager = new qiniu.rs.BucketManager(mac, config);
23686
23686
  const url = bucketManager.publicDownloadUrl(Domain, key);
23687
- return resolve20(url);
23687
+ return resolve21(url);
23688
23688
  } else {
23689
23689
  return reject(respInfo.error);
23690
23690
  }
@@ -23749,8 +23749,8 @@ function openFile(filePath) {
23749
23749
  }
23750
23750
  }
23751
23751
  function openFileInWSL(filePath) {
23752
- const attempt = (spawn5, fallback) => {
23753
- const child = spawn5();
23752
+ const attempt = (spawn7, fallback) => {
23753
+ const child = spawn7();
23754
23754
  let settled = false;
23755
23755
  const tryFallback = () => {
23756
23756
  if (!settled) {
@@ -23818,8 +23818,8 @@ var crossnoteBuildDirectory_ = (() => {
23818
23818
  return "";
23819
23819
  }
23820
23820
  })();
23821
- function setCrossnoteBuildDirectory(path27) {
23822
- crossnoteBuildDirectory_ = path27;
23821
+ function setCrossnoteBuildDirectory(path28) {
23822
+ crossnoteBuildDirectory_ = path28;
23823
23823
  }
23824
23824
  function getCrossnoteBuildDirectory() {
23825
23825
  return crossnoteBuildDirectory_;
@@ -23933,12 +23933,12 @@ function replaceVariablesInString(inputString, replacements = {}) {
23933
23933
 
23934
23934
  // src/markdown-engine/index.ts
23935
23935
  var cheerio3 = __toESM(require("cheerio"));
23936
- var import_child_process13 = require("child_process");
23936
+ var import_child_process11 = require("child_process");
23937
23937
  var import_copy_anything = require("copy-anything");
23938
23938
  var import_crypto_js = __toESM(require("crypto-js"));
23939
23939
  var fs14 = __toESM(require("fs"));
23940
23940
  var import_html_escaper13 = require("html-escaper");
23941
- var path18 = __toESM(require("path"));
23941
+ var path19 = __toESM(require("path"));
23942
23942
  var YAML7 = __toESM(require("yaml"));
23943
23943
 
23944
23944
  // src/converters/ebook-convert.ts
@@ -24077,7 +24077,7 @@ function processPDF(config = {}, args) {
24077
24077
  }
24078
24078
  }
24079
24079
  function ebookConvert(src, dest, config = {}) {
24080
- return new Promise((resolve20, reject) => {
24080
+ return new Promise((resolve21, reject) => {
24081
24081
  const args = [
24082
24082
  src,
24083
24083
  dest,
@@ -24106,7 +24106,7 @@ function ebookConvert(src, dest, config = {}) {
24106
24106
  if (error2) {
24107
24107
  return reject(error2.toString());
24108
24108
  } else {
24109
- return resolve20();
24109
+ return resolve21();
24110
24110
  }
24111
24111
  });
24112
24112
  }).catch((error) => {
@@ -24567,7 +24567,7 @@ function toSVGMarkdown(pdfFilePath, {
24567
24567
  svgWidth,
24568
24568
  svgHeight
24569
24569
  }) {
24570
- return new Promise((resolve20, reject) => {
24570
+ return new Promise((resolve21, reject) => {
24571
24571
  if (!svgDirectoryPath) {
24572
24572
  if (!SVG_DIRECTORY_PATH) {
24573
24573
  SVG_DIRECTORY_PATH = mkdirSync("crossnote_pdf");
@@ -24629,7 +24629,7 @@ function toSVGMarkdown(pdfFilePath, {
24629
24629
  }
24630
24630
  }
24631
24631
  });
24632
- return resolve20(svgMarkdown);
24632
+ return resolve21(svgMarkdown);
24633
24633
  });
24634
24634
  }
24635
24635
  });
@@ -24949,7 +24949,7 @@ async function loadFile(filePath, {
24949
24949
  }
24950
24950
  if (filePath.endsWith(".less")) {
24951
24951
  const data = await notebook.fs.readFile(filePath);
24952
- return await new Promise((resolve20, reject) => {
24952
+ return await new Promise((resolve21, reject) => {
24953
24953
  less.render(
24954
24954
  data,
24955
24955
  { paths: [path5.dirname(filePath)] },
@@ -24957,7 +24957,7 @@ async function loadFile(filePath, {
24957
24957
  if (error) {
24958
24958
  return reject(error);
24959
24959
  } else {
24960
- return resolve20(output?.css || "");
24960
+ return resolve21(output?.css || "");
24961
24961
  }
24962
24962
  }
24963
24963
  );
@@ -25885,7 +25885,7 @@ function toSVGMarkdown2(texFilePath, {
25885
25885
  svgWidth,
25886
25886
  svgHeight
25887
25887
  }) {
25888
- return new Promise((resolve20, reject) => {
25888
+ return new Promise((resolve21, reject) => {
25889
25889
  const task = (0, import_child_process3.spawn)(latexEngine, [texFilePath], {
25890
25890
  cwd: path6.dirname(texFilePath)
25891
25891
  });
@@ -25919,7 +25919,7 @@ function toSVGMarkdown2(texFilePath, {
25919
25919
  svgHeight
25920
25920
  }).then((svgMarkdown) => {
25921
25921
  cleanUpFiles(texFilePath);
25922
- return resolve20(svgMarkdown);
25922
+ return resolve21(svgMarkdown);
25923
25923
  }).catch((error) => {
25924
25924
  cleanUpFiles(texFilePath);
25925
25925
  return reject(error);
@@ -26024,7 +26024,7 @@ except Exception:
26024
26024
  if (!findInputFileMacro && !normalizedAttributes["stdin"]) {
26025
26025
  args.push(savePath);
26026
26026
  }
26027
- return await new Promise((resolve20) => {
26027
+ return await new Promise((resolve21) => {
26028
26028
  const task = (0, import_child_process4.spawn)(cmd, args, { cwd: fileDirectoryPath });
26029
26029
  if (normalizedAttributes["stdin"]) {
26030
26030
  task.stdin.write(content);
@@ -26043,7 +26043,7 @@ except Exception:
26043
26043
  task.on("close", async () => {
26044
26044
  await (0, import_promises.unlink)(savePath);
26045
26045
  const data = Buffer.concat(chunks).toString();
26046
- resolve20(data);
26046
+ resolve21(data);
26047
26047
  });
26048
26048
  });
26049
26049
  }
@@ -26114,8 +26114,8 @@ var PlantUMLTask = class {
26114
26114
  this.startTask();
26115
26115
  }
26116
26116
  generateSVG(content) {
26117
- return new Promise((resolve20) => {
26118
- this.callbacks.push(resolve20);
26117
+ return new Promise((resolve21) => {
26118
+ this.callbacks.push(resolve21);
26119
26119
  this.task?.stdin.write(content + "\n");
26120
26120
  });
26121
26121
  }
@@ -26305,8 +26305,8 @@ async function svgElementToPNGFile(svgElement, pngFilePath, imageMagickPath = ""
26305
26305
  }
26306
26306
 
26307
26307
  // src/tools/mermaid.ts
26308
- var import_child_process7 = require("child_process");
26309
26308
  var fs7 = __toESM(require("fs"));
26309
+ var import_cross_spawn = __toESM(require("cross-spawn"));
26310
26310
  async function mermaidToPNG(mermaidCode, pngFilePath, projectDirectoryPath, themeName) {
26311
26311
  const info = await tempOpen({
26312
26312
  prefix: "crossnote-mermaid",
@@ -26317,7 +26317,7 @@ async function mermaidToPNG(mermaidCode, pngFilePath, projectDirectoryPath, them
26317
26317
  themeName = "null";
26318
26318
  }
26319
26319
  try {
26320
- (0, import_child_process7.execFileSync)(
26320
+ const result = import_cross_spawn.default.sync(
26321
26321
  "npx",
26322
26322
  [
26323
26323
  "-p",
@@ -26331,10 +26331,18 @@ async function mermaidToPNG(mermaidCode, pngFilePath, projectDirectoryPath, them
26331
26331
  pngFilePath
26332
26332
  ],
26333
26333
  {
26334
- shell: true,
26335
- cwd: projectDirectoryPath
26334
+ cwd: projectDirectoryPath,
26335
+ // Match the old `execFileSync` behavior: the CLI's errors stream to
26336
+ // our stderr; neither stream is read here.
26337
+ stdio: ["ignore", "ignore", "inherit"]
26336
26338
  }
26337
26339
  );
26340
+ if (result.error) {
26341
+ throw result.error;
26342
+ }
26343
+ if (result.status !== 0) {
26344
+ throw new Error(`mermaid CLI exited with code ${result.status}`);
26345
+ }
26338
26346
  return pngFilePath;
26339
26347
  } catch (error) {
26340
26348
  throw new Error(
@@ -26369,8 +26377,8 @@ Please make sure you have libvips installed.`,
26369
26377
  }
26370
26378
 
26371
26379
  // src/tools/wavedrom.ts
26372
- var import_child_process8 = require("child_process");
26373
26380
  var fs8 = __toESM(require("fs"));
26381
+ var import_cross_spawn2 = __toESM(require("cross-spawn"));
26374
26382
  async function render3(wavedromCode, projectDirectoryPath) {
26375
26383
  const info = await tempOpen({
26376
26384
  prefix: "crossnote-wavedrom",
@@ -26378,11 +26386,19 @@ async function render3(wavedromCode, projectDirectoryPath) {
26378
26386
  });
26379
26387
  await fs8.writeFileSync(info.fd, wavedromCode);
26380
26388
  try {
26381
- const svg = (await (0, import_child_process8.execFileSync)("npx", ["wavedrom-cli", "-i", info.path], {
26382
- shell: true,
26383
- cwd: projectDirectoryPath
26384
- })).toString("utf-8");
26385
- return svg;
26389
+ const result = import_cross_spawn2.default.sync("npx", ["wavedrom-cli", "-i", info.path], {
26390
+ cwd: projectDirectoryPath,
26391
+ // stdout carries the SVG; stderr streams to our console like the old
26392
+ // `execFileSync` call did.
26393
+ stdio: ["ignore", "pipe", "inherit"]
26394
+ });
26395
+ if (result.error) {
26396
+ throw result.error;
26397
+ }
26398
+ if (result.status !== 0) {
26399
+ throw new Error(`wavedrom CLI exited with code ${result.status}`);
26400
+ }
26401
+ return result.stdout.toString("utf-8");
26386
26402
  } catch (error) {
26387
26403
  throw new Error(
26388
26404
  "wavedrom CLI is required to be installed.\nCheck http://github.com/wavedrom/cli for more information.",
@@ -26934,7 +26950,7 @@ async function markdownConvert(text, {
26934
26950
  mathBlockDelimiters: notebook.config.mathBlockDelimiters,
26935
26951
  mathRenderingOnlineService: notebook.config.mathRenderingOnlineService
26936
26952
  }) : text;
26937
- return await new Promise((resolve20, reject) => {
26953
+ return await new Promise((resolve21, reject) => {
26938
26954
  (0, import_mkdirp2.mkdirp)(imageDirectoryPath).then(() => {
26939
26955
  processGraphs(text, {
26940
26956
  fileDirectoryPath,
@@ -26957,7 +26973,7 @@ async function markdownConvert(text, {
26957
26973
  if (error2) {
26958
26974
  return reject(error2.toString());
26959
26975
  }
26960
- return resolve20(outputFilePath);
26976
+ return resolve21(outputFilePath);
26961
26977
  }
26962
26978
  );
26963
26979
  });
@@ -26970,7 +26986,7 @@ async function markdownConvert(text, {
26970
26986
  }
26971
26987
 
26972
26988
  // src/converters/pandoc-convert.ts
26973
- var import_child_process9 = require("child_process");
26989
+ var import_child_process7 = require("child_process");
26974
26990
  var fs10 = __toESM(require("fs"));
26975
26991
  var mkdirp3 = __toESM(require("mkdirp"));
26976
26992
  var path11 = __toESM(require("path"));
@@ -27278,8 +27294,8 @@ async function pandocConvert(text, {
27278
27294
  notebook
27279
27295
  });
27280
27296
  await mkdirp3.sync(path11.dirname(outputFilePath));
27281
- return await new Promise((resolve20, reject) => {
27282
- const program = (0, import_child_process9.execFile)(
27297
+ return await new Promise((resolve21, reject) => {
27298
+ const program = (0, import_child_process7.execFile)(
27283
27299
  notebook.config.pandocPath,
27284
27300
  args,
27285
27301
  { cwd: fileDirectoryPath },
@@ -27287,7 +27303,7 @@ async function pandocConvert(text, {
27287
27303
  if (error) {
27288
27304
  return reject(error.toString());
27289
27305
  } else {
27290
- return resolve20(outputFilePath);
27306
+ return resolve21(outputFilePath);
27291
27307
  }
27292
27308
  }
27293
27309
  );
@@ -27296,10 +27312,10 @@ async function pandocConvert(text, {
27296
27312
  }
27297
27313
 
27298
27314
  // src/converters/prince-convert.ts
27299
- var import_child_process10 = require("child_process");
27315
+ var import_child_process8 = require("child_process");
27300
27316
  function princeConvert(src, dest) {
27301
- return new Promise((resolve20, reject) => {
27302
- (0, import_child_process10.execFile)(
27317
+ return new Promise((resolve21, reject) => {
27318
+ (0, import_child_process8.execFile)(
27303
27319
  "prince",
27304
27320
  [src, "--javascript", "-o", dest],
27305
27321
  (error) => {
@@ -27310,17 +27326,86 @@ function princeConvert(src, dest) {
27310
27326
  }
27311
27327
  return reject(errorMessage);
27312
27328
  }
27313
- return resolve20();
27329
+ return resolve21();
27314
27330
  }
27315
27331
  );
27316
27332
  });
27317
27333
  }
27318
27334
 
27335
+ // src/lib/css-urls.ts
27336
+ var path12 = __toESM(require("path"));
27337
+ var ABSOLUTE_URL = /^(data:|https?:|file:|\/\/)/i;
27338
+ var CSS_URL = /url\(\s*(['"]?)([^'")]+)\1\s*\)(\s*format\([^)]+\))?/gi;
27339
+ var ABSOLUTE_FS_PATH = /^(\/|[A-Za-z]:[\\/])/;
27340
+ async function resolveRelativeCssUrls(css, baseDir, exists) {
27341
+ const root = path12.resolve(baseDir);
27342
+ const candidates = [];
27343
+ css.replace(CSS_URL, (_whole, _quote, rawUrl) => {
27344
+ candidates.push(rawUrl.trim());
27345
+ return "";
27346
+ });
27347
+ const resolutions = await Promise.all(
27348
+ candidates.map(async (url) => {
27349
+ if (!url || url.startsWith("#") || ABSOLUTE_URL.test(url)) {
27350
+ return null;
27351
+ }
27352
+ if (ABSOLUTE_FS_PATH.test(url)) {
27353
+ return null;
27354
+ }
27355
+ const [, filePart, suffix = ""] = url.match(/^([^?#]*)([?#].*)?$/) ?? [];
27356
+ if (!filePart) {
27357
+ return null;
27358
+ }
27359
+ const resolved = path12.resolve(baseDir, filePart);
27360
+ if (resolved !== root && !resolved.startsWith(root + path12.sep)) {
27361
+ return null;
27362
+ }
27363
+ if (!await exists(resolved)) {
27364
+ return null;
27365
+ }
27366
+ return resolved + suffix;
27367
+ })
27368
+ );
27369
+ let i = 0;
27370
+ return css.replace(
27371
+ CSS_URL,
27372
+ (whole, _quote, _rawUrl, formatPart = "") => {
27373
+ const resolved = resolutions[i++];
27374
+ if (resolved === null) {
27375
+ return whole;
27376
+ }
27377
+ return `url("${escapeCssUrl(resolved)}")${formatPart}`;
27378
+ }
27379
+ );
27380
+ }
27381
+ function mapAbsoluteCssUrls(css, toUrl) {
27382
+ return css.replace(
27383
+ CSS_URL,
27384
+ (whole, _quote, rawUrl, formatPart = "") => {
27385
+ const url = rawUrl.trim();
27386
+ if (ABSOLUTE_URL.test(url) || !ABSOLUTE_FS_PATH.test(url)) {
27387
+ return whole;
27388
+ }
27389
+ const [, filePart, suffix = ""] = url.match(/^([^?#]*)([?#].*)?$/) ?? [];
27390
+ if (!filePart) {
27391
+ return whole;
27392
+ }
27393
+ return `url("${escapeCssUrl(toUrl(unescapeCssUrl(filePart)) + suffix)}")${formatPart}`;
27394
+ }
27395
+ );
27396
+ }
27397
+ function escapeCssUrl(value) {
27398
+ return value.replace(/(["\\])/g, "\\$1").replace(/\n/g, "");
27399
+ }
27400
+ function unescapeCssUrl(value) {
27401
+ return value.replace(/\\(["\\])/g, "$1");
27402
+ }
27403
+
27319
27404
  // src/notebook/index.ts
27320
27405
  var import_async_mutex = require("async-mutex");
27321
27406
  var caseAnything = __toESM(require("case-anything"));
27322
27407
  var import_ignore = __toESM(require("ignore"));
27323
- var import_child_process11 = require("child_process");
27408
+ var import_child_process9 = require("child_process");
27324
27409
  var import_markdown_it = __toESM(require("markdown-it"));
27325
27410
  var import_markdown_it_abbr = __toESM(require("markdown-it-abbr"));
27326
27411
  var import_markdown_it_deflist = __toESM(require("markdown-it-deflist"));
@@ -27328,7 +27413,8 @@ var import_markdown_it_footnote = __toESM(require("markdown-it-footnote"));
27328
27413
  var import_markdown_it_mark = __toESM(require("markdown-it-mark"));
27329
27414
  var import_markdown_it_sub = __toESM(require("markdown-it-sub"));
27330
27415
  var import_markdown_it_sup = __toESM(require("markdown-it-sup"));
27331
- var path14 = __toESM(require("path"));
27416
+ var os = __toESM(require("os"));
27417
+ var path15 = __toESM(require("path"));
27332
27418
  var import_vscode_uri = require("vscode-uri");
27333
27419
 
27334
27420
  // src/renderers/parse-math.ts
@@ -31061,7 +31147,7 @@ var widget_default = (md, notebook) => {
31061
31147
  };
31062
31148
 
31063
31149
  // src/custom-markdown-it-features/wikilink.ts
31064
- var path12 = __toESM(require("path"));
31150
+ var path13 = __toESM(require("path"));
31065
31151
  var wikilink_default = (md, notebook) => {
31066
31152
  md.inline.ruler.before("autolink", "wikilink", (state, silent) => {
31067
31153
  if (!notebook.config.enableWikiLinkSyntax || !state.src.startsWith("[[", state.pos)) {
@@ -31106,9 +31192,9 @@ var wikilink_default = (md, notebook) => {
31106
31192
  filePart,
31107
31193
  notebook.currentRenderFilePath
31108
31194
  );
31109
- const currentFileDir = path12.dirname(notebook.currentRenderFilePath).replace(/\\/g, "/");
31195
+ const currentFileDir = path13.dirname(notebook.currentRenderFilePath).replace(/\\/g, "/");
31110
31196
  const resolvedNorm = resolvedPath.replace(/\\/g, "/");
31111
- const fileRelativeHref = path12.posix.relative(currentFileDir, resolvedNorm);
31197
+ const fileRelativeHref = path13.posix.relative(currentFileDir, resolvedNorm);
31112
31198
  const resolvedLink = fileRelativeHref + fragment;
31113
31199
  const displayText = content.includes("|") ? text : formatWikilinkDisplay(text);
31114
31200
  return `<a href="${md.utils.escapeHtml(resolvedLink)}">${md.utils.escapeHtml(
@@ -31145,7 +31231,7 @@ function formatWikilinkDisplay(raw) {
31145
31231
  // src/notebook/config-helper.ts
31146
31232
  var fs11 = __toESM(require("fs"));
31147
31233
  var less2 = __toESM(require("less"));
31148
- var path13 = __toESM(require("path"));
31234
+ var path14 = __toESM(require("path"));
31149
31235
 
31150
31236
  // src/lib/js-sandbox.ts
31151
31237
  var import_quickjs_singlefile_cjs_release_sync = __toESM(require("@jitl/quickjs-singlefile-cjs-release-sync"));
@@ -31458,7 +31544,7 @@ async function loadConfigsInDirectory(directoryPath, fileSystem, createDirectory
31458
31544
  return loadedConfig;
31459
31545
  }
31460
31546
  async function getGlobalStyles(configPath, fs23) {
31461
- const globalLessPath = path13.join(configPath, "./style.less");
31547
+ const globalLessPath = path14.join(configPath, "./style.less");
31462
31548
  let fileContent;
31463
31549
  try {
31464
31550
  fileContent = await fs23.readFile(globalLessPath);
@@ -31474,7 +31560,7 @@ async function getGlobalStyles(configPath, fs23) {
31474
31560
  `;
31475
31561
  await fs23.writeFile(globalLessPath, fileContent);
31476
31562
  }
31477
- return await new Promise((resolve20) => {
31563
+ return await new Promise((resolve21) => {
31478
31564
  const generateErrorMessage = (error) => {
31479
31565
  return `html body:before {
31480
31566
  content: "Failed to compile \`style.less\`. ${error}" !important;
@@ -31484,19 +31570,25 @@ async function getGlobalStyles(configPath, fs23) {
31484
31570
  };
31485
31571
  less2.render(
31486
31572
  fileContent,
31487
- { paths: [path13.dirname(globalLessPath)] },
31573
+ { paths: [path14.dirname(globalLessPath)] },
31488
31574
  (error, output) => {
31489
31575
  if (error) {
31490
- return resolve20(generateErrorMessage(error));
31576
+ return resolve21(generateErrorMessage(error));
31491
31577
  } else {
31492
- return resolve20(output?.css || "");
31578
+ return resolve21(
31579
+ resolveRelativeCssUrls(
31580
+ output?.css || "",
31581
+ path14.dirname(globalLessPath),
31582
+ (filePath) => fs23.exists(filePath)
31583
+ )
31584
+ );
31493
31585
  }
31494
31586
  }
31495
31587
  );
31496
31588
  });
31497
31589
  }
31498
31590
  async function getHeaderIncludes(configPath, fs23) {
31499
- const headerIncludesPath = path13.join(configPath, "./head.html");
31591
+ const headerIncludesPath = path14.join(configPath, "./head.html");
31500
31592
  let fileContent;
31501
31593
  try {
31502
31594
  fileContent = await fs23.readFile(headerIncludesPath);
@@ -31512,7 +31604,7 @@ async function getHeaderIncludes(configPath, fs23) {
31512
31604
  return fileContent;
31513
31605
  }
31514
31606
  async function getConfigs(configPath, fs23) {
31515
- const configScriptPath = path13.join(configPath, "./config.js");
31607
+ const configScriptPath = path14.join(configPath, "./config.js");
31516
31608
  const setupDefaultConfigScript = async () => {
31517
31609
  const defaultKatexConfig = getDefaultKatexConfig();
31518
31610
  const defaultMathjaxConfig = getDefaultMathjaxConfig();
@@ -31551,7 +31643,7 @@ async function getConfigs(configPath, fs23) {
31551
31643
  }
31552
31644
  async function getParserConfig(configPath, fs23) {
31553
31645
  const defaultParserConfig = getDefaultParserConfig();
31554
- const parserConfigPath = path13.join(configPath, "./parser.js");
31646
+ const parserConfigPath = path14.join(configPath, "./parser.js");
31555
31647
  if (await fs23.exists(parserConfigPath)) {
31556
31648
  try {
31557
31649
  const script = await fs23.readFile(parserConfigPath);
@@ -31924,6 +32016,13 @@ var defaultMarkdownItConfig = {
31924
32016
  sourceMap: true
31925
32017
  // Enable source map
31926
32018
  };
32019
+ var OVERSIZED_WALK_WARN_THRESHOLD = 1e4;
32020
+ function isSamePath(a, b) {
32021
+ if (process.platform === "win32") {
32022
+ return a.toLowerCase() === b.toLowerCase();
32023
+ }
32024
+ return a === b;
32025
+ }
31927
32026
  var Notebook = class _Notebook {
31928
32027
  constructor() {
31929
32028
  /**
@@ -31958,10 +32057,19 @@ var Notebook = class _Notebook {
31958
32057
  this.notes = {};
31959
32058
  this.hasLoadedNotes = false;
31960
32059
  /**
31961
- * Whether `skipIndexingIfFilesystemRoot` has already warned for this
32060
+ * Whether `skipIndexingIfRootIsRefused` has already warned for this
31962
32061
  * notebook, so the refusal is logged once per instance.
31963
32062
  */
31964
- this.filesystemRootWarned = false;
32063
+ this.refusedRootWarned = false;
32064
+ /**
32065
+ * Filesystem entries stat'ed by the note-index walk currently running
32066
+ * (or most recently finished). Reset by `refreshNotes` /
32067
+ * `refreshNotesIncremental` — both run under `refreshNotesMutex`, so
32068
+ * concurrent walks cannot interleave counts.
32069
+ */
32070
+ this.walkedEntriesThisRefresh = 0;
32071
+ /** Whether the oversized-walk warning already fired for this notebook. */
32072
+ this.oversizedWalkWarned = false;
31965
32073
  /**
31966
32074
  * The notebook-relative path of the note currently being rendered.
31967
32075
  * Set by MarkdownEngine.parseMD() before calling renderMarkdown().
@@ -32027,7 +32135,7 @@ var Notebook = class _Notebook {
32027
32135
  fs: fs23
32028
32136
  }) {
32029
32137
  const uri = import_vscode_uri.URI.parse(notebookPath);
32030
- if (!path14.isAbsolute(uri.fsPath) || uri.path.startsWith("/./")) {
32138
+ if (!path15.isAbsolute(uri.fsPath) || uri.path.startsWith("/./")) {
32031
32139
  throw new Error(
32032
32140
  `\`notebookPath\`: "${notebookPath}" must be an absolute path`
32033
32141
  );
@@ -32048,7 +32156,7 @@ var Notebook = class _Notebook {
32048
32156
  }
32049
32157
  async initConfig(config) {
32050
32158
  const extraConfig = await loadConfigsInDirectory(
32051
- path14.join(this.notebookPath.fsPath, "./.crossnote"),
32159
+ path15.join(this.notebookPath.fsPath, "./.crossnote"),
32052
32160
  this.fs
32053
32161
  );
32054
32162
  this.config = {
@@ -32206,7 +32314,7 @@ var Notebook = class _Notebook {
32206
32314
  let html;
32207
32315
  if (binaryPath) {
32208
32316
  const args = this.buildMarkdownYoBinaryArgs(renderOpts);
32209
- html = (0, import_child_process11.execFileSync)(binaryPath, args, {
32317
+ html = (0, import_child_process9.execFileSync)(binaryPath, args, {
32210
32318
  input: markdown,
32211
32319
  encoding: "utf8",
32212
32320
  maxBuffer: 256 * 1024 * 1024
@@ -32461,7 +32569,7 @@ var Notebook = class _Notebook {
32461
32569
  const fragmentMarker = rawLink.match(/[#^]/);
32462
32570
  const fileLink = fragmentMarker ? rawLink.slice(0, fragmentMarker.index) : rawLink;
32463
32571
  const fragment = fragmentMarker ? rawLink.slice(fragmentMarker.index) : "";
32464
- const ext = path14.extname(fileLink);
32572
+ const ext = path15.extname(fileLink);
32465
32573
  if (ext && !this.config.markdownFileExtensions.includes(ext)) {
32466
32574
  continue;
32467
32575
  }
@@ -32495,7 +32603,7 @@ var Notebook = class _Notebook {
32495
32603
  if (token.attrs?.length && token.attrs[0][0] === "href") {
32496
32604
  let link = decodeURI(token.attrs[0][1]);
32497
32605
  const text = tokens2[i + 1].content.trim();
32498
- const linkExt = path14.extname(link).toLowerCase();
32606
+ const linkExt = path15.extname(link).toLowerCase();
32499
32607
  if (link.match(/https?:\/\//) || !text.length || !this.config.markdownFileExtensions.includes(linkExt)) {
32500
32608
  continue;
32501
32609
  }
@@ -32583,7 +32691,7 @@ var Notebook = class _Notebook {
32583
32691
  } catch {
32584
32692
  return null;
32585
32693
  }
32586
- if (!stats.isFile() || !this.config.markdownFileExtensions.includes(path14.extname(filePath))) {
32694
+ if (!stats.isFile() || !this.config.markdownFileExtensions.includes(path15.extname(filePath))) {
32587
32695
  return null;
32588
32696
  }
32589
32697
  const sizeLimit = this.config.maxNoteFileSize ?? 0;
@@ -32637,12 +32745,12 @@ var Notebook = class _Notebook {
32637
32745
  if (oldNote) {
32638
32746
  oldMentions = oldNote.mentions;
32639
32747
  }
32640
- const baseExt = path14.extname(absFilePath);
32641
- const title = this.config.markdownFileExtensions.includes(baseExt) ? path14.basename(absFilePath, baseExt) : path14.basename(absFilePath);
32748
+ const baseExt = path15.extname(absFilePath);
32749
+ const title = this.config.markdownFileExtensions.includes(baseExt) ? path15.basename(absFilePath, baseExt) : path15.basename(absFilePath);
32642
32750
  return {
32643
32751
  note: {
32644
32752
  notebookPath: this.notebookPath,
32645
- filePath: path14.relative(this.notebookPath.fsPath, absFilePath),
32753
+ filePath: path15.relative(this.notebookPath.fsPath, absFilePath),
32646
32754
  title,
32647
32755
  config: noteConfig,
32648
32756
  mentions: oldMentions
@@ -32667,23 +32775,36 @@ var Notebook = class _Notebook {
32667
32775
  return this.notes;
32668
32776
  }
32669
32777
  /**
32670
- * True when the notebook is rooted at a filesystem root (`/` on
32671
- * macOS/Linux, `C:\` on Windows) rather than an actual folder —
32672
- * including dot-path spellings of it such as `/.`, which hosts can
32673
- * produce for untitled documents (they resolve to `/`). Indexing
32674
- * such a "notebook" would recursively stat and read files across
32675
- * the whole machine (vscode-markdown-preview-enhanced#2376), so
32676
- * every refresh entry point refuses to walk it. Warns once.
32778
+ * True when the notebook is rooted at a directory the index must
32779
+ * refuse to walk:
32780
+ *
32781
+ * - a filesystem root (`/` on macOS/Linux, `C:\` on Windows),
32782
+ * including dot-path spellings of it such as `/.`, which hosts can
32783
+ * produce for untitled documents (they resolve to `/`);
32784
+ * - the user's home directory — hosts that resolve a loose markdown
32785
+ * file's notebook root to its parent directory produce `~` whenever
32786
+ * the file sits directly in it, and indexing `~` recursively stats
32787
+ * and reads files all over it (on macOS `~/Library` alone spans
32788
+ * Mail, Messages and iCloud data), which is the filesystem scan of
32789
+ * vscode-markdown-preview-enhanced#2376 all over again.
32790
+ *
32791
+ * Every refresh entry point refuses to walk such a root. Warns once.
32677
32792
  */
32678
- skipIndexingIfFilesystemRoot() {
32679
- const resolved = path14.resolve(this.notebookPath.fsPath);
32680
- if (path14.parse(resolved).root !== resolved) {
32793
+ skipIndexingIfRootIsRefused() {
32794
+ const resolved = path15.resolve(this.notebookPath.fsPath);
32795
+ let reason;
32796
+ if (path15.parse(resolved).root === resolved) {
32797
+ reason = "a filesystem root";
32798
+ } else if (isSamePath(resolved, path15.resolve(os.homedir()))) {
32799
+ reason = "the home directory";
32800
+ }
32801
+ if (!reason) {
32681
32802
  return false;
32682
32803
  }
32683
- if (!this.filesystemRootWarned) {
32684
- this.filesystemRootWarned = true;
32804
+ if (!this.refusedRootWarned) {
32805
+ this.refusedRootWarned = true;
32685
32806
  console.warn(
32686
- `Crossnote: notebook root "${this.notebookPath.fsPath}" is a filesystem root; skipping note indexing (wikilinks/backlinks/graph will find nothing). Open a specific folder as the notebook root instead.`
32807
+ `Crossnote: notebook root "${this.notebookPath.fsPath}" is ${reason}; skipping note indexing (wikilinks/backlinks/graph will find nothing). Open a specific folder as the notebook root instead.`
32687
32808
  );
32688
32809
  }
32689
32810
  return true;
@@ -32692,7 +32813,7 @@ var Notebook = class _Notebook {
32692
32813
  async loadGitignoreForDir(dirAbsPath) {
32693
32814
  try {
32694
32815
  const content = await this.fs.readFile(
32695
- path14.join(dirAbsPath, ".gitignore")
32816
+ path15.join(dirAbsPath, ".gitignore")
32696
32817
  );
32697
32818
  return (0, import_ignore.default)().add(content);
32698
32819
  } catch {
@@ -32701,9 +32822,10 @@ var Notebook = class _Notebook {
32701
32822
  }
32702
32823
  async refreshNotes(args) {
32703
32824
  return this.refreshNotesMutex.runExclusive(async () => {
32704
- if (this.skipIndexingIfFilesystemRoot()) {
32825
+ if (this.skipIndexingIfRootIsRefused()) {
32705
32826
  return this.notes;
32706
32827
  }
32828
+ this.walkedEntriesThisRefresh = 0;
32707
32829
  const { refreshRelations = true } = args;
32708
32830
  if (refreshRelations) {
32709
32831
  this.notes = {};
@@ -32737,9 +32859,10 @@ var Notebook = class _Notebook {
32737
32859
  */
32738
32860
  async refreshNotesIncremental(args) {
32739
32861
  return this.refreshNotesMutex.runExclusive(async () => {
32740
- if (this.skipIndexingIfFilesystemRoot()) {
32862
+ if (this.skipIndexingIfRootIsRefused()) {
32741
32863
  return this.notes;
32742
32864
  }
32865
+ this.walkedEntriesThisRefresh = 0;
32743
32866
  const { dir = "./", includeSubdirectories = false } = args;
32744
32867
  const onDisk = /* @__PURE__ */ new Map();
32745
32868
  await this._collectOnDiskMtimes(dir, includeSubdirectories, [], onDisk);
@@ -32808,13 +32931,13 @@ var Notebook = class _Notebook {
32808
32931
  * the duplication when adding new walk-driven features.
32809
32932
  */
32810
32933
  async _walkNotebookDir(dir, includeSubdirectories, gitignoreStack, onFile) {
32811
- const dirAbsPath = path14.resolve(this.notebookPath.fsPath, dir);
32812
- const normalizedDir = path14.relative(this.notebookPath.fsPath, dirAbsPath).replace(/\\/g, "/");
32934
+ const dirAbsPath = path15.resolve(this.notebookPath.fsPath, dir);
32935
+ const normalizedDir = path15.relative(this.notebookPath.fsPath, dirAbsPath).replace(/\\/g, "/");
32813
32936
  const localIg = await this.loadGitignoreForDir(dirAbsPath);
32814
32937
  const currentStack = localIg ? [...gitignoreStack, { ig: localIg, base: normalizedDir || "." }] : gitignoreStack;
32815
32938
  const isIgnoredByGitignore = (relPath) => {
32816
32939
  for (const { ig, base } of currentStack) {
32817
- const relFromBase = base === "." || base === "" ? relPath : path14.posix.relative(base, relPath);
32940
+ const relFromBase = base === "." || base === "" ? relPath : path15.posix.relative(base, relPath);
32818
32941
  if (relFromBase.startsWith("..")) {
32819
32942
  continue;
32820
32943
  }
@@ -32835,8 +32958,8 @@ var Notebook = class _Notebook {
32835
32958
  if (file.match(/^(node_modules|\.git)$/)) {
32836
32959
  continue;
32837
32960
  }
32838
- const absFilePath = path14.resolve(dirAbsPath, file);
32839
- const relFromNotebook = path14.relative(this.notebookPath.fsPath, absFilePath).replace(/\\/g, "/");
32961
+ const absFilePath = path15.resolve(dirAbsPath, file);
32962
+ const relFromNotebook = path15.relative(this.notebookPath.fsPath, absFilePath).replace(/\\/g, "/");
32840
32963
  if (currentStack.length > 0 && isIgnoredByGitignore(relFromNotebook)) {
32841
32964
  continue;
32842
32965
  }
@@ -32846,6 +32969,13 @@ var Notebook = class _Notebook {
32846
32969
  } catch {
32847
32970
  continue;
32848
32971
  }
32972
+ this.walkedEntriesThisRefresh += 1;
32973
+ if (!this.oversizedWalkWarned && this.walkedEntriesThisRefresh > OVERSIZED_WALK_WARN_THRESHOLD) {
32974
+ this.oversizedWalkWarned = true;
32975
+ console.warn(
32976
+ `Crossnote: the note index walk under "${this.notebookPath.fsPath}" has passed ${OVERSIZED_WALK_WARN_THRESHOLD} filesystem entries \u2014 this notebook root is unusually broad, so wikilink/backlink/graph indexing may be slow. If this is unexpected, open a smaller folder as the notebook root.`
32977
+ );
32978
+ }
32849
32979
  if (stats.isSymbolicLink()) {
32850
32980
  continue;
32851
32981
  }
@@ -32883,7 +33013,7 @@ var Notebook = class _Notebook {
32883
33013
  includeSubdirectories,
32884
33014
  gitignoreStack,
32885
33015
  async ({ relPath, stats }) => {
32886
- const ext = path14.extname(relPath);
33016
+ const ext = path15.extname(relPath);
32887
33017
  if (this.config.markdownFileExtensions.includes(ext) && (sizeLimit <= 0 || stats.size <= sizeLimit)) {
32888
33018
  out.set(relPath, Math.floor(stats.mtimeMs));
32889
33019
  }
@@ -33006,10 +33136,10 @@ var Notebook = class _Notebook {
33006
33136
  * @returns
33007
33137
  */
33008
33138
  resolveNoteAbsolutePath(filePath) {
33009
- if (path14.isAbsolute(filePath)) {
33139
+ if (path15.isAbsolute(filePath)) {
33010
33140
  return filePath;
33011
33141
  } else {
33012
- return path14.resolve(this.notebookPath.fsPath, filePath);
33142
+ return path15.resolve(this.notebookPath.fsPath, filePath);
33013
33143
  }
33014
33144
  }
33015
33145
  /**
@@ -33018,8 +33148,8 @@ var Notebook = class _Notebook {
33018
33148
  * @returns
33019
33149
  */
33020
33150
  resolveNoteRelativePath(filePath) {
33021
- if (path14.isAbsolute(filePath)) {
33022
- return path14.relative(this.notebookPath.fsPath, filePath);
33151
+ if (path15.isAbsolute(filePath)) {
33152
+ return path15.relative(this.notebookPath.fsPath, filePath);
33023
33153
  } else {
33024
33154
  return filePath;
33025
33155
  }
@@ -33080,7 +33210,7 @@ var Notebook = class _Notebook {
33080
33210
  blockRef = link.slice(blockRefIndex);
33081
33211
  link = link.slice(0, blockRefIndex);
33082
33212
  }
33083
- const parsed = path14.parse(link);
33213
+ const parsed = path15.parse(link);
33084
33214
  let fileName = parsed.name;
33085
33215
  let fileExtension = parsed.ext;
33086
33216
  if (fileExtension.match(/^\.\d+$/)) {
@@ -33093,7 +33223,7 @@ var Notebook = class _Notebook {
33093
33223
  if (!fileExtension) {
33094
33224
  fileExtension = this.config.wikiLinkTargetFileExtension;
33095
33225
  }
33096
- link = path14.join(parsed.dir, fileName + fileExtension);
33226
+ link = path15.join(parsed.dir, fileName + fileExtension);
33097
33227
  if (hash2) {
33098
33228
  link += hash2;
33099
33229
  }
@@ -33114,20 +33244,20 @@ var Notebook = class _Notebook {
33114
33244
  * @returns notebook-root-relative file path
33115
33245
  */
33116
33246
  resolveWikilink(link, currentNoteFilePath) {
33117
- if (!path14.extname(link)) {
33247
+ if (!path15.extname(link)) {
33118
33248
  link = link + this.config.wikiLinkTargetFileExtension;
33119
33249
  }
33120
33250
  if (link.startsWith("/")) {
33121
- return path14.relative(
33251
+ return path15.relative(
33122
33252
  this.notebookPath.fsPath,
33123
- path14.join(this.notebookPath.fsPath, "." + link)
33253
+ path15.join(this.notebookPath.fsPath, "." + link)
33124
33254
  );
33125
33255
  }
33126
33256
  const mode = this.config.wikiLinkResolution;
33127
33257
  if (mode === "absolute") {
33128
- return path14.relative(
33258
+ return path15.relative(
33129
33259
  this.notebookPath.fsPath,
33130
- path14.join(this.notebookPath.fsPath, link)
33260
+ path15.join(this.notebookPath.fsPath, link)
33131
33261
  );
33132
33262
  }
33133
33263
  if (mode === "shortest") {
@@ -33148,7 +33278,7 @@ var Notebook = class _Notebook {
33148
33278
  const shortest = candidates.filter(
33149
33279
  (c) => normalize(c).split("/").length === bestDepth
33150
33280
  );
33151
- const normalizedDir = normalize(path14.dirname(currentNoteFilePath));
33281
+ const normalizedDir = normalize(path15.dirname(currentNoteFilePath));
33152
33282
  const inDir = shortest.find((c) => {
33153
33283
  const nc = normalize(c);
33154
33284
  if (normalizedDir === ".") {
@@ -33159,8 +33289,8 @@ var Notebook = class _Notebook {
33159
33289
  return inDir || shortest[0];
33160
33290
  }
33161
33291
  }
33162
- const noteDir = currentNoteFilePath ? path14.dirname(path14.join(this.notebookPath.fsPath, currentNoteFilePath)) : this.notebookPath.fsPath;
33163
- return path14.relative(this.notebookPath.fsPath, path14.join(noteDir, link));
33292
+ const noteDir = currentNoteFilePath ? path15.dirname(path15.join(this.notebookPath.fsPath, currentNoteFilePath)) : this.notebookPath.fsPath;
33293
+ return path15.relative(this.notebookPath.fsPath, path15.join(noteDir, link));
33164
33294
  }
33165
33295
  };
33166
33296
 
@@ -33487,16 +33617,16 @@ async function enhance2($, notebook, resolveFilePath) {
33487
33617
  return;
33488
33618
  }
33489
33619
  asyncFunctions.push(
33490
- new Promise((resolve20) => {
33620
+ new Promise((resolve21) => {
33491
33621
  notebook.fs.readFile(src, "base64").then((base64) => {
33492
33622
  $img.attr(
33493
33623
  "src",
33494
33624
  `data:image/${imageType};charset=utf-8;base64,${base64}`
33495
33625
  );
33496
- return resolve20(base64);
33626
+ return resolve21(base64);
33497
33627
  }).catch((error) => {
33498
33628
  console.error(error);
33499
- return resolve20(null);
33629
+ return resolve21(null);
33500
33630
  });
33501
33631
  })
33502
33632
  );
@@ -33521,15 +33651,15 @@ async function enhance3($, notebook, resolveFilePath) {
33521
33651
  return;
33522
33652
  }
33523
33653
  asyncFunctions.push(
33524
- new Promise((resolve20) => {
33654
+ new Promise((resolve21) => {
33525
33655
  notebook.fs.readFile(src, "base64").then((base64) => {
33526
33656
  $img.attr(
33527
33657
  "src",
33528
33658
  `data:image/svg+xml;charset=utf-8;base64,${base64}`
33529
33659
  );
33530
- return resolve20(base64);
33660
+ return resolve21(base64);
33531
33661
  }).catch(() => {
33532
- return resolve20(null);
33662
+ return resolve21(null);
33533
33663
  });
33534
33664
  })
33535
33665
  );
@@ -33540,7 +33670,7 @@ async function enhance3($, notebook, resolveFilePath) {
33540
33670
 
33541
33671
  // src/render-enhancers/embedded-wikilinks.ts
33542
33672
  var import_html_escaper6 = require("html-escaper");
33543
- var path15 = __toESM(require("path"));
33673
+ var path16 = __toESM(require("path"));
33544
33674
  var cheerio2 = __toESM(require("cheerio"));
33545
33675
  var MAX_EMBED_DEPTH = 3;
33546
33676
  var BINARY_EMBED_EXTENSIONS = /* @__PURE__ */ new Set([
@@ -33632,9 +33762,9 @@ async function resolveEmbed(_$, notebook, fileDirectoryPath, $placeholder, embed
33632
33762
  }
33633
33763
  let resolvedPath;
33634
33764
  if (embedPath.startsWith("/")) {
33635
- resolvedPath = path15.resolve(notebook.notebookPath.fsPath, "." + embedPath);
33765
+ resolvedPath = path16.resolve(notebook.notebookPath.fsPath, "." + embedPath);
33636
33766
  } else {
33637
- resolvedPath = path15.resolve(fileDirectoryPath, embedPath);
33767
+ resolvedPath = path16.resolve(fileDirectoryPath, embedPath);
33638
33768
  }
33639
33769
  let hash2 = "";
33640
33770
  const hashIndex = resolvedPath.lastIndexOf("#");
@@ -33642,7 +33772,7 @@ async function resolveEmbed(_$, notebook, fileDirectoryPath, $placeholder, embed
33642
33772
  hash2 = resolvedPath.substring(hashIndex);
33643
33773
  resolvedPath = resolvedPath.substring(0, hashIndex);
33644
33774
  }
33645
- const extname14 = path15.extname(resolvedPath).toLowerCase();
33775
+ const extname14 = path16.extname(resolvedPath).toLowerCase();
33646
33776
  if (IMAGE_EMBED_RE.test(extname14)) {
33647
33777
  $placeholder.replaceWith(
33648
33778
  `<div class="wikilink-embed-content"><img src="${(0, import_html_escaper6.escape)(
@@ -33719,7 +33849,7 @@ async function resolveEmbed(_$, notebook, fileDirectoryPath, $placeholder, embed
33719
33849
  return;
33720
33850
  }
33721
33851
  }
33722
- const embedFileDir = path15.dirname(resolvedPath);
33852
+ const embedFileDir = path16.dirname(resolvedPath);
33723
33853
  const engine = notebook.getNoteMarkdownEngine(resolvedPath);
33724
33854
  const { html } = await engine.parseMD(markdownContent, {
33725
33855
  useRelativeFilePath: false,
@@ -34032,23 +34162,23 @@ async function renderBitfield(code, options) {
34032
34162
  }
34033
34163
 
34034
34164
  // src/renderers/d2.ts
34035
- var import_child_process12 = require("child_process");
34165
+ var import_child_process10 = require("child_process");
34036
34166
  var crypto = __toESM(require("crypto"));
34037
34167
  var import_html_escaper9 = require("html-escaper");
34038
34168
  var fs12 = __toESM(require("fs"));
34039
- var os = __toESM(require("os"));
34040
- var path16 = __toESM(require("path"));
34169
+ var os2 = __toESM(require("os"));
34170
+ var path17 = __toESM(require("path"));
34041
34171
  var D2_NOT_FOUND = /* @__PURE__ */ Symbol("D2_NOT_FOUND");
34042
34172
  async function writeInputFile(fileDirectoryPath, name, code) {
34043
34173
  if (fileDirectoryPath) {
34044
- const preferred = path16.join(fileDirectoryPath, name);
34174
+ const preferred = path17.join(fileDirectoryPath, name);
34045
34175
  try {
34046
34176
  await fs12.promises.writeFile(preferred, code, "utf8");
34047
34177
  return preferred;
34048
34178
  } catch {
34049
34179
  }
34050
34180
  }
34051
- const fallback = path16.join(os.tmpdir(), name);
34181
+ const fallback = path17.join(os2.tmpdir(), name);
34052
34182
  await fs12.promises.writeFile(fallback, code, "utf8");
34053
34183
  return fallback;
34054
34184
  }
@@ -34056,12 +34186,12 @@ async function renderD2(code, opts, fileDirectoryPath) {
34056
34186
  if (typeof crypto?.randomBytes !== "function") return D2_NOT_FOUND;
34057
34187
  const id = crypto.randomBytes(8).toString("hex");
34058
34188
  const inputName = `.crossnote-d2-${id}.d2`;
34059
- const tmpOut = path16.join(os.tmpdir(), `d2-${id}.svg`);
34189
+ const tmpOut = path17.join(os2.tmpdir(), `d2-${id}.svg`);
34060
34190
  let tmpIn;
34061
34191
  try {
34062
34192
  tmpIn = await writeInputFile(fileDirectoryPath, inputName, code);
34063
34193
  const inputPath = tmpIn;
34064
- await new Promise((resolve20, reject) => {
34194
+ await new Promise((resolve21, reject) => {
34065
34195
  const args = [
34066
34196
  `--theme=${opts.d2Theme}`,
34067
34197
  `--layout=${opts.d2Layout}`,
@@ -34069,7 +34199,7 @@ async function renderD2(code, opts, fileDirectoryPath) {
34069
34199
  inputPath,
34070
34200
  tmpOut
34071
34201
  ];
34072
- (0, import_child_process12.execFile)(
34202
+ (0, import_child_process10.execFile)(
34073
34203
  opts.d2Path,
34074
34204
  args,
34075
34205
  { timeout: 3e4 },
@@ -34079,7 +34209,7 @@ async function renderD2(code, opts, fileDirectoryPath) {
34079
34209
  wrapped.code = err.code;
34080
34210
  reject(wrapped);
34081
34211
  } else {
34082
- resolve20();
34212
+ resolve21();
34083
34213
  }
34084
34214
  }
34085
34215
  );
@@ -34715,9 +34845,7 @@ async function enhance9($, options, resolveFilePath) {
34715
34845
 
34716
34846
  // src/markdown-engine/inline-offline-assets.ts
34717
34847
  var fs13 = __toESM(require("fs"));
34718
- var path17 = __toESM(require("path"));
34719
- var ABSOLUTE_URL = /^(data:|https?:|file:|\/\/)/i;
34720
- var CSS_URL = /url\(\s*(['"]?)([^'")]+)\1\s*\)(\s*format\([^)]+\))?/gi;
34848
+ var path18 = __toESM(require("path"));
34721
34849
  var FALLBACK_FONT_EXTS = /* @__PURE__ */ new Set([".woff", ".ttf", ".eot", ".otf"]);
34722
34850
  var MIME_BY_EXT = {
34723
34851
  ".woff2": "font/woff2",
@@ -34741,7 +34869,7 @@ ${escaped}
34741
34869
  }
34742
34870
  async function readOfflineCss(absPath) {
34743
34871
  const css = await fs13.promises.readFile(absPath, "utf8");
34744
- const rewritten = rewriteCssUrls(css, path17.dirname(absPath));
34872
+ const rewritten = rewriteCssUrls(css, path18.dirname(absPath));
34745
34873
  const escaped = rewritten.replace(/<\/style/gi, "<\\/style");
34746
34874
  return `<style>
34747
34875
  ${escaped}
@@ -34755,11 +34883,11 @@ function rewriteCssUrls(css, cssDir) {
34755
34883
  if (ABSOLUTE_URL.test(url)) {
34756
34884
  return whole;
34757
34885
  }
34758
- const resolved = path17.resolve(cssDir, url.replace(/[?#].*$/, ""));
34759
- if (resolved !== cssDir && !resolved.startsWith(cssDir + path17.sep)) {
34886
+ const resolved = path18.resolve(cssDir, url.replace(/[?#].*$/, ""));
34887
+ if (resolved !== cssDir && !resolved.startsWith(cssDir + path18.sep)) {
34760
34888
  return "";
34761
34889
  }
34762
- const ext = path17.extname(resolved).toLowerCase();
34890
+ const ext = path18.extname(resolved).toLowerCase();
34763
34891
  if (FALLBACK_FONT_EXTS.has(ext)) {
34764
34892
  const woff2 = resolved.slice(0, -ext.length) + ".woff2";
34765
34893
  if (fs13.existsSync(woff2)) {
@@ -34821,12 +34949,108 @@ function buildMathJaxConfigScript(mathJaxConfig) {
34821
34949
 
34822
34950
  // src/renderers/wavedrom-source.ts
34823
34951
  var import_json52 = __toESM(require("json5"));
34952
+
34953
+ // src/lib/dangerous-urls.ts
34954
+ var DANGEROUS_URL_PATTERN = /^\s*(javascript|vbscript)\s*:|^\s*data\s*:\s*text\/html/i;
34955
+ var URL_ATTRIBUTES = [
34956
+ "href",
34957
+ "src",
34958
+ "action",
34959
+ "formaction",
34960
+ "xlink:href"
34961
+ ];
34962
+ function isDangerousUrl(value) {
34963
+ return DANGEROUS_URL_PATTERN.test(value);
34964
+ }
34965
+
34966
+ // src/renderers/wavedrom-source.ts
34967
+ var DANGEROUS_SVG_TAGS = /* @__PURE__ */ new Set([
34968
+ "script",
34969
+ "handler",
34970
+ // SVG Tiny 1.2 event scripting
34971
+ "listener",
34972
+ // SVG Tiny 1.2 event wiring
34973
+ "foreignobject",
34974
+ // switches to the HTML namespace inside SVG
34975
+ "iframe",
34976
+ "embed",
34977
+ "object",
34978
+ "applet",
34979
+ // SMIL animation elements: <animate attributeName="href" to="javascript:...">
34980
+ "animate",
34981
+ "animatemotion",
34982
+ "animatetransform",
34983
+ "set"
34984
+ ]);
34985
+ var TAG_NAME_PATTERN = /^[a-zA-Z][a-zA-Z0-9:._-]*$/;
34986
+ function isPlainObject(value) {
34987
+ return typeof value === "object" && value !== null && !Array.isArray(value);
34988
+ }
34989
+ function escapeXml(s) {
34990
+ return /[&<>"]/.test(s) ? s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;") : s;
34991
+ }
34992
+ function escapeAttrBag(attrs) {
34993
+ const out = {};
34994
+ for (const [key, val] of Object.entries(attrs)) {
34995
+ const escapedKey = /[&<>"]/.test(key) ? escapeXml(key) : key;
34996
+ out[escapedKey] = Array.isArray(val) ? val.map((v) => typeof v === "string" ? escapeXml(v) : v) : typeof val === "string" ? escapeXml(val) : val;
34997
+ }
34998
+ return out;
34999
+ }
35000
+ function sanitizeWavedromData(value, parentKey) {
35001
+ if (Array.isArray(value)) {
35002
+ const rawTag = value[0];
35003
+ const tag = typeof rawTag === "string" ? rawTag.toLowerCase() : null;
35004
+ if (tag !== null && DANGEROUS_SVG_TAGS.has(tag)) {
35005
+ if (isPlainObject(value[1]) || tag === "script" || tag === "handler") {
35006
+ return "";
35007
+ }
35008
+ }
35009
+ const bag = value[1];
35010
+ const isElement = tag !== null && (isPlainObject(bag) || TAG_NAME_PATTERN.test(tag));
35011
+ if (!isElement || parentKey === "data") {
35012
+ return value.map(
35013
+ (v) => Array.isArray(v) || isPlainObject(v) ? sanitizeWavedromData(v) : v
35014
+ );
35015
+ }
35016
+ const out = [rawTag];
35017
+ let i = 1;
35018
+ if (isPlainObject(bag)) {
35019
+ sanitizeWavedromData(bag);
35020
+ out.push(escapeAttrBag(bag));
35021
+ i = 2;
35022
+ }
35023
+ for (; i < value.length; i++) {
35024
+ const child = value[i];
35025
+ out.push(
35026
+ typeof child === "string" ? escapeXml(child) : sanitizeWavedromData(child)
35027
+ );
35028
+ }
35029
+ return out;
35030
+ }
35031
+ if (isPlainObject(value)) {
35032
+ for (const key of Object.keys(value)) {
35033
+ if (/^on/i.test(key)) {
35034
+ delete value[key];
35035
+ continue;
35036
+ }
35037
+ const attrValue = value[key];
35038
+ if (URL_ATTRIBUTES.includes(key.toLowerCase()) && typeof attrValue === "string" && isDangerousUrl(attrValue)) {
35039
+ delete value[key];
35040
+ continue;
35041
+ }
35042
+ value[key] = sanitizeWavedromData(attrValue, key);
35043
+ }
35044
+ }
35045
+ return value;
35046
+ }
34824
35047
  function normalizeWavedromSource(raw) {
34825
35048
  try {
34826
35049
  const data = import_json52.default.parse(raw);
34827
35050
  if (typeof data !== "object" || data === null || Array.isArray(data)) {
34828
35051
  return null;
34829
35052
  }
35053
+ sanitizeWavedromData(data);
34830
35054
  const json = JSON.stringify(data, (_key, value) => {
34831
35055
  if (typeof value === "number" && !Number.isFinite(value)) {
34832
35056
  throw new SyntaxError("WaveDrom data contains a non-finite number");
@@ -34840,10 +35064,8 @@ function normalizeWavedromSource(raw) {
34840
35064
  }
34841
35065
 
34842
35066
  // src/markdown-engine/sanitize.ts
34843
- var DANGEROUS_URL_PATTERN = /^\s*(javascript|vbscript)\s*:|^\s*data\s*:\s*text\/html/i;
34844
35067
  var DANGEROUS_TAGS = ["object", "embed", "applet"];
34845
35068
  var SAFE_SCRIPT_TYPES = /* @__PURE__ */ new Set(["wavedrom", "text/tikz"]);
34846
- var URL_ATTRIBUTES = ["href", "src", "action", "formaction", "xlink:href"];
34847
35069
  function sanitizeRenderedHTML($) {
34848
35070
  $(DANGEROUS_TAGS.join(", ")).remove();
34849
35071
  $("script").each((_, el) => {
@@ -34874,7 +35096,7 @@ function sanitizeRenderedHTML($) {
34874
35096
  delete attribs[attr];
34875
35097
  continue;
34876
35098
  }
34877
- if (URL_ATTRIBUTES.includes(attr.toLowerCase()) && DANGEROUS_URL_PATTERN.test(attribs[attr])) {
35099
+ if (URL_ATTRIBUTES.includes(attr.toLowerCase()) && isDangerousUrl(attribs[attr])) {
34878
35100
  delete attribs[attr];
34879
35101
  }
34880
35102
  }
@@ -34942,11 +35164,11 @@ function isPathInsideDirectory(parentDirectoryPath, filePath) {
34942
35164
  return p;
34943
35165
  }
34944
35166
  };
34945
- const relative11 = path18.relative(
35167
+ const relative11 = path19.relative(
34946
35168
  realpath(parentDirectoryPath),
34947
35169
  realpath(filePath)
34948
35170
  );
34949
- return relative11 !== "" && !relative11.startsWith("..") && !path18.isAbsolute(relative11);
35171
+ return relative11 !== "" && !relative11.startsWith("..") && !path19.isAbsolute(relative11);
34950
35172
  }
34951
35173
  function isExistingFile(filePath) {
34952
35174
  try {
@@ -34978,7 +35200,7 @@ var MarkdownEngine = class _MarkdownEngine {
34978
35200
  this.isPreviewInPresentationMode = false;
34979
35201
  this.filePath = filePath;
34980
35202
  this.notebook = notebook;
34981
- this.fileDirectoryPath = path18.dirname(this.filePath);
35203
+ this.fileDirectoryPath = path19.dirname(this.filePath);
34982
35204
  this.projectDirectoryPath = this.notebook.notebookPath || this.fileDirectoryPath;
34983
35205
  this.fs = this.notebook.fs;
34984
35206
  this.headings = [];
@@ -35004,7 +35226,7 @@ var MarkdownEngine = class _MarkdownEngine {
35004
35226
  let scripts = "";
35005
35227
  scripts += `<script>var exports = undefined</script>`;
35006
35228
  scripts += `<script type="text/javascript" src="${addFileProtocol(
35007
- path18.resolve(
35229
+ path19.resolve(
35008
35230
  getCrossnoteBuildDirectory(),
35009
35231
  `./dependencies/mermaid/mermaid.min.js`
35010
35232
  ),
@@ -35015,21 +35237,21 @@ var MarkdownEngine = class _MarkdownEngine {
35015
35237
  await mermaid.registerExternalDiagrams([zenuml]);
35016
35238
  </script>`;
35017
35239
  scripts += `<script type="text/javascript" src="${addFileProtocol(
35018
- path18.resolve(
35240
+ path19.resolve(
35019
35241
  getCrossnoteBuildDirectory(),
35020
35242
  "./dependencies/wavedrom/skins/default.js"
35021
35243
  ),
35022
35244
  vscodePreviewPanel
35023
35245
  )}" charset="UTF-8"></script>`;
35024
35246
  scripts += `<script type="text/javascript" src="${addFileProtocol(
35025
- path18.resolve(
35247
+ path19.resolve(
35026
35248
  getCrossnoteBuildDirectory(),
35027
35249
  "./dependencies/wavedrom/skins/narrow.js"
35028
35250
  ),
35029
35251
  vscodePreviewPanel
35030
35252
  )}" charset="UTF-8"></script>`;
35031
35253
  scripts += `<script type="text/javascript" src="${addFileProtocol(
35032
- path18.resolve(
35254
+ path19.resolve(
35033
35255
  getCrossnoteBuildDirectory(),
35034
35256
  "./dependencies/wavedrom/wavedrom.min.js"
35035
35257
  ),
@@ -35062,7 +35284,7 @@ var MarkdownEngine = class _MarkdownEngine {
35062
35284
  let presentationInitScript = "";
35063
35285
  if (isForPresentation) {
35064
35286
  scripts += `<script src='${addFileProtocol(
35065
- path18.resolve(
35287
+ path19.resolve(
35066
35288
  getCrossnoteBuildDirectory(),
35067
35289
  "./dependencies/reveal/js/reveal.js"
35068
35290
  ),
@@ -35126,7 +35348,7 @@ if (typeof(window['Reveal']) !== 'undefined') {
35126
35348
  }
35127
35349
  dependentLibraryMaterials.forEach(({ key }) => {
35128
35350
  scripts += `<script src="${addFileProtocol(
35129
- path18.resolve(
35351
+ path19.resolve(
35130
35352
  getCrossnoteBuildDirectory(),
35131
35353
  `./dependencies/${key}/${key}.min.js`
35132
35354
  ),
@@ -35303,7 +35525,7 @@ window["initRevealPresentation"] = async function() {
35303
35525
  let styles = "";
35304
35526
  if (this.notebook.config.mathRenderingOption === "KaTeX" && this.notebook.config.markdownParser !== "pandoc") {
35305
35527
  styles += `<link rel="stylesheet" href="${addFileProtocol(
35306
- path18.resolve(
35528
+ path19.resolve(
35307
35529
  getCrossnoteBuildDirectory(),
35308
35530
  "./dependencies/katex/katex.min.css"
35309
35531
  ),
@@ -35311,7 +35533,7 @@ window["initRevealPresentation"] = async function() {
35311
35533
  )}">`;
35312
35534
  }
35313
35535
  styles += `<link rel="stylesheet" href="${addFileProtocol(
35314
- path18.resolve(
35536
+ path19.resolve(
35315
35537
  getCrossnoteBuildDirectory(),
35316
35538
  `./dependencies/font-awesome/css/all.min.css`
35317
35539
  ),
@@ -35319,7 +35541,7 @@ window["initRevealPresentation"] = async function() {
35319
35541
  )}">`;
35320
35542
  if (!isPresentationMode) {
35321
35543
  styles += `<link rel="stylesheet" href="${addFileProtocol(
35322
- path18.resolve(
35544
+ path19.resolve(
35323
35545
  getCrossnoteBuildDirectory(),
35324
35546
  `./styles/preview_theme/${this.notebook.config.previewTheme}`
35325
35547
  ),
@@ -35327,14 +35549,14 @@ window["initRevealPresentation"] = async function() {
35327
35549
  )}">`;
35328
35550
  } else {
35329
35551
  styles += `<link rel="stylesheet" href="${addFileProtocol(
35330
- path18.resolve(
35552
+ path19.resolve(
35331
35553
  getCrossnoteBuildDirectory(),
35332
35554
  "./dependencies/reveal/css/reveal.css"
35333
35555
  ),
35334
35556
  vscodePreviewPanel
35335
35557
  )}" >`;
35336
35558
  styles += `<link rel="stylesheet" href="${addFileProtocol(
35337
- path18.resolve(
35559
+ path19.resolve(
35338
35560
  getCrossnoteBuildDirectory(),
35339
35561
  `./dependencies/reveal/css/theme/${(() => {
35340
35562
  const presObj = typeof yamlConfig["presentation"] === "object" && yamlConfig["presentation"] !== null && !Array.isArray(yamlConfig["presentation"]) ? yamlConfig["presentation"] : null;
@@ -35345,7 +35567,7 @@ window["initRevealPresentation"] = async function() {
35345
35567
  )}" >`;
35346
35568
  }
35347
35569
  styles += `<link rel="stylesheet" href="${addFileProtocol(
35348
- path18.resolve(
35570
+ path19.resolve(
35349
35571
  getCrossnoteBuildDirectory(),
35350
35572
  `./styles/prism_theme/${this.getPrismTheme(
35351
35573
  isPresentationMode,
@@ -35355,27 +35577,30 @@ window["initRevealPresentation"] = async function() {
35355
35577
  vscodePreviewPanel
35356
35578
  )}">`;
35357
35579
  styles += `<link rel="stylesheet" media="screen" href="${addFileProtocol(
35358
- path18.resolve(
35580
+ path19.resolve(
35359
35581
  getCrossnoteBuildDirectory(),
35360
35582
  "./styles/style-template.css"
35361
35583
  ),
35362
35584
  vscodePreviewPanel
35363
35585
  )}">`;
35364
35586
  styles += `<link rel="stylesheet" media="screen" href="${addFileProtocol(
35365
- path18.resolve(
35587
+ path19.resolve(
35366
35588
  getCrossnoteBuildDirectory(),
35367
35589
  "./styles/markdown-it-admonition.css"
35368
35590
  ),
35369
35591
  vscodePreviewPanel
35370
35592
  )}">`;
35371
35593
  styles += `<link rel="stylesheet" media="screen" href="${addFileProtocol(
35372
- path18.resolve(
35594
+ path19.resolve(
35373
35595
  getCrossnoteBuildDirectory(),
35374
35596
  "./styles/markdown-it-callout.css"
35375
35597
  ),
35376
35598
  vscodePreviewPanel
35377
35599
  )}">`;
35378
- styles += `<style>${this.notebook.config.globalCss}</style>`;
35600
+ styles += `<style>${this.resolvePathsInStyles(
35601
+ this.notebook.config.globalCss,
35602
+ vscodePreviewPanel
35603
+ )}</style>`;
35379
35604
  return styles;
35380
35605
  }
35381
35606
  /**
@@ -35389,7 +35614,7 @@ window["initRevealPresentation"] = async function() {
35389
35614
  if (!this.notebook.previewScriptsEnabled || sourcePath.startsWith("//") || /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(sourcePath)) {
35390
35615
  return;
35391
35616
  }
35392
- const resolvedPath = sourcePath[0] === "/" ? path18.resolve(this.projectDirectoryPath.fsPath, "." + sourcePath) : path18.resolve(this.fileDirectoryPath, sourcePath);
35617
+ const resolvedPath = sourcePath[0] === "/" ? path19.resolve(this.projectDirectoryPath.fsPath, "." + sourcePath) : path19.resolve(this.fileDirectoryPath, sourcePath);
35393
35618
  if (!this.isPathInsideProjectDirectory(resolvedPath)) {
35394
35619
  return;
35395
35620
  }
@@ -35402,13 +35627,13 @@ window["initRevealPresentation"] = async function() {
35402
35627
  let absoluteFilePath = sourcePath;
35403
35628
  if (sourcePath[0] === "/") {
35404
35629
  absoluteFilePath = addFileProtocol(
35405
- path18.resolve(this.projectDirectoryPath.fsPath, "." + sourcePath),
35630
+ path19.resolve(this.projectDirectoryPath.fsPath, "." + sourcePath),
35406
35631
  vscodePreviewPanel
35407
35632
  );
35408
35633
  } else if (sourcePath.match(/^file:\/\//) || sourcePath.match(/^https?:\/\//)) {
35409
35634
  } else {
35410
35635
  absoluteFilePath = addFileProtocol(
35411
- path18.resolve(this.fileDirectoryPath, sourcePath),
35636
+ path19.resolve(this.fileDirectoryPath, sourcePath),
35412
35637
  vscodePreviewPanel
35413
35638
  );
35414
35639
  }
@@ -35447,14 +35672,14 @@ window["initRevealPresentation"] = async function() {
35447
35672
  let webviewCss = "";
35448
35673
  if (!webviewScript) {
35449
35674
  webviewScript = addFileProtocol(
35450
- path18.resolve(
35675
+ path19.resolve(
35451
35676
  getCrossnoteBuildDirectory(),
35452
35677
  "./webview/preview.js"
35453
35678
  ),
35454
35679
  vscodePreviewPanel
35455
35680
  );
35456
35681
  webviewCss = addFileProtocol(
35457
- path18.resolve(
35682
+ path19.resolve(
35458
35683
  getCrossnoteBuildDirectory(),
35459
35684
  "./webview/preview.css"
35460
35685
  ),
@@ -35505,7 +35730,7 @@ window["initRevealPresentation"] = async function() {
35505
35730
  </style>
35506
35731
  ` : ""}
35507
35732
  <link rel="stylesheet" href="${addFileProtocol(
35508
- path18.resolve(
35733
+ path19.resolve(
35509
35734
  getCrossnoteBuildDirectory(),
35510
35735
  "./styles/preview.css"
35511
35736
  ),
@@ -35547,14 +35772,14 @@ window["initRevealPresentation"] = async function() {
35547
35772
  contentSecurityPolicy = ""
35548
35773
  }) {
35549
35774
  const webviewScript = addFileProtocol(
35550
- path18.resolve(
35775
+ path19.resolve(
35551
35776
  getCrossnoteBuildDirectory(),
35552
35777
  "./webview/graph-view.js"
35553
35778
  ),
35554
35779
  vscodePreviewPanel
35555
35780
  );
35556
35781
  const webviewCss = addFileProtocol(
35557
- path18.resolve(
35782
+ path19.resolve(
35558
35783
  getCrossnoteBuildDirectory(),
35559
35784
  "./webview/graph-view.css"
35560
35785
  ),
@@ -35585,7 +35810,7 @@ window["initRevealPresentation"] = async function() {
35585
35810
  async generateHTMLTemplateForExport(html, yamlConfig = {}, options) {
35586
35811
  const fileURL = (p) => toFileURL(p, { useWSL: !!options.isForBrowser });
35587
35812
  const embedAssets = !!(options.offline && options.embedOfflineAssets);
35588
- const depPath = (...parts) => path18.resolve(getCrossnoteBuildDirectory(), ...parts);
35813
+ const depPath = (...parts) => path19.resolve(getCrossnoteBuildDirectory(), ...parts);
35589
35814
  const offlineStyle = async (rel) => {
35590
35815
  const abs = depPath(rel);
35591
35816
  if (embedAssets) {
@@ -35665,7 +35890,7 @@ window["initRevealPresentation"] = async function() {
35665
35890
  "./dependencies/mermaid/mermaid.min.js"
35666
35891
  );
35667
35892
  } else {
35668
- mermaidScript = `<script src="https://${this.notebook.config.jsdelivrCdnHost}/npm/mermaid@11.17.2/dist/mermaid.min.js"></script>`;
35893
+ mermaidScript = `<script src="https://${this.notebook.config.jsdelivrCdnHost}/npm/mermaid@12.0.0/dist/mermaid.min.js"></script>`;
35669
35894
  }
35670
35895
  mermaidInitScript += `<script type="module">
35671
35896
  // TODO: If ZenUML gets integrated into mermaid in the future,
@@ -35778,7 +36003,7 @@ if (typeof(window['Reveal']) !== 'undefined') {
35778
36003
  if (presentationConfig["enableSpeakerNotes"]) {
35779
36004
  if (options.offline) {
35780
36005
  dependencies.push({
35781
- src: path18.resolve(
36006
+ src: path19.resolve(
35782
36007
  getCrossnoteBuildDirectory(),
35783
36008
  "./dependencies/reveal/plugin/notes/notes.js"
35784
36009
  ),
@@ -35792,13 +36017,13 @@ if (typeof(window['Reveal']) !== 'undefined') {
35792
36017
  presentationStyle = `
35793
36018
  <style>
35794
36019
  ${await this.fs.readFile(
35795
- path18.resolve(
36020
+ path19.resolve(
35796
36021
  getCrossnoteBuildDirectory(),
35797
36022
  "./dependencies/reveal/css/reveal.css"
35798
36023
  )
35799
36024
  )}
35800
36025
  ${options.isForPrint ? await this.fs.readFile(
35801
- path18.resolve(
36026
+ path19.resolve(
35802
36027
  getCrossnoteBuildDirectory(),
35803
36028
  "./dependencies/reveal/css/print/pdf.css"
35804
36029
  )
@@ -35818,8 +36043,8 @@ if (typeof(window['Reveal']) !== 'undefined') {
35818
36043
  if (options.isForPrince) {
35819
36044
  princeClass = "prince";
35820
36045
  }
35821
- let title = path18.basename(this.filePath);
35822
- title = title.slice(0, title.length - path18.extname(title).length);
36046
+ let title = path19.basename(this.filePath);
36047
+ title = title.slice(0, title.length - path19.extname(title).length);
35823
36048
  if (yamlConfig["title"]) {
35824
36049
  title = yamlConfig["title"];
35825
36050
  }
@@ -35832,7 +36057,7 @@ if (typeof(window['Reveal']) !== 'undefined') {
35832
36057
  try {
35833
36058
  if (forceLightTheme && !yamlConfig["isPresentationMode"]) {
35834
36059
  styleCSS += await this.fs.readFile(
35835
- path18.resolve(
36060
+ path19.resolve(
35836
36061
  getCrossnoteBuildDirectory(),
35837
36062
  `./styles/prism_theme/github.css`
35838
36063
  )
@@ -35852,14 +36077,14 @@ if (typeof(window['Reveal']) !== 'undefined') {
35852
36077
  if (darkPrismTheme) {
35853
36078
  colorSchemeMeta = '<meta name="color-scheme" content="light dark">';
35854
36079
  styleCSS += await this.fs.readFile(
35855
- path18.resolve(
36080
+ path19.resolve(
35856
36081
  getCrossnoteBuildDirectory(),
35857
36082
  `./styles/prism_theme/${prismTheme}`
35858
36083
  )
35859
36084
  );
35860
36085
  styleCSS += `@media (prefers-color-scheme: dark) {
35861
36086
  ${await this.fs.readFile(
35862
- path18.resolve(
36087
+ path19.resolve(
35863
36088
  getCrossnoteBuildDirectory(),
35864
36089
  `./styles/prism_theme/${darkPrismTheme}`
35865
36090
  )
@@ -35868,7 +36093,7 @@ ${await this.fs.readFile(
35868
36093
  `;
35869
36094
  } else {
35870
36095
  styleCSS += await this.fs.readFile(
35871
- path18.resolve(
36096
+ path19.resolve(
35872
36097
  getCrossnoteBuildDirectory(),
35873
36098
  `./styles/prism_theme/${prismTheme}`
35874
36099
  )
@@ -35900,7 +36125,7 @@ ${await this.fs.readFile(
35900
36125
  ) : null;
35901
36126
  if (forceLightTheme) {
35902
36127
  styleCSS += await this.fs.readFile(
35903
- path18.resolve(
36128
+ path19.resolve(
35904
36129
  getCrossnoteBuildDirectory(),
35905
36130
  `./styles/preview_theme/github-light.css`
35906
36131
  )
@@ -35909,14 +36134,14 @@ ${await this.fs.readFile(
35909
36134
  const lightPreviewTheme = darkPreviewTheme === previewTheme ? _MarkdownEngine.PreviewThemeColorCounterparts[previewTheme] : previewTheme;
35910
36135
  colorSchemeMeta = '<meta name="color-scheme" content="light dark">';
35911
36136
  styleCSS += await this.fs.readFile(
35912
- path18.resolve(
36137
+ path19.resolve(
35913
36138
  getCrossnoteBuildDirectory(),
35914
36139
  `./styles/preview_theme/${lightPreviewTheme}`
35915
36140
  )
35916
36141
  );
35917
36142
  styleCSS += `@media (prefers-color-scheme: dark) {
35918
36143
  ${await this.fs.readFile(
35919
- path18.resolve(
36144
+ path19.resolve(
35920
36145
  getCrossnoteBuildDirectory(),
35921
36146
  `./styles/preview_theme/${darkPreviewTheme}`
35922
36147
  )
@@ -35925,7 +36150,7 @@ ${await this.fs.readFile(
35925
36150
  `;
35926
36151
  } else {
35927
36152
  styleCSS += await this.fs.readFile(
35928
- path18.resolve(
36153
+ path19.resolve(
35929
36154
  getCrossnoteBuildDirectory(),
35930
36155
  `./styles/preview_theme/${previewTheme}`
35931
36156
  )
@@ -35933,14 +36158,14 @@ ${await this.fs.readFile(
35933
36158
  }
35934
36159
  }
35935
36160
  styleCSS += await this.fs.readFile(
35936
- path18.resolve(
36161
+ path19.resolve(
35937
36162
  getCrossnoteBuildDirectory(),
35938
36163
  "./styles/style-template.css"
35939
36164
  )
35940
36165
  );
35941
36166
  if (html.indexOf("admonition") > 0) {
35942
36167
  styleCSS += await this.fs.readFile(
35943
- path18.resolve(
36168
+ path19.resolve(
35944
36169
  getCrossnoteBuildDirectory(),
35945
36170
  "./styles/markdown-it-admonition.css"
35946
36171
  )
@@ -35948,7 +36173,7 @@ ${await this.fs.readFile(
35948
36173
  }
35949
36174
  if (html.indexOf("callout") > 0) {
35950
36175
  styleCSS += await this.fs.readFile(
35951
- path18.resolve(
36176
+ path19.resolve(
35952
36177
  getCrossnoteBuildDirectory(),
35953
36178
  "./styles/markdown-it-callout.css"
35954
36179
  )
@@ -35957,7 +36182,9 @@ ${await this.fs.readFile(
35957
36182
  } catch {
35958
36183
  styleCSS = "";
35959
36184
  }
35960
- const globalStyles = this.notebook.config.globalCss;
36185
+ const globalStyles = this.resolvePathsInStyles(
36186
+ this.notebook.config.globalCss
36187
+ );
35961
36188
  let sidebarTOC = "";
35962
36189
  let sidebarTOCScript = "";
35963
36190
  let sidebarTOCBtn = "";
@@ -36096,26 +36323,26 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36096
36323
  runAllCodeChunks = false
36097
36324
  } = {}) {
36098
36325
  let dest = this.filePath;
36099
- const extname14 = path18.extname(dest);
36326
+ const extname14 = path19.extname(dest);
36100
36327
  dest = dest.replace(new RegExp(extname14 + "$"), ".html");
36101
36328
  const html = await this.htmlExportDocument({ offline, runAllCodeChunks });
36102
36329
  if (!offline && html.indexOf('[{"src":"revealjs_deps/notes.js","async":true}]') >= 0) {
36103
- const depsDirName = path18.resolve(path18.dirname(dest), "revealjs_deps");
36330
+ const depsDirName = path19.resolve(path19.dirname(dest), "revealjs_deps");
36104
36331
  if (!fs14.existsSync(depsDirName)) {
36105
36332
  fs14.mkdirSync(depsDirName);
36106
36333
  }
36107
36334
  fs14.createReadStream(
36108
- path18.resolve(
36335
+ path19.resolve(
36109
36336
  getCrossnoteBuildDirectory(),
36110
36337
  "./dependencies/reveal/plugin/notes/notes.js"
36111
36338
  )
36112
- ).pipe(fs14.createWriteStream(path18.resolve(depsDirName, "notes.js")));
36339
+ ).pipe(fs14.createWriteStream(path19.resolve(depsDirName, "notes.js")));
36113
36340
  fs14.createReadStream(
36114
- path18.resolve(
36341
+ path19.resolve(
36115
36342
  getCrossnoteBuildDirectory(),
36116
36343
  "./dependencies/reveal/plugin/notes/notes.html"
36117
36344
  )
36118
- ).pipe(fs14.createWriteStream(path18.resolve(depsDirName, "notes.html")));
36345
+ ).pipe(fs14.createWriteStream(path19.resolve(depsDirName, "notes.html")));
36119
36346
  }
36120
36347
  await this.fs.writeFile(dest, html);
36121
36348
  return dest;
@@ -36182,7 +36409,7 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36182
36409
  runAllCodeChunks
36183
36410
  }));
36184
36411
  let dest = this.filePath;
36185
- const extname14 = path18.extname(dest);
36412
+ const extname14 = path19.extname(dest);
36186
36413
  dest = dest.replace(new RegExp(extname14 + "$"), "." + fileType);
36187
36414
  html = await this.generateHTMLTemplateForExport(html, yamlConfig, {
36188
36415
  isForPrint: true,
@@ -36232,10 +36459,10 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36232
36459
  timeout = puppeteerConfig2["timeout"];
36233
36460
  }
36234
36461
  if (timeout && typeof timeout === "number") {
36235
- await new Promise((resolve20) => setTimeout(resolve20, timeout));
36462
+ await new Promise((resolve21) => setTimeout(resolve21, timeout));
36236
36463
  } else if (this.notebook.config.puppeteerWaitForTimeout && this.notebook.config.puppeteerWaitForTimeout > 0) {
36237
36464
  await new Promise(
36238
- (resolve20) => setTimeout(resolve20, this.notebook.config.puppeteerWaitForTimeout)
36465
+ (resolve21) => setTimeout(resolve21, this.notebook.config.puppeteerWaitForTimeout)
36239
36466
  );
36240
36467
  }
36241
36468
  if (fileType === "pdf") {
@@ -36269,7 +36496,7 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36269
36496
  runAllCodeChunks
36270
36497
  }));
36271
36498
  let dest = this.filePath;
36272
- const extname14 = path18.extname(dest);
36499
+ const extname14 = path19.extname(dest);
36273
36500
  dest = dest.replace(new RegExp(extname14 + "$"), ".pdf");
36274
36501
  html = await this.generateHTMLTemplateForExport(html, yamlConfig, {
36275
36502
  isForPrint: true,
@@ -36295,7 +36522,7 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36295
36522
  }
36296
36523
  async eBookDownloadImages($, dest) {
36297
36524
  const imagesToDownload = [];
36298
- if (path18.extname(dest) === ".epub" || path18.extname("dest") === ".mobi") {
36525
+ if (path19.extname(dest) === ".epub" || path19.extname("dest") === ".mobi") {
36299
36526
  $("img").each((offset, img) => {
36300
36527
  const $img = $(img);
36301
36528
  const src = $img.attr("src") || "";
@@ -36306,8 +36533,8 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36306
36533
  }
36307
36534
  const asyncFunctions = imagesToDownload.map(async ($img) => {
36308
36535
  const httpSrc = $img.attr("src") ?? "";
36309
- let savePath = Math.random().toString(36).substr(2, 9) + "_" + path18.basename(httpSrc);
36310
- savePath = path18.resolve(this.fileDirectoryPath, savePath);
36536
+ let savePath = Math.random().toString(36).substr(2, 9) + "_" + path19.basename(httpSrc);
36537
+ savePath = path19.resolve(this.fileDirectoryPath, savePath);
36311
36538
  const response = await fetch(httpSrc);
36312
36539
  if (!response.ok || !response.body) {
36313
36540
  throw new Error(`Failed to download image from ${httpSrc}`);
@@ -36346,7 +36573,7 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36346
36573
  emojiToSvg
36347
36574
  }));
36348
36575
  let dest = this.filePath;
36349
- const extname14 = path18.extname(dest);
36576
+ const extname14 = path19.extname(dest);
36350
36577
  dest = dest.replace(
36351
36578
  new RegExp(extname14 + "$"),
36352
36579
  "." + fileType.toLowerCase()
@@ -36407,24 +36634,24 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36407
36634
  }
36408
36635
  const asyncFunctions = tocStructure.map(
36409
36636
  ({ heading, id, level, filePath }, offset) => {
36410
- return new Promise((resolve20, reject) => {
36637
+ return new Promise((resolve21, reject) => {
36411
36638
  filePath = removeFileProtocol(filePath);
36412
36639
  if (filePath.match(/^https?:\/\//)) {
36413
- return resolve20({ heading, id, level, filePath, html: "", offset });
36640
+ return resolve21({ heading, id, level, filePath, html: "", offset });
36414
36641
  }
36415
36642
  fs14.readFile(filePath, { encoding: "utf-8" }, (error, text) => {
36416
36643
  if (error) {
36417
36644
  return reject(error.toString());
36418
36645
  }
36419
- const rootPath = path18.dirname(this.filePath);
36646
+ const rootPath = path19.dirname(this.filePath);
36420
36647
  text = text.replace(
36421
36648
  /(!\[[^\]]*\]\()(\.[^)\s]*)/g,
36422
36649
  (whole, openTag, imageLink) => {
36423
- const fullPath = path18.resolve(
36424
- path18.dirname(filePath),
36650
+ const fullPath = path19.resolve(
36651
+ path19.dirname(filePath),
36425
36652
  imageLink
36426
36653
  );
36427
- const relativePath = path18.relative(rootPath, fullPath);
36654
+ const relativePath = path19.relative(rootPath, fullPath);
36428
36655
  return openTag + relativePath;
36429
36656
  }
36430
36657
  );
@@ -36433,10 +36660,10 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36433
36660
  isForPreview: false,
36434
36661
  hideFrontMatter: true,
36435
36662
  emojiToSvg,
36436
- fileDirectoryPath: path18.dirname(filePath)
36663
+ fileDirectoryPath: path19.dirname(filePath)
36437
36664
  /* tslint:disable-next-line:no-shadowed-variable */
36438
36665
  }).then(({ html: html2 }) => {
36439
- return resolve20({ heading, id, level, filePath, html: html2, offset });
36666
+ return resolve21({ heading, id, level, filePath, html: html2, offset });
36440
36667
  });
36441
36668
  });
36442
36669
  });
@@ -36462,7 +36689,7 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36462
36689
  });
36463
36690
  $ = cheerio3.load(outputHTML);
36464
36691
  const downloadedImagePaths = await this.eBookDownloadImages($, dest);
36465
- if (path18.extname(dest) === ".html") {
36692
+ if (path19.extname(dest) === ".html") {
36466
36693
  if (ebookConfig["cover"]) {
36467
36694
  const cover = ebookConfig["cover"];
36468
36695
  const coverUrl = cover[0] === "/" ? toFileURL(cover) : cover;
@@ -36480,11 +36707,11 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36480
36707
  const title = ebookConfig["title"] || "no title";
36481
36708
  let mathStyle = "";
36482
36709
  if (outputHTML.indexOf('class="katex"') > 0) {
36483
- if (path18.extname(dest) === ".html" && ebookConfig["html"] && ebookConfig["html"]["cdn"]) {
36710
+ if (path19.extname(dest) === ".html" && ebookConfig["html"] && ebookConfig["html"]["cdn"]) {
36484
36711
  mathStyle = `<link rel="stylesheet" href="https://${this.notebook.config.jsdelivrCdnHost}/npm/katex@0.16.47/dist/katex.min.css">`;
36485
36712
  } else {
36486
36713
  mathStyle = `<link rel="stylesheet" href="${toFileURL(
36487
- path18.resolve(
36714
+ path19.resolve(
36488
36715
  getCrossnoteBuildDirectory(),
36489
36716
  "./dependencies/katex/katex.min.css"
36490
36717
  )
@@ -36496,14 +36723,14 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36496
36723
  const styles = await Promise.all([
36497
36724
  // style template
36498
36725
  await this.fs.readFile(
36499
- path18.resolve(
36726
+ path19.resolve(
36500
36727
  getCrossnoteBuildDirectory(),
36501
36728
  "./styles/style-template.css"
36502
36729
  )
36503
36730
  ),
36504
36731
  // prism *.css
36505
36732
  await this.fs.readFile(
36506
- path18.resolve(
36733
+ path19.resolve(
36507
36734
  getCrossnoteBuildDirectory(),
36508
36735
  `./styles/prism_theme/${_MarkdownEngine.resolveThemeForExport(
36509
36736
  _MarkdownEngine.AutoPrismThemeMap[ebookConfig["theme"] || this.notebook.config.previewTheme] ?? "default.css",
@@ -36513,14 +36740,14 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36513
36740
  ),
36514
36741
  // twemoji css style
36515
36742
  await this.fs.readFile(
36516
- path18.resolve(
36743
+ path19.resolve(
36517
36744
  getCrossnoteBuildDirectory(),
36518
36745
  "./styles/twemoji.css"
36519
36746
  )
36520
36747
  ),
36521
36748
  // preview theme
36522
36749
  await this.fs.readFile(
36523
- path18.resolve(
36750
+ path19.resolve(
36524
36751
  getCrossnoteBuildDirectory(),
36525
36752
  `./styles/preview_theme/${_MarkdownEngine.resolveThemeForExport(
36526
36753
  ebookConfig["theme"] || this.notebook.config.previewTheme,
@@ -36530,14 +36757,14 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36530
36757
  ),
36531
36758
  // markdown-it-admonition
36532
36759
  outputHTML.indexOf("admonition") > 0 ? await this.fs.readFile(
36533
- path18.resolve(
36760
+ path19.resolve(
36534
36761
  getCrossnoteBuildDirectory(),
36535
36762
  "./styles/markdown-it-admonition.css"
36536
36763
  )
36537
36764
  ) : "",
36538
36765
  // markdown-it-callout
36539
36766
  outputHTML.indexOf("callout") > 0 ? await this.fs.readFile(
36540
- path18.resolve(
36767
+ path19.resolve(
36541
36768
  getCrossnoteBuildDirectory(),
36542
36769
  "./styles/markdown-it-callout.css"
36543
36770
  )
@@ -36549,7 +36776,7 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36549
36776
  }
36550
36777
  let globalStyles = "";
36551
36778
  try {
36552
- globalStyles = this.notebook.config.globalCss;
36779
+ globalStyles = this.resolvePathsInStyles(this.notebook.config.globalCss);
36553
36780
  } catch {
36554
36781
  }
36555
36782
  html = `
@@ -36566,14 +36793,14 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36566
36793
  ${mathStyle}
36567
36794
  ${await this.resolvePathsInHeader(this.notebook.config.includeInHeader)}
36568
36795
  </head>
36569
- <body ${path18.extname(dest) === ".html" ? 'for="html-export"' : ""}>
36796
+ <body ${path19.extname(dest) === ".html" ? 'for="html-export"' : ""}>
36570
36797
  <div class="crossnote markdown-preview">
36571
36798
  ${outputHTML}
36572
36799
  </div>
36573
36800
  </body>
36574
36801
  </html>
36575
36802
  `;
36576
- if (path18.extname(dest) === ".html") {
36803
+ if (path19.extname(dest) === ".html") {
36577
36804
  await this.fs.writeFile(dest, html);
36578
36805
  return dest;
36579
36806
  }
@@ -36689,11 +36916,11 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36689
36916
  markdownConfig["path"] = this.filePath.replace(/\.src\./, ".");
36690
36917
  } else {
36691
36918
  markdownConfig["path"] = this.filePath.replace(
36692
- new RegExp(path18.extname(this.filePath)),
36693
- "_" + path18.extname(this.filePath)
36919
+ new RegExp(path19.extname(this.filePath)),
36920
+ "_" + path19.extname(this.filePath)
36694
36921
  );
36695
36922
  }
36696
- markdownConfig["path"] = path18.basename(markdownConfig["path"]);
36923
+ markdownConfig["path"] = path19.basename(markdownConfig["path"]);
36697
36924
  }
36698
36925
  if (markdownConfig["ignore_from_front_matter"] || !("ignore_from_front_matter" in markdownConfig)) {
36699
36926
  delete config["markdown"];
@@ -36780,13 +37007,13 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36780
37007
  return filePath;
36781
37008
  } else if (filePath[0] === "/") {
36782
37009
  if (relative11) {
36783
- return path18.relative(
37010
+ return path19.relative(
36784
37011
  fileDirectoryPath || this.fileDirectoryPath,
36785
- path18.resolve(this.projectDirectoryPath.fsPath, "." + filePath)
37012
+ path19.resolve(this.projectDirectoryPath.fsPath, "." + filePath)
36786
37013
  );
36787
37014
  } else {
36788
37015
  return addFileProtocol(
36789
- path18.resolve(this.projectDirectoryPath.fsPath, "." + filePath),
37016
+ path19.resolve(this.projectDirectoryPath.fsPath, "." + filePath),
36790
37017
  this.vscodePreviewPanel
36791
37018
  );
36792
37019
  }
@@ -36795,12 +37022,33 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36795
37022
  return filePath;
36796
37023
  } else {
36797
37024
  return addFileProtocol(
36798
- path18.resolve(fileDirectoryPath || this.fileDirectoryPath, filePath),
37025
+ path19.resolve(fileDirectoryPath || this.fileDirectoryPath, filePath),
36799
37026
  this.vscodePreviewPanel
36800
37027
  );
36801
37028
  }
36802
37029
  }
36803
37030
  }
37031
+ /**
37032
+ * Turn the absolute filesystem paths that `resolveRelativeCssUrls` left in
37033
+ * the user's compiled `style.less` into URLs the current render target can
37034
+ * load — `vscode-webview://…` inside a VS Code webview, `file://…` for every
37035
+ * export path and for `crossnote serve`.
37036
+ *
37037
+ * Without this the preview inlines `<style>` with the paths still raw, and a
37038
+ * relative `@font-face src` (or `background-image`) resolves against the
37039
+ * webview document instead of the stylesheet, so local fonts silently fall
37040
+ * back while remote ones keep working
37041
+ * ([vscode-mpe#2424](https://github.com/shd101wyy/vscode-markdown-preview-enhanced/issues/2424)).
37042
+ */
37043
+ resolvePathsInStyles(css, vscodePreviewPanel) {
37044
+ if (!css) {
37045
+ return css;
37046
+ }
37047
+ return mapAbsoluteCssUrls(
37048
+ css,
37049
+ (filePath) => addFileProtocol(filePath, vscodePreviewPanel)
37050
+ );
37051
+ }
36804
37052
  // FIXME: This function actually doesn't help in the web version.
36805
37053
  async resolvePathsInHeader(header, {
36806
37054
  allowScripts = false,
@@ -36815,9 +37063,9 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36815
37063
  $(element).remove();
36816
37064
  return;
36817
37065
  }
36818
- const candidatePaths = src.startsWith("/") ? [path18.resolve(this.projectDirectoryPath.fsPath, "." + src)] : [
36819
- path18.resolve(this.fileDirectoryPath, src),
36820
- ...trustedScriptRoots.map((root) => path18.resolve(root, src))
37066
+ const candidatePaths = src.startsWith("/") ? [path19.resolve(this.projectDirectoryPath.fsPath, "." + src)] : [
37067
+ path19.resolve(this.fileDirectoryPath, src),
37068
+ ...trustedScriptRoots.map((root) => path19.resolve(root, src))
36821
37069
  ];
36822
37070
  const resolvedPath = candidatePaths.find(
36823
37071
  (p) => isExistingFile(p) && (this.isPathInsideProjectDirectory(p) || trustedScriptRoots.some(
@@ -37077,9 +37325,9 @@ sidebarTOCBtn.addEventListener('click', function(event) {
37077
37325
  i += 1;
37078
37326
  }
37079
37327
  const pandocPath = this.notebook.config.pandocPath;
37080
- return await new Promise((resolve20, reject) => {
37328
+ return await new Promise((resolve21, reject) => {
37081
37329
  try {
37082
- const program = (0, import_child_process13.execFile)(
37330
+ const program = (0, import_child_process11.execFile)(
37083
37331
  pandocPath,
37084
37332
  args,
37085
37333
  { cwd: this.fileDirectoryPath, maxBuffer: Infinity },
@@ -37087,11 +37335,11 @@ sidebarTOCBtn.addEventListener('click', function(event) {
37087
37335
  if (error) {
37088
37336
  return reject(error);
37089
37337
  } else if (stderr) {
37090
- return resolve20(
37338
+ return resolve21(
37091
37339
  '<pre class="language-text"><code>' + (0, import_html_escaper13.escape)(stderr) + "</code></pre>" + stdout
37092
37340
  );
37093
37341
  } else {
37094
- return resolve20(stdout);
37342
+ return resolve21(stdout);
37095
37343
  }
37096
37344
  }
37097
37345
  );
@@ -37168,7 +37416,7 @@ Check "http://pandoc.org/installing.html" website.`;
37168
37416
  )}</code></pre>`;
37169
37417
  }
37170
37418
  } else {
37171
- this.notebook.currentRenderFilePath = path18.relative(
37419
+ this.notebook.currentRenderFilePath = path19.relative(
37172
37420
  this.notebook.notebookPath.fsPath,
37173
37421
  this.filePath
37174
37422
  );
@@ -37412,7 +37660,7 @@ ${result}
37412
37660
  // src/wiki/index.ts
37413
37661
  var cheerio4 = __toESM(require("cheerio"));
37414
37662
  var fs18 = __toESM(require("fs"));
37415
- var path22 = __toESM(require("path"));
37663
+ var path23 = __toESM(require("path"));
37416
37664
 
37417
37665
  // src/serve/preview-host-shim.ts
37418
37666
  function previewHostShimScript(targetOriginExpression) {
@@ -37463,35 +37711,35 @@ function previewHostShimScript(targetOriginExpression) {
37463
37711
 
37464
37712
  // src/serve/config.ts
37465
37713
  var fs16 = __toESM(require("fs"));
37466
- var os3 = __toESM(require("os"));
37467
- var path20 = __toESM(require("path"));
37714
+ var os4 = __toESM(require("os"));
37715
+ var path21 = __toESM(require("path"));
37468
37716
 
37469
37717
  // src/serve/config-writer.ts
37470
37718
  var fs15 = __toESM(require("fs"));
37471
- var os2 = __toESM(require("os"));
37472
- var path19 = __toESM(require("path"));
37719
+ var os3 = __toESM(require("os"));
37720
+ var path20 = __toESM(require("path"));
37473
37721
  var import_json53 = __toESM(require("json5"));
37474
37722
  var MPE_SETTINGS_PREFIX = "markdown-preview-enhanced.";
37475
37723
  function detectVSCodeSettingsPath(explicitPath) {
37476
37724
  if (explicitPath) {
37477
- return path19.resolve(explicitPath);
37725
+ return path20.resolve(explicitPath);
37478
37726
  }
37479
- const home = os2.homedir();
37727
+ const home = os3.homedir();
37480
37728
  const candidates = process.platform === "win32" ? [
37481
- path19.join(home, "AppData/Roaming/Code - Insiders/User/settings.json"),
37482
- path19.join(home, "AppData/Roaming/Code/User/settings.json")
37729
+ path20.join(home, "AppData/Roaming/Code - Insiders/User/settings.json"),
37730
+ path20.join(home, "AppData/Roaming/Code/User/settings.json")
37483
37731
  ] : process.platform === "darwin" ? [
37484
- path19.join(
37732
+ path20.join(
37485
37733
  home,
37486
37734
  "Library/Application Support/Code - Insiders/User/settings.json"
37487
37735
  ),
37488
- path19.join(
37736
+ path20.join(
37489
37737
  home,
37490
37738
  "Library/Application Support/Code/User/settings.json"
37491
37739
  )
37492
37740
  ] : [
37493
- path19.join(home, ".config/Code - Insiders/User/settings.json"),
37494
- path19.join(home, ".config/Code/User/settings.json")
37741
+ path20.join(home, ".config/Code - Insiders/User/settings.json"),
37742
+ path20.join(home, ".config/Code/User/settings.json")
37495
37743
  ];
37496
37744
  for (const candidate of candidates) {
37497
37745
  if (fs15.existsSync(candidate)) {
@@ -37586,11 +37834,11 @@ async function updateVSCodeSetting(settingsPath, key, value) {
37586
37834
  { cause: error }
37587
37835
  );
37588
37836
  }
37589
- await fs15.promises.mkdir(path19.dirname(settingsPath), { recursive: true });
37837
+ await fs15.promises.mkdir(path20.dirname(settingsPath), { recursive: true });
37590
37838
  await fs15.promises.writeFile(settingsPath, text, "utf-8");
37591
37839
  }
37592
37840
  async function updateGlobalConfigKey(globalConfigDirectory, key, value) {
37593
- const configScriptPath = path19.join(globalConfigDirectory, "./config.js");
37841
+ const configScriptPath = path20.join(globalConfigDirectory, "./config.js");
37594
37842
  let parsed = {};
37595
37843
  if (fs15.existsSync(configScriptPath)) {
37596
37844
  const raw = await fs15.promises.readFile(configScriptPath, "utf-8");
@@ -37632,17 +37880,17 @@ ${JSON.stringify(
37632
37880
  // src/serve/config.ts
37633
37881
  function getGlobalConfigDirectory() {
37634
37882
  if (process.platform === "win32") {
37635
- return path20.join(os3.homedir(), "./.crossnote");
37883
+ return path21.join(os4.homedir(), "./.crossnote");
37636
37884
  }
37637
37885
  if (typeof process.env.XDG_CONFIG_HOME === "string" && process.env.XDG_CONFIG_HOME !== "") {
37638
- return path20.resolve(process.env.XDG_CONFIG_HOME, "./crossnote");
37886
+ return path21.resolve(process.env.XDG_CONFIG_HOME, "./crossnote");
37639
37887
  }
37640
- return path20.resolve(os3.homedir(), "./.local/state/crossnote");
37888
+ return path21.resolve(os4.homedir(), "./.local/state/crossnote");
37641
37889
  }
37642
37890
  async function createConfigContext(options) {
37643
37891
  const globalConfigDirectory = options.globalConfigDirectory ?? getGlobalConfigDirectory();
37644
37892
  return {
37645
- rootDirectory: path20.resolve(options.rootDirectory),
37893
+ rootDirectory: path21.resolve(options.rootDirectory),
37646
37894
  vscode: !!options.vscode,
37647
37895
  globalConfigDirectory,
37648
37896
  vscodeSettingsPath: options.vscode ? detectVSCodeSettingsPath(options.vscodeSettingsPath) : null
@@ -37664,7 +37912,7 @@ async function loadServerConfig(context) {
37664
37912
  console.error("Failed to load global crossnote config:", error);
37665
37913
  }
37666
37914
  let workspaceConfig = {};
37667
- const workspaceConfigDirectory = path20.join(
37915
+ const workspaceConfigDirectory = path21.join(
37668
37916
  context.rootDirectory,
37669
37917
  "./.crossnote"
37670
37918
  );
@@ -37701,7 +37949,7 @@ async function updateServerConfigKey(context, key, value) {
37701
37949
  async function createNotebooksForDirectories(directories, options = {}) {
37702
37950
  const rootDirectories = [];
37703
37951
  for (const directory of directories) {
37704
- const resolved = path20.resolve(directory);
37952
+ const resolved = path21.resolve(directory);
37705
37953
  const stat3 = await fs16.promises.stat(resolved).catch(() => null);
37706
37954
  if (!stat3?.isDirectory()) {
37707
37955
  throw new Error(`Not a directory: ${resolved}`);
@@ -37733,12 +37981,12 @@ async function createNotebooksForDirectories(directories, options = {}) {
37733
37981
 
37734
37982
  // src/serve/markdown-files.ts
37735
37983
  var fs17 = __toESM(require("fs"));
37736
- var path21 = __toESM(require("path"));
37984
+ var path22 = __toESM(require("path"));
37737
37985
  var import_ignore2 = __toESM(require("ignore"));
37738
37986
  var MARKDOWN_EXTENSIONS = [".md", ".markdown", ".mdx"];
37739
37987
  var SKIPPED_DIRECTORY_NAMES = /* @__PURE__ */ new Set(["node_modules", ".git"]);
37740
37988
  function isMarkdownFile(filePath) {
37741
- return MARKDOWN_EXTENSIONS.includes(path21.extname(filePath).toLowerCase());
37989
+ return MARKDOWN_EXTENSIONS.includes(path22.extname(filePath).toLowerCase());
37742
37990
  }
37743
37991
  function encodePathSegments(relativePath) {
37744
37992
  return relativePath.split("/").map((segment) => encodeURIComponent(segment)).join("/");
@@ -37756,7 +38004,7 @@ function isPathWithinRootOn(platform, root, candidate) {
37756
38004
  return candidate === root || candidate.startsWith(root + "/");
37757
38005
  }
37758
38006
  async function listMarkdownFiles(rootDirectory, limit = 5e3) {
37759
- const gitignorePath = path21.join(rootDirectory, ".gitignore");
38007
+ const gitignorePath = path22.join(rootDirectory, ".gitignore");
37760
38008
  let isIgnored = () => false;
37761
38009
  try {
37762
38010
  if (fs17.existsSync(gitignorePath)) {
@@ -37777,8 +38025,8 @@ async function listMarkdownFiles(rootDirectory, limit = 5e3) {
37777
38025
  continue;
37778
38026
  }
37779
38027
  for (const entry of entries) {
37780
- const absolutePath = path21.join(directory, entry.name);
37781
- const relativePath = path21.relative(rootDirectory, absolutePath).split(path21.sep).join("/");
38028
+ const absolutePath = path22.join(directory, entry.name);
38029
+ const relativePath = path22.relative(rootDirectory, absolutePath).split(path22.sep).join("/");
37782
38030
  if (isIgnored(relativePath) || entry.isDirectory() && isIgnored(`${relativePath}/`)) {
37783
38031
  continue;
37784
38032
  }
@@ -37820,14 +38068,14 @@ var IMAGE_MIME_TYPES = {
37820
38068
  };
37821
38069
  var SCRIPT_STYLE_EXTENSIONS = /* @__PURE__ */ new Set([".js", ".mjs", ".cjs", ".css"]);
37822
38070
  function isImagePath(filePath) {
37823
- const extension = path22.extname(filePath).toLowerCase().slice(1);
38071
+ const extension = path23.extname(filePath).toLowerCase().slice(1);
37824
38072
  return extension in IMAGE_MIME_TYPES;
37825
38073
  }
37826
38074
  function toPosixPath(filePath) {
37827
- return filePath.split(path22.sep).join("/");
38075
+ return filePath.split(path23.sep).join("/");
37828
38076
  }
37829
38077
  async function buildWiki(options) {
37830
- const buildDirectory = path22.resolve(
38078
+ const buildDirectory = path23.resolve(
37831
38079
  options.crossnoteBuildDirectory ?? getCrossnoteBuildDirectory()
37832
38080
  );
37833
38081
  setCrossnoteBuildDirectory(buildDirectory);
@@ -37840,17 +38088,17 @@ async function buildWiki(options) {
37840
38088
  }
37841
38089
  );
37842
38090
  const multiRoot = rootDirectories.length > 1;
37843
- const rootNames = rootDirectories.map((root) => path22.basename(root) || root);
38091
+ const rootNames = rootDirectories.map((root) => path23.basename(root) || root);
37844
38092
  const noteKeyFor = (absolutePath, rootIndex) => {
37845
38093
  const relative11 = toPosixPath(
37846
- path22.relative(rootDirectories[rootIndex], absolutePath)
38094
+ path23.relative(rootDirectories[rootIndex], absolutePath)
37847
38095
  );
37848
38096
  return multiRoot ? `${rootNames[rootIndex]}/${relative11}` : relative11;
37849
38097
  };
37850
38098
  const assetIds = /* @__PURE__ */ new Map();
37851
38099
  let assetCounter = 0;
37852
38100
  const tokenFor = (filePath) => {
37853
- const resolved = path22.resolve(filePath);
38101
+ const resolved = path23.resolve(filePath);
37854
38102
  let id = assetIds.get(resolved);
37855
38103
  if (id === void 0) {
37856
38104
  id = String(assetCounter++);
@@ -37859,7 +38107,7 @@ async function buildWiki(options) {
37859
38107
  return `${ASSET_TOKEN_PREFIX}${id}`;
37860
38108
  };
37861
38109
  const dataUriForImage = (filePath) => {
37862
- const extension = path22.extname(filePath).toLowerCase().slice(1);
38110
+ const extension = path23.extname(filePath).toLowerCase().slice(1);
37863
38111
  const mime = IMAGE_MIME_TYPES[extension];
37864
38112
  if (!mime) {
37865
38113
  return null;
@@ -37891,7 +38139,7 @@ async function buildWiki(options) {
37891
38139
  const cleanPath = resolvedPath(filePath);
37892
38140
  if (isPathWithinRoot(buildDirectory, cleanPath)) {
37893
38141
  const relativeToBuild = toPosixPath(
37894
- path22.relative(buildDirectory, cleanPath)
38142
+ path23.relative(buildDirectory, cleanPath)
37895
38143
  );
37896
38144
  if (relativeToBuild.startsWith("styles/preview_theme/")) {
37897
38145
  return `${THEME_TOKEN_PREFIX}preview`;
@@ -37915,10 +38163,10 @@ async function buildWiki(options) {
37915
38163
  }
37916
38164
  return addFileProtocol(cleanPath);
37917
38165
  }
37918
- if (SCRIPT_STYLE_EXTENSIONS.has(path22.extname(cleanPath).toLowerCase())) {
38166
+ if (SCRIPT_STYLE_EXTENSIONS.has(path23.extname(cleanPath).toLowerCase())) {
37919
38167
  return tokenFor(cleanPath);
37920
38168
  }
37921
- const relative11 = path22.relative(root, cleanPath);
38169
+ const relative11 = path23.relative(root, cleanPath);
37922
38170
  return `/${toPosixPath(relative11)}`;
37923
38171
  }
37924
38172
  return addFileProtocol(cleanPath);
@@ -37961,7 +38209,7 @@ async function buildWiki(options) {
37961
38209
  head: ""
37962
38210
  });
37963
38211
  const yamlConfig = output.yamlConfig;
37964
- const title = typeof yamlConfig["title"] === "string" && yamlConfig["title"].trim() || path22.basename(file.absolutePath, path22.extname(file.absolutePath));
38212
+ const title = typeof yamlConfig["title"] === "string" && yamlConfig["title"].trim() || path23.basename(file.absolutePath, path23.extname(file.absolutePath));
37965
38213
  const mtimeMs = (await fs18.promises.stat(file.absolutePath)).mtimeMs;
37966
38214
  files.push({
37967
38215
  path: noteKey,
@@ -38005,11 +38253,11 @@ async function buildWiki(options) {
38005
38253
  }
38006
38254
  const assets = {};
38007
38255
  for (const [filePath, id] of assetIds) {
38008
- assets[id] = path22.extname(filePath).toLowerCase() === ".css" ? await readStylesheetWithInlinedUrls(filePath) : await fs18.promises.readFile(filePath, "utf-8").catch(() => "");
38256
+ assets[id] = path23.extname(filePath).toLowerCase() === ".css" ? await readStylesheetWithInlinedUrls(filePath) : await fs18.promises.readFile(filePath, "utf-8").catch(() => "");
38009
38257
  }
38010
- assets["graph-view.js"] = await fs18.promises.readFile(path22.join(buildDirectory, "webview", "graph-view.js"), "utf-8").catch(() => "");
38258
+ assets["graph-view.js"] = await fs18.promises.readFile(path23.join(buildDirectory, "webview", "graph-view.js"), "utf-8").catch(() => "");
38011
38259
  assets["graph-view.css"] = await readStylesheetWithInlinedUrls(
38012
- path22.join(buildDirectory, "webview", "graph-view.css")
38260
+ path23.join(buildDirectory, "webview", "graph-view.css")
38013
38261
  ).catch(() => "");
38014
38262
  const themes = await collectThemeAssets(buildDirectory, notebooks[0]);
38015
38263
  const graph = {};
@@ -38036,7 +38284,7 @@ async function buildWiki(options) {
38036
38284
  }
38037
38285
  try {
38038
38286
  backlinks[file.path] = (await notebook.getNoteBacklinks(
38039
- path22.join(rootDirectories[rootIndex], ...file.path.split("/"))
38287
+ path23.join(rootDirectories[rootIndex], ...file.path.split("/"))
38040
38288
  ) ?? []).map(
38041
38289
  (backlink) => scrubBacklinkForWiki(backlink, rootDirectories[rootIndex])
38042
38290
  );
@@ -38059,8 +38307,8 @@ async function buildWiki(options) {
38059
38307
  });
38060
38308
  return {
38061
38309
  html,
38062
- files: files.map(({ path: path27, root, title, mtimeMs }) => ({
38063
- path: path27,
38310
+ files: files.map(({ path: path28, root, title, mtimeMs }) => ({
38311
+ path: path28,
38064
38312
  root,
38065
38313
  title,
38066
38314
  mtimeMs
@@ -38107,11 +38355,11 @@ function scrubWikiHtmlLinks(html, rootDirectory) {
38107
38355
  decoded = "/" + decoded;
38108
38356
  }
38109
38357
  }
38110
- const normalized = decoded.replace(/\//g, path22.sep);
38358
+ const normalized = decoded.replace(/\//g, path23.sep);
38111
38359
  if (!isPathWithinRoot(rootDirectory, normalized)) {
38112
38360
  continue;
38113
38361
  }
38114
- const relative11 = path22.relative(rootDirectory, normalized).split(path22.sep).join("/");
38362
+ const relative11 = path23.relative(rootDirectory, normalized).split(path23.sep).join("/");
38115
38363
  $(element).attr(attribute, `file:///${relative11}`);
38116
38364
  }
38117
38365
  });
@@ -38122,7 +38370,7 @@ function scrubWikiHtmlLinks(html, rootDirectory) {
38122
38370
  }
38123
38371
  async function collectThemeAssets(buildDirectory, notebook) {
38124
38372
  const readThemeDirectory = async (relativeDirectory) => {
38125
- const absoluteDirectory = path22.join(
38373
+ const absoluteDirectory = path23.join(
38126
38374
  buildDirectory,
38127
38375
  ...relativeDirectory.split("/")
38128
38376
  );
@@ -38133,7 +38381,7 @@ async function collectThemeAssets(buildDirectory, notebook) {
38133
38381
  continue;
38134
38382
  }
38135
38383
  map[entry] = await readStylesheetWithInlinedUrls(
38136
- path22.join(absoluteDirectory, entry)
38384
+ path23.join(absoluteDirectory, entry)
38137
38385
  );
38138
38386
  }
38139
38387
  return map;
@@ -38217,7 +38465,7 @@ async function readStylesheetWithInlinedUrls(cssPath) {
38217
38465
  } catch {
38218
38466
  return "";
38219
38467
  }
38220
- const directory = path22.dirname(cssPath);
38468
+ const directory = path23.dirname(cssPath);
38221
38469
  const cache = /* @__PURE__ */ new Map();
38222
38470
  return css.replace(
38223
38471
  /url\(\s*(['"]?)([^'")]+)\1\s*\)/g,
@@ -38229,8 +38477,8 @@ async function readStylesheetWithInlinedUrls(cssPath) {
38229
38477
  if (dataUri === void 0) {
38230
38478
  dataUri = "";
38231
38479
  try {
38232
- const assetPath = path22.resolve(directory, decodeURIComponent(ref));
38233
- const extension = path22.extname(assetPath).toLowerCase().slice(1);
38480
+ const assetPath = path23.resolve(directory, decodeURIComponent(ref));
38481
+ const extension = path23.extname(assetPath).toLowerCase().slice(1);
38234
38482
  const mime = IMAGE_MIME_TYPES[extension] ?? (extension === "woff2" ? "font/woff2" : extension === "woff" ? "font/woff" : extension === "ttf" ? "font/ttf" : extension === "otf" ? "font/otf" : extension === "eot" ? "application/vnd.ms-fontobject" : "application/octet-stream");
38235
38483
  const base64 = fs18.readFileSync(assetPath).toString("base64");
38236
38484
  dataUri = `data:${mime};base64,${base64}`;
@@ -38252,12 +38500,12 @@ function buildShellHTML({
38252
38500
  backlinks,
38253
38501
  buildDirectory
38254
38502
  }) {
38255
- const appScriptPath = path22.join(
38503
+ const appScriptPath = path23.join(
38256
38504
  buildDirectory,
38257
38505
  "server-app",
38258
38506
  "server-app.js"
38259
38507
  );
38260
- const appStylePath = path22.join(
38508
+ const appStylePath = path23.join(
38261
38509
  buildDirectory,
38262
38510
  "server-app",
38263
38511
  "server-app.css"
@@ -38459,7 +38707,7 @@ var SSEHub = class {
38459
38707
 
38460
38708
  // src/serve/static.ts
38461
38709
  var fs19 = __toESM(require("fs"));
38462
- var path23 = __toESM(require("path"));
38710
+ var path24 = __toESM(require("path"));
38463
38711
  var CONTENT_TYPES = {
38464
38712
  ".js": "text/javascript; charset=utf-8",
38465
38713
  ".mjs": "text/javascript; charset=utf-8",
@@ -38519,10 +38767,10 @@ function resolveMountedFile(mountRoots, urlPrefix, urlPath, preferredRootIndex)
38519
38767
  }
38520
38768
  }
38521
38769
  for (const index of candidates) {
38522
- const root = path23.resolve(mountRoots[index]);
38523
- const filePath = path23.resolve(
38770
+ const root = path24.resolve(mountRoots[index]);
38771
+ const filePath = path24.resolve(
38524
38772
  root,
38525
- `.${path23.sep}${relativePath.replace(/\//g, path23.sep)}`
38773
+ `.${path24.sep}${relativePath.replace(/\//g, path24.sep)}`
38526
38774
  );
38527
38775
  if (!isPathWithinRoot(root, filePath)) {
38528
38776
  continue;
@@ -38543,7 +38791,7 @@ function serveFileFromPath(response, filePath) {
38543
38791
  response.end("not found");
38544
38792
  return;
38545
38793
  }
38546
- const extension = path23.extname(filePath).toLowerCase();
38794
+ const extension = path24.extname(filePath).toLowerCase();
38547
38795
  const contentType = CONTENT_TYPES[extension] ?? "application/octet-stream";
38548
38796
  response.writeHead(200, {
38549
38797
  "content-type": contentType,
@@ -38562,7 +38810,7 @@ function serveFileFromPath(response, filePath) {
38562
38810
 
38563
38811
  // src/serve/watcher.ts
38564
38812
  var fs20 = __toESM(require("fs"));
38565
- var path24 = __toESM(require("path"));
38813
+ var path25 = __toESM(require("path"));
38566
38814
  var MarkdownWatcher = class {
38567
38815
  constructor(rootDirectory, onChange, pollIntervalMs = 1e3) {
38568
38816
  this.rootDirectory = rootDirectory;
@@ -38583,7 +38831,7 @@ var MarkdownWatcher = class {
38583
38831
  if (!filename) {
38584
38832
  return;
38585
38833
  }
38586
- const absolutePath = path24.resolve(this.rootDirectory, filename);
38834
+ const absolutePath = path25.resolve(this.rootDirectory, filename);
38587
38835
  if (!isMarkdownFile(absolutePath)) {
38588
38836
  return;
38589
38837
  }
@@ -38672,12 +38920,12 @@ var RequestError = class extends Error {
38672
38920
  };
38673
38921
  var MAX_COMMAND_BODY_BYTES = 64 * 1024 * 1024;
38674
38922
  async function nonConflictingWikiPath(rootDirectory) {
38675
- const base = path25.join(rootDirectory, "crossnote-wiki.html");
38923
+ const base = path26.join(rootDirectory, "crossnote-wiki.html");
38676
38924
  if (!fs21.existsSync(base)) {
38677
38925
  return base;
38678
38926
  }
38679
38927
  const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:]/g, "").replace(/\..+$/, "").replace("T", "-");
38680
- return path25.join(rootDirectory, `crossnote-wiki-${stamp}.html`);
38928
+ return path26.join(rootDirectory, `crossnote-wiki-${stamp}.html`);
38681
38929
  }
38682
38930
  var PREVIEW_HOST_SHIM = previewHostShimScript("window.location.origin");
38683
38931
  var GRAPH_HOST_SHIM = graphHostShimScript({
@@ -38711,27 +38959,30 @@ async function startServeServer(options) {
38711
38959
  globalConfigDirectory: options.globalConfigDirectory
38712
38960
  });
38713
38961
  const rootDirectory = rootDirectories[0];
38714
- const buildDirectory = path25.resolve(
38962
+ const buildDirectory = path26.resolve(
38715
38963
  options.crossnoteBuildDirectory ?? utility.getCrossnoteBuildDirectory()
38716
38964
  );
38717
38965
  utility.setCrossnoteBuildDirectory(buildDirectory);
38718
38966
  const dummyPanel = {};
38719
38967
  utility.useExternalAddFileProtocolFunction((filePath) => {
38720
38968
  if (isPathWithinRoot(buildDirectory, filePath)) {
38721
- const relativePath = path25.relative(buildDirectory, filePath).split(path25.sep).join("/");
38969
+ const relativePath = path26.relative(buildDirectory, filePath).split(path26.sep).join("/");
38722
38970
  return `/assets/${encodePathSegments(relativePath)}`;
38723
38971
  }
38724
38972
  for (let index = 0; index < rootDirectories.length; index++) {
38725
38973
  if (isPathWithinRoot(rootDirectories[index], filePath)) {
38726
- const relativePath = path25.relative(rootDirectories[index], filePath).split(path25.sep).join("/");
38974
+ const relativePath = path26.relative(rootDirectories[index], filePath).split(path26.sep).join("/");
38727
38975
  const rootHint = rootDirectories.length > 1 ? `?root=${index}` : "";
38728
38976
  return `/files/${encodePathSegments(relativePath)}${rootHint}`;
38729
38977
  }
38730
38978
  }
38979
+ if (/^\/(?:files|assets)\//.test(filePath)) {
38980
+ return filePath;
38981
+ }
38731
38982
  return (0, import_url2.pathToFileURL)(filePath).href;
38732
38983
  });
38733
38984
  function rootIndexOf(absolutePath) {
38734
- const resolved = path25.resolve(absolutePath);
38985
+ const resolved = path26.resolve(absolutePath);
38735
38986
  return rootDirectories.findIndex(
38736
38987
  (root) => isPathWithinRoot(root, resolved)
38737
38988
  );
@@ -38808,7 +39059,7 @@ async function startServeServer(options) {
38808
39059
  });
38809
39060
  }
38810
39061
  function assertFileWithinRoots(absolutePath) {
38811
- const resolved = path25.resolve(absolutePath);
39062
+ const resolved = path26.resolve(absolutePath);
38812
39063
  return rootIndexOf(resolved) === -1 ? null : resolved;
38813
39064
  }
38814
39065
  async function readJSONBody(request) {
@@ -39054,7 +39305,7 @@ async function startServeServer(options) {
39054
39305
  sse.broadcast({
39055
39306
  type: "notification",
39056
39307
  level: "info",
39057
- message: `Exported ${path25.basename(sourceUri)} to ${dest}`
39308
+ message: `Exported ${path26.basename(sourceUri)} to ${dest}`
39058
39309
  });
39059
39310
  } catch (error) {
39060
39311
  console.error(`crossnote serve: ${command} failed:`, error);
@@ -39239,7 +39490,7 @@ async function startServeServer(options) {
39239
39490
  });
39240
39491
  const data = constructGraphView(graphNotebook);
39241
39492
  const rootIndex = rootIndexOf(file);
39242
- const relativePath = rootIndex === -1 ? "" : path25.relative(rootDirectories[rootIndex], file).split(path25.sep).join("/");
39493
+ const relativePath = rootIndex === -1 ? "" : path26.relative(rootDirectories[rootIndex], file).split(path26.sep).join("/");
39243
39494
  sendJSON(response, 200, { data, activeFilePath: relativePath });
39244
39495
  } catch (error) {
39245
39496
  console.error("crossnote serve: failed to build graph data:", error);
@@ -39330,7 +39581,7 @@ async function startServeServer(options) {
39330
39581
  watchers.forEach((watcher) => watcher.close());
39331
39582
  sse.dispose();
39332
39583
  await new Promise(
39333
- (resolve20, reject) => server.close((error) => error ? reject(error) : resolve20())
39584
+ (resolve21, reject) => server.close((error) => error ? reject(error) : resolve21())
39334
39585
  );
39335
39586
  }
39336
39587
  };
@@ -39399,7 +39650,7 @@ function isAllowedOrigin(originHeader, bindHost, port) {
39399
39650
  return isAllowedRequestHost(origin.host, bindHost, port);
39400
39651
  }
39401
39652
  function listenWithFallback(server, host, port) {
39402
- return new Promise((resolve20, reject) => {
39653
+ return new Promise((resolve21, reject) => {
39403
39654
  const tryPort = (candidate, remainingAttempts) => {
39404
39655
  const onError = (error) => {
39405
39656
  if (error.code === "EADDRINUSE" && remainingAttempts > 0 && candidate !== 0) {
@@ -39416,7 +39667,7 @@ function listenWithFallback(server, host, port) {
39416
39667
  reject(new Error("failed to bind server"));
39417
39668
  return;
39418
39669
  }
39419
- resolve20(address.port);
39670
+ resolve21(address.port);
39420
39671
  });
39421
39672
  };
39422
39673
  tryPort(port, port === 3e3 ? 20 : 0);
@@ -39507,7 +39758,7 @@ function parseCommandLine(argv, spec) {
39507
39758
  console.error(`Unknown option: ${arg}`);
39508
39759
  return null;
39509
39760
  }
39510
- directories.push(path26.resolve(process.cwd(), arg));
39761
+ directories.push(path27.resolve(process.cwd(), arg));
39511
39762
  i += 1;
39512
39763
  }
39513
39764
  return { values, directories };
@@ -39609,7 +39860,7 @@ async function serve(argv) {
39609
39860
  // The CLI bundle lives in <package>/out/cli, so the build directory with
39610
39861
  // webview/, dependencies/ and styles/ is one level up unless a host that
39611
39862
  // bundles the CLI elsewhere passes its own copy via --build-dir.
39612
- crossnoteBuildDirectory: parsed.buildDirectory ?? path26.resolve(__dirname, "../")
39863
+ crossnoteBuildDirectory: parsed.buildDirectory ?? path27.resolve(__dirname, "../")
39613
39864
  });
39614
39865
  if (parsed.json) {
39615
39866
  console.log(
@@ -39658,17 +39909,17 @@ async function buildWikiCommand(argv) {
39658
39909
  process.exitCode = 1;
39659
39910
  return;
39660
39911
  }
39661
- const outputPath = path26.resolve(
39912
+ const outputPath = path27.resolve(
39662
39913
  process.cwd(),
39663
39914
  parsed.output ?? "./index.html"
39664
39915
  );
39665
- await fs22.promises.mkdir(path26.dirname(outputPath), { recursive: true });
39916
+ await fs22.promises.mkdir(path27.dirname(outputPath), { recursive: true });
39666
39917
  let lastRoot = null;
39667
39918
  const result = await buildWiki({
39668
39919
  directories,
39669
39920
  vscode: parsed.vscode,
39670
39921
  vscodeSettingsPath: parsed.vscodeSettingsPath,
39671
- crossnoteBuildDirectory: parsed.buildDirectory ?? path26.resolve(__dirname, "../"),
39922
+ crossnoteBuildDirectory: parsed.buildDirectory ?? path27.resolve(__dirname, "../"),
39672
39923
  onProgress: ({ rendered, total, root }) => {
39673
39924
  if (root !== lastRoot) {
39674
39925
  if (lastRoot !== null) {