crossnote 0.9.42 → 0.9.44

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
@@ -24127,7 +24127,7 @@ function ebookConvert(src, dest, config = {}) {
24127
24127
  args.push(arg);
24128
24128
  });
24129
24129
  (0, import_mkdirp.mkdirp)(path3.dirname(dest)).then(() => {
24130
- (0, import_child_process.execFile)("ebook-convert", args, (error2) => {
24130
+ (0, import_child_process.execFile)("ebook-convert", args, { windowsHide: true }, (error2) => {
24131
24131
  if (error2) {
24132
24132
  return reject(error2.toString());
24133
24133
  } else {
@@ -24601,14 +24601,18 @@ function toSVGMarkdown(pdfFilePath, {
24601
24601
  svgDirectoryPath = SVG_DIRECTORY_PATH;
24602
24602
  }
24603
24603
  const svgFilePrefix = compute_checksum_default(pdfFilePath) + "_";
24604
- const task = (0, import_child_process2.spawn)("pdf2svg", [
24605
- pdfFilePath,
24606
- path4.resolve(
24607
- svgDirectoryPath ?? `/tmp/crossnote_pdf`,
24608
- svgFilePrefix + "%d.svg"
24609
- ),
24610
- "all"
24611
- ]);
24604
+ const task = (0, import_child_process2.spawn)(
24605
+ "pdf2svg",
24606
+ [
24607
+ pdfFilePath,
24608
+ path4.resolve(
24609
+ svgDirectoryPath ?? `/tmp/crossnote_pdf`,
24610
+ svgFilePrefix + "%d.svg"
24611
+ ),
24612
+ "all"
24613
+ ],
24614
+ { windowsHide: true }
24615
+ );
24612
24616
  const chunks = [];
24613
24617
  task.stdout.on("data", (chunk) => {
24614
24618
  chunks.push(chunk);
@@ -25168,7 +25172,15 @@ async function transformMarkdown(inputString, {
25168
25172
  }
25169
25173
  if (!inCodeBlock) {
25170
25174
  lastOpeningCodeBlockFence = currentCodeBlockFence;
25171
- } else if (lastOpeningCodeBlockFence !== null && currentCodeBlockFence.trim().length === lastOpeningCodeBlockFence.trim().length) {
25175
+ } else if (lastOpeningCodeBlockFence !== null && // A closing fence carries no info string (CommonMark). Treating
25176
+ // "```bash" as a closer desyncs this tracker from markdown-it
25177
+ // whenever markdown-it auto-closes a fence at a container
25178
+ // boundary (e.g. a list item ends while its fence is open):
25179
+ // every later bare "```" is then misread as an opener, gets
25180
+ // {data-source-line=…} appended — which makes it invalid as a
25181
+ // closer — and everything below collapses into one code block
25182
+ // (vscode-mpe#2337).
25183
+ rest.trim() === "" && currentCodeBlockFence.trim().length === lastOpeningCodeBlockFence.trim().length) {
25172
25184
  lastOpeningCodeBlockFence = null;
25173
25185
  }
25174
25186
  i = end + 1;
@@ -25940,7 +25952,8 @@ function toSVGMarkdown2(texFilePath, {
25940
25952
  }) {
25941
25953
  return new Promise((resolve21, reject) => {
25942
25954
  const task = (0, import_child_process3.spawn)(latexEngine, [texFilePath], {
25943
- cwd: path6.dirname(texFilePath)
25955
+ cwd: path6.dirname(texFilePath),
25956
+ windowsHide: true
25944
25957
  });
25945
25958
  const chunks = [];
25946
25959
  task.stdout.on("data", (chunk) => {
@@ -26078,7 +26091,10 @@ except Exception:
26078
26091
  args.push(savePath);
26079
26092
  }
26080
26093
  return await new Promise((resolve21) => {
26081
- const task = (0, import_child_process4.spawn)(cmd, args, { cwd: fileDirectoryPath });
26094
+ const task = (0, import_child_process4.spawn)(cmd, args, {
26095
+ cwd: fileDirectoryPath,
26096
+ windowsHide: true
26097
+ });
26082
26098
  if (normalizedAttributes["stdin"]) {
26083
26099
  task.stdin.write(content);
26084
26100
  }
@@ -26173,23 +26189,27 @@ var PlantUMLTask = class {
26173
26189
  });
26174
26190
  }
26175
26191
  startTask() {
26176
- this.task = (0, import_child_process5.spawn)("java", [
26177
- "-Djava.awt.headless=true",
26178
- "-Dfile.encoding=UTF-8",
26179
- "-Dplantuml.include.path=" + [
26180
- this.fileDirectoryPath
26181
- /*getExtensionConfigPath()*/
26182
- ].join(
26183
- path8.delimiter
26184
- ),
26185
- "-jar",
26186
- this.plantumlJarPath,
26187
- // '-graphvizdot', 'exe'
26188
- "-pipe",
26189
- "-tsvg",
26190
- "-charset",
26191
- "UTF-8"
26192
- ]);
26192
+ this.task = (0, import_child_process5.spawn)(
26193
+ "java",
26194
+ [
26195
+ "-Djava.awt.headless=true",
26196
+ "-Dfile.encoding=UTF-8",
26197
+ "-Dplantuml.include.path=" + [
26198
+ this.fileDirectoryPath
26199
+ /*getExtensionConfigPath()*/
26200
+ ].join(
26201
+ path8.delimiter
26202
+ ),
26203
+ "-jar",
26204
+ this.plantumlJarPath,
26205
+ // '-graphvizdot', 'exe'
26206
+ "-pipe",
26207
+ "-tsvg",
26208
+ "-charset",
26209
+ "UTF-8"
26210
+ ],
26211
+ { windowsHide: true }
26212
+ );
26193
26213
  this.task.stdout.on("data", (chunk) => {
26194
26214
  let data = chunk.toString();
26195
26215
  this.chunks += data;
@@ -26344,7 +26364,7 @@ async function svgElementToPNGFile(svgElement, pngFilePath, imageMagickPath = ""
26344
26364
  const args = [info.path, pngFilePath];
26345
26365
  try {
26346
26366
  if (imageMagickPath && imageMagickPath.length) {
26347
- await (0, import_child_process6.execFileSync)(imageMagickPath, args);
26367
+ await (0, import_child_process6.execFileSync)(imageMagickPath, args, { windowsHide: true });
26348
26368
  } else {
26349
26369
  await import_imagemagick_cli.default.exec(`convert ${args.join(" ")}`);
26350
26370
  }
@@ -26385,6 +26405,9 @@ async function mermaidToPNG(mermaidCode, pngFilePath, projectDirectoryPath, them
26385
26405
  ],
26386
26406
  {
26387
26407
  cwd: projectDirectoryPath,
26408
+ // Without this, the `cmd.exe` wrapper cross-spawn uses on Windows
26409
+ // flashes a console window per diagram (CREATE_NO_WINDOW).
26410
+ windowsHide: true,
26388
26411
  // Match the old `execFileSync` behavior: the CLI's errors stream to
26389
26412
  // our stderr; neither stream is read here.
26390
26413
  stdio: ["ignore", "ignore", "inherit"]
@@ -26441,6 +26464,8 @@ async function render3(wavedromCode, projectDirectoryPath) {
26441
26464
  try {
26442
26465
  const result = import_cross_spawn2.default.sync("npx", ["wavedrom-cli", "-i", info.path], {
26443
26466
  cwd: projectDirectoryPath,
26467
+ // Hide the `cmd.exe` wrapper window cross-spawn uses on Windows.
26468
+ windowsHide: true,
26444
26469
  // stdout carries the SVG; stderr streams to our console like the old
26445
26470
  // `execFileSync` call did.
26446
26471
  stdio: ["ignore", "pipe", "inherit"]
@@ -26714,7 +26739,9 @@ ${error}
26714
26739
  content,
26715
26740
  pngFilePath,
26716
26741
  projectDirectoryPath,
26717
- notebook.config.mermaidTheme
26742
+ // An explicit mermaidConfig.theme (config script) wins, same as
26743
+ // in the preview init script.
26744
+ notebook.config.mermaidConfig?.theme || notebook.config.mermaidTheme
26718
26745
  );
26719
26746
  let displayPNGFilePath;
26720
26747
  if (useRelativeFilePath) {
@@ -27344,6 +27371,10 @@ async function pandocConvert(text, {
27344
27371
  codeChunksData,
27345
27372
  graphsCache,
27346
27373
  addOptionsStr: true,
27374
+ // The cache-busting `?0.5319…` query suffix is a webview device; pandoc
27375
+ // resolves image paths literally, so `assets/x.png?0.53…` is a missing
27376
+ // file and the image is dropped from the output (vscode-mpe#2350).
27377
+ cacheBust: false,
27347
27378
  notebook
27348
27379
  });
27349
27380
  await mkdirp3.sync(path11.dirname(outputFilePath));
@@ -27351,7 +27382,7 @@ async function pandocConvert(text, {
27351
27382
  const program = (0, import_child_process7.execFile)(
27352
27383
  notebook.config.pandocPath,
27353
27384
  args,
27354
- { cwd: fileDirectoryPath },
27385
+ { cwd: fileDirectoryPath, windowsHide: true },
27355
27386
  (error) => {
27356
27387
  if (error) {
27357
27388
  return reject(error.toString());
@@ -27371,6 +27402,7 @@ function princeConvert(src, dest) {
27371
27402
  (0, import_child_process8.execFile)(
27372
27403
  "prince",
27373
27404
  [src, "--javascript", "-o", dest],
27405
+ { windowsHide: true },
27374
27406
  (error) => {
27375
27407
  if (error) {
27376
27408
  let errorMessage = error.toString();
@@ -30856,6 +30888,24 @@ var html5_embed_default = (md, notebook) => {
30856
30888
  };
30857
30889
 
30858
30890
  // src/custom-markdown-it-features/math.ts
30891
+ var ENDS_WITH_WORD_CHAR = /[\p{L}\p{M}\p{N}]$/u;
30892
+ var TEX_START = /^[\^_\\{]/;
30893
+ var AMOUNT = /^(?:\d|\s\d)/;
30894
+ var TEX_CHARS = /[\\^_{}=+\-*/<>]/;
30895
+ var SPACE = /\s/;
30896
+ function isDollarMathSpan(src, open2, close) {
30897
+ if (ENDS_WITH_WORD_CHAR.test(src.slice(Math.max(0, open2 - 2), open2)) && !TEX_START.test(src.slice(open2 + 1, open2 + 2))) {
30898
+ return false;
30899
+ }
30900
+ const content = src.slice(open2 + 1, close);
30901
+ if (AMOUNT.test(content) && SPACE.test(content) && !TEX_CHARS.test(content)) {
30902
+ return false;
30903
+ }
30904
+ if (SPACE.test(src.charAt(close - 1))) {
30905
+ return false;
30906
+ }
30907
+ return !AMOUNT.test(src.slice(close + 1, close + 3));
30908
+ }
30859
30909
  var math_default = (md, notebook) => {
30860
30910
  md.block.ruler.before(
30861
30911
  "lheading",
@@ -30969,6 +31019,9 @@ var math_default = (md, notebook) => {
30969
31019
  } else {
30970
31020
  return false;
30971
31021
  }
31022
+ if (openTag === "$" && closeTag === "$" && !isDollarMathSpan(state.src, state.pos, end)) {
31023
+ return false;
31024
+ }
30972
31025
  if (content && !silent) {
30973
31026
  const token = state.push("math", "", 0);
30974
31027
  token.content = content.trim();
@@ -31089,6 +31142,11 @@ function replaceDelimited(html, openTag, closeTag, displayMode, notebook) {
31089
31142
  i += openTag.length;
31090
31143
  continue;
31091
31144
  }
31145
+ if (openTag === "$" && closeTag === "$" && !isDollarMathSpan(html, i, end)) {
31146
+ out += html[i];
31147
+ i += 1;
31148
+ continue;
31149
+ }
31092
31150
  const content = html.slice(i + openTag.length, end).trim();
31093
31151
  out += parse_math_default({
31094
31152
  content,
@@ -31124,6 +31182,9 @@ var tag_default = (md, notebook) => {
31124
31182
  if (!notebook.config.enableTagSyntax || state.src.charCodeAt(state.pos) !== 35) {
31125
31183
  return false;
31126
31184
  }
31185
+ if (state.linkLevel > 0) {
31186
+ return false;
31187
+ }
31127
31188
  if (state.pos > 0) {
31128
31189
  const prev = state.src.charCodeAt(state.pos - 1);
31129
31190
  if (prev === 47 || prev === 38 || prev === 63 || prev === 92 || prev >= 48 && prev <= 57 || prev >= 65 && prev <= 90 || prev >= 97 && prev <= 122 || prev === 95 || prev === 45) {
@@ -32076,6 +32137,15 @@ function isSamePath(a, b) {
32076
32137
  }
32077
32138
  return a === b;
32078
32139
  }
32140
+ function normalizeNotebookConfig(config) {
32141
+ if (config.markdownParser === "markdown_yo") {
32142
+ return { ...config, markdownParser: "markdown-yo" };
32143
+ }
32144
+ return config;
32145
+ }
32146
+ function parseNotebookPath(notebookPath) {
32147
+ return /^[A-Za-z]:[\\/]/.test(notebookPath) ? import_vscode_uri.URI.file(notebookPath) : import_vscode_uri.URI.parse(notebookPath);
32148
+ }
32079
32149
  var Notebook = class _Notebook {
32080
32150
  constructor() {
32081
32151
  /**
@@ -32159,12 +32229,12 @@ var Notebook = class _Notebook {
32159
32229
  this.processedMtimes = /* @__PURE__ */ new Map();
32160
32230
  this.search = new Search();
32161
32231
  /**
32162
- * Optional markdown_yo WASM renderer.
32163
- * Used for HTML rendering when `markdownParser === 'markdown_yo'`.
32232
+ * Optional markdown-yo WASM renderer.
32233
+ * Used for HTML rendering when `markdownParser === 'markdown-yo'`.
32164
32234
  */
32165
32235
  this.markdownYoRenderer = null;
32166
32236
  /**
32167
- * Tracks in-flight markdown_yo initialization to avoid duplicate loads.
32237
+ * Tracks in-flight markdown-yo initialization to avoid duplicate loads.
32168
32238
  */
32169
32239
  this.markdownYoRendererPromise = null;
32170
32240
  /**
@@ -32187,7 +32257,7 @@ var Notebook = class _Notebook {
32187
32257
  config = {},
32188
32258
  fs: fs23
32189
32259
  }) {
32190
- const uri = import_vscode_uri.URI.parse(notebookPath);
32260
+ const uri = parseNotebookPath(notebookPath);
32191
32261
  if (!path15.isAbsolute(uri.fsPath) || uri.path.startsWith("/./")) {
32192
32262
  throw new Error(
32193
32263
  `\`notebookPath\`: "${notebookPath}" must be an absolute path`
@@ -32197,7 +32267,7 @@ var Notebook = class _Notebook {
32197
32267
  this.initFs(fs23);
32198
32268
  await this.initConfig(config);
32199
32269
  this.md = this.initMarkdownIt();
32200
- if (this.config.markdownParser === "markdown_yo") {
32270
+ if (this.config.markdownParser === "markdown-yo") {
32201
32271
  await this.initMarkdownYo();
32202
32272
  }
32203
32273
  this.updateConfig({});
@@ -32212,11 +32282,11 @@ var Notebook = class _Notebook {
32212
32282
  path15.join(this.notebookPath.fsPath, "./.crossnote"),
32213
32283
  this.fs
32214
32284
  );
32215
- this.config = {
32285
+ this.config = normalizeNotebookConfig({
32216
32286
  ...getDefaultNotebookConfig(),
32217
32287
  ...extraConfig,
32218
32288
  ...config
32219
- };
32289
+ });
32220
32290
  }
32221
32291
  initMarkdownIt(options) {
32222
32292
  const md = new import_markdown_it.default(options ?? defaultMarkdownItConfig);
@@ -32276,7 +32346,7 @@ var Notebook = class _Notebook {
32276
32346
  }
32277
32347
  }
32278
32348
  /**
32279
- * Initialize the markdown_yo WASM renderer.
32349
+ * Initialize the markdown-yo WASM renderer.
32280
32350
  */
32281
32351
  async initMarkdownYo() {
32282
32352
  if (this.markdownYoRendererPromise) {
@@ -32288,15 +32358,15 @@ var Notebook = class _Notebook {
32288
32358
  }
32289
32359
  this.markdownYoRendererPromise = (async () => {
32290
32360
  try {
32291
- const { createRenderer } = await import("markdown_yo");
32361
+ const { createRenderer } = await import("@shd101wyy/markdown-yo");
32292
32362
  const renderer = await createRenderer();
32293
- if (this.config.markdownParser === "markdown_yo") {
32363
+ if (this.config.markdownParser === "markdown-yo") {
32294
32364
  this.markdownYoRenderer = renderer;
32295
32365
  } else {
32296
32366
  renderer.destroy();
32297
32367
  }
32298
32368
  } catch (error) {
32299
- console.warn("Failed to load markdown_yo WASM renderer:", error);
32369
+ console.warn("Failed to load markdown-yo WASM renderer:", error);
32300
32370
  this.markdownYoRenderer = null;
32301
32371
  } finally {
32302
32372
  this.markdownYoRendererPromise = null;
@@ -32309,7 +32379,7 @@ var Notebook = class _Notebook {
32309
32379
  this.markdownYoRenderer = null;
32310
32380
  }
32311
32381
  /**
32312
- * Build markdown_yo render options from the current notebook config.
32382
+ * Build markdown-yo render options from the current notebook config.
32313
32383
  */
32314
32384
  buildMarkdownYoOptions(isForPreview) {
32315
32385
  const c = this.config;
@@ -32335,7 +32405,7 @@ var Notebook = class _Notebook {
32335
32405
  };
32336
32406
  }
32337
32407
  /**
32338
- * Convert markdown_yo RenderOptions to CLI flags for the native binary.
32408
+ * Convert markdown-yo RenderOptions to CLI flags for the native binary.
32339
32409
  */
32340
32410
  buildMarkdownYoBinaryArgs(opts) {
32341
32411
  const flags = [];
@@ -32359,11 +32429,11 @@ var Notebook = class _Notebook {
32359
32429
  return flags;
32360
32430
  }
32361
32431
  /**
32362
- * Render markdown to HTML using markdown_yo (WASM) if available,
32432
+ * Render markdown to HTML using markdown-yo (WASM) if available,
32363
32433
  * otherwise falls back to markdown-it.
32364
32434
  */
32365
32435
  renderMarkdown(markdown, options) {
32366
- if (this.config.markdownParser === "markdown_yo") {
32436
+ if (this.config.markdownParser === "markdown-yo") {
32367
32437
  const renderOpts = this.buildMarkdownYoOptions(!!options?.isForPreview);
32368
32438
  const binaryPath = this.config.markdownYoBinaryPath;
32369
32439
  let html;
@@ -32372,7 +32442,8 @@ var Notebook = class _Notebook {
32372
32442
  html = (0, import_child_process9.execFileSync)(binaryPath, args, {
32373
32443
  input: markdown,
32374
32444
  encoding: "utf8",
32375
- maxBuffer: 256 * 1024 * 1024
32445
+ maxBuffer: 256 * 1024 * 1024,
32446
+ windowsHide: true
32376
32447
  });
32377
32448
  } else if (this.markdownYoRenderer) {
32378
32449
  html = this.markdownYoRenderer.render(markdown, renderOpts);
@@ -32394,7 +32465,7 @@ var Notebook = class _Notebook {
32394
32465
  return md.render(markdown);
32395
32466
  }
32396
32467
  /**
32397
- * Post-process markdown_yo HTML output:
32468
+ * Post-process markdown-yo HTML output:
32398
32469
  * - Render math expressions with KaTeX (when mathRenderingOption is 'KaTeX')
32399
32470
  * - Append file extension to wikilink hrefs
32400
32471
  */
@@ -32436,17 +32507,17 @@ var Notebook = class _Notebook {
32436
32507
  return html;
32437
32508
  }
32438
32509
  updateConfig(config) {
32439
- this.config = {
32510
+ this.config = normalizeNotebookConfig({
32440
32511
  ...this.config,
32441
32512
  ...config
32442
- };
32513
+ });
32443
32514
  this.interpolateConfig();
32444
32515
  this.md.set({
32445
32516
  typographer: !!this.config.enableTypographer,
32446
32517
  breaks: !!this.config.breakOnSingleNewLine,
32447
32518
  linkify: !!this.config.enableLinkify
32448
32519
  });
32449
- if (this.config.markdownParser === "markdown_yo") {
32520
+ if (this.config.markdownParser === "markdown-yo") {
32450
32521
  void this.initMarkdownYo();
32451
32522
  } else {
32452
32523
  this.destroyMarkdownYo();
@@ -33949,17 +34020,19 @@ async function enhance5($) {
33949
34020
  const $col = $(col);
33950
34021
  const text = $col.text();
33951
34022
  const html = $col.html();
34023
+ const $children = $col.children();
34024
+ const isBareText = !$children.length || $children.length === 1 && $children.is("p") && !$children.children().length;
33952
34025
  if (!text.length && !html?.length) {
33953
34026
  const $prev = $col.prev();
33954
34027
  if ($prev.length) {
33955
34028
  colspans2.push([$prev, $col]);
33956
34029
  }
33957
- } else if (text.trim() === "^" && $prevRow) {
34030
+ } else if (isBareText && text.trim() === "^" && $prevRow) {
33958
34031
  const $prev = $($prevRow.children()[j]);
33959
34032
  if ($prev.length) {
33960
34033
  rowspans.push([$prev, $col]);
33961
34034
  }
33962
- } else if (text.trim() === ">") {
34035
+ } else if (isBareText && text.trim() === ">") {
33963
34036
  const $next = $col.next();
33964
34037
  if ($next.length) {
33965
34038
  colspans.push([$col, $next]);
@@ -34273,7 +34346,7 @@ async function renderD2(code, opts, fileDirectoryPath) {
34273
34346
  (0, import_child_process10.execFile)(
34274
34347
  opts.d2Path,
34275
34348
  args,
34276
- { timeout: 3e4 },
34349
+ { timeout: 3e4, windowsHide: true },
34277
34350
  (err, _stdout, stderr) => {
34278
34351
  if (err) {
34279
34352
  const wrapped = new Error(stderr || err.message);
@@ -35064,6 +35137,61 @@ function buildMathJaxConfigScript(mathJaxConfig) {
35064
35137
  })();`;
35065
35138
  }
35066
35139
 
35140
+ // src/markdown-engine/mermaid-export.ts
35141
+ function buildMermaidExportScript(config, hasZenUML) {
35142
+ return `
35143
+ // Page load and data-processed do not imply that Mermaid's layout is complete.
35144
+ window.__crossnoteMermaidExport = { status: 'pending' }
35145
+ try {
35146
+ // Disable the load listener before an external module can yield control.
35147
+ mermaid.startOnLoad = false
35148
+ // TODO: If ZenUML gets integrated into mermaid in the future,
35149
+ // we can remove the following lines.
35150
+ ${hasZenUML ? `const { default: zenuml } = await import('https://${config.jsdelivrCdnHost}/npm/@mermaid-js/mermaid-zenuml@0.1.0/dist/mermaid-zenuml.esm.min.mjs');
35151
+ await mermaid.registerExternalDiagrams([zenuml])` : ``}
35152
+
35153
+ var MERMAID_CONFIG = (${JSON.stringify(config.mermaidConfig)});
35154
+ if (typeof MERMAID_CONFIG !== 'undefined') {
35155
+ MERMAID_CONFIG.startOnLoad = false
35156
+ MERMAID_CONFIG.cloneCssStyles = false
35157
+ MERMAID_CONFIG.theme = MERMAID_CONFIG.theme || "${config.mermaidTheme}"
35158
+ }
35159
+
35160
+ mermaid.initialize(MERMAID_CONFIG || {})
35161
+ // Complete the initial pass before Reveal can start separate renders.
35162
+ await mermaid.run({
35163
+ nodes: document.querySelectorAll('div.mermaid')
35164
+ })
35165
+ if (typeof(window['Reveal']) !== 'undefined') {
35166
+ function mermaidRevealHelper(event) {
35167
+ var currentSlide = event.currentSlide
35168
+ var diagrams = currentSlide.querySelectorAll('div.mermaid')
35169
+ for (var i = 0; i < diagrams.length; i++) {
35170
+ var diagram = diagrams[i]
35171
+ if (!diagram.hasAttribute('data-processed')) {
35172
+ mermaid.init(null, diagram, ()=> {
35173
+ Reveal.slide(event.indexh, event.indexv)
35174
+ })
35175
+ }
35176
+ }
35177
+ }
35178
+ Reveal.addEventListener('slidetransitionend', mermaidRevealHelper)
35179
+ Reveal.addEventListener('ready', mermaidRevealHelper)
35180
+ }
35181
+ window.__crossnoteMermaidExport = { status: 'complete' }
35182
+ } catch (error) {
35183
+ window.__crossnoteMermaidExport = {
35184
+ status: 'error',
35185
+ message: String(error && error.message || error)
35186
+ }
35187
+ console.error(error)
35188
+ }
35189
+ `;
35190
+ }
35191
+
35192
+ // src/markdown-engine/mermaid-polyfill.ts
35193
+ var MERMAID_LEGACY_WEBVIEW_POLYFILL = `<script>if(!Object.groupBy){Object.groupBy=function(e,t){var r=Object.create(null);for(var i=0;i<e.length;i++){var k=t(e[i],i);if(typeof k!=="symbol"){k=String(k)}if(!(k in r)){r[k]=[]}r[k].push(e[i])}return r}}</script>`;
35194
+
35067
35195
  // src/renderers/wavedrom-source.ts
35068
35196
  var import_json52 = __toESM(require("json5"));
35069
35197
 
@@ -35289,7 +35417,7 @@ function pandocSupportsMathMethod(pandocPath) {
35289
35417
  (0, import_child_process11.execFile)(
35290
35418
  pandocPath,
35291
35419
  ["--version"],
35292
- { timeout: 1e4 },
35420
+ { timeout: 1e4, windowsHide: true },
35293
35421
  (error, stdout) => {
35294
35422
  resolve21(!error && pandocVersionSupportsMathMethod(String(stdout)));
35295
35423
  }
@@ -35368,6 +35496,7 @@ var MarkdownEngine = class _MarkdownEngine {
35368
35496
  generateScriptsForPreview(isForPresentation = false, yamlConfig = {}, vscodePreviewPanel = null) {
35369
35497
  let scripts = "";
35370
35498
  scripts += `<script>var exports = undefined</script>`;
35499
+ scripts += MERMAID_LEGACY_WEBVIEW_POLYFILL;
35371
35500
  scripts += `<script type="text/javascript" src="${addFileProtocol(
35372
35501
  path19.resolve(
35373
35502
  getCrossnoteBuildDirectory(),
@@ -35461,7 +35590,7 @@ var MERMAID_CONFIG = (${JSON.stringify(this.notebook.config.mermaidConfig)});
35461
35590
  if (typeof MERMAID_CONFIG !== 'undefined') {
35462
35591
  MERMAID_CONFIG.startOnLoad = false
35463
35592
  MERMAID_CONFIG.cloneCssStyles = false
35464
- MERMAID_CONFIG.theme = "${this.notebook.config.mermaidTheme}"
35593
+ MERMAID_CONFIG.theme = MERMAID_CONFIG.theme || "${this.notebook.config.mermaidTheme}"
35465
35594
  }
35466
35595
  mermaid.initialize(MERMAID_CONFIG || {})
35467
35596
  if (typeof(window['Reveal']) !== 'undefined') {
@@ -36010,7 +36139,7 @@ window["initRevealPresentation"] = async function() {
36010
36139
  if (options.offline) {
36011
36140
  mathStyle = await offlineStyle("./dependencies/katex/katex.min.css");
36012
36141
  } else {
36013
- mathStyle = `<link rel="stylesheet" href="https://${this.notebook.config.jsdelivrCdnHost}/npm/katex@0.16.47/dist/katex.min.css">`;
36142
+ mathStyle = `<link rel="stylesheet" href="https://${this.notebook.config.jsdelivrCdnHost}/npm/katex@0.19.1/dist/katex.min.css">`;
36014
36143
  }
36015
36144
  } else {
36016
36145
  mathStyle = "";
@@ -36028,51 +36157,18 @@ window["initRevealPresentation"] = async function() {
36028
36157
  let mermaidScript = "";
36029
36158
  let mermaidInitScript = "";
36030
36159
  if (html.indexOf(' class="mermaid') >= 0) {
36160
+ mermaidScript = MERMAID_LEGACY_WEBVIEW_POLYFILL;
36031
36161
  if (options.offline) {
36032
- mermaidScript = await offlineScript(
36162
+ mermaidScript += await offlineScript(
36033
36163
  "./dependencies/mermaid/mermaid.min.js"
36034
36164
  );
36035
36165
  } else {
36036
- mermaidScript = `<script src="https://${this.notebook.config.jsdelivrCdnHost}/npm/mermaid@12.0.0/dist/mermaid.min.js"></script>`;
36166
+ mermaidScript += `<script src="https://${this.notebook.config.jsdelivrCdnHost}/npm/mermaid@12.3.0/dist/mermaid.min.js"></script>`;
36037
36167
  }
36038
- mermaidInitScript += `<script type="module">
36039
- // TODO: If ZenUML gets integrated into mermaid in the future,
36040
- // we can remove the following lines.
36041
- ${html.match(/zenuml/i) ? `import zenuml from 'https://${this.notebook.config.jsdelivrCdnHost}/npm/@mermaid-js/mermaid-zenuml@0.1.0/dist/mermaid-zenuml.esm.min.mjs';
36042
- await mermaid.registerExternalDiagrams([zenuml])` : ``}
36043
-
36044
- var MERMAID_CONFIG = (${JSON.stringify(this.notebook.config.mermaidConfig)});
36045
- if (typeof MERMAID_CONFIG !== 'undefined') {
36046
- MERMAID_CONFIG.startOnLoad = false
36047
- MERMAID_CONFIG.cloneCssStyles = false
36048
- MERMAID_CONFIG.theme = "${this.notebook.config.mermaidTheme}"
36049
- }
36050
-
36051
- mermaid.initialize(MERMAID_CONFIG || {})
36052
- if (typeof(window['Reveal']) !== 'undefined') {
36053
- function mermaidRevealHelper(event) {
36054
- var currentSlide = event.currentSlide
36055
- var diagrams = currentSlide.querySelectorAll('div.mermaid')
36056
- for (var i = 0; i < diagrams.length; i++) {
36057
- var diagram = diagrams[i]
36058
- if (!diagram.hasAttribute('data-processed')) {
36059
- mermaid.init(null, diagram, ()=> {
36060
- Reveal.slide(event.indexh, event.indexv)
36061
- })
36062
- }
36063
- }
36064
- }
36065
- Reveal.addEventListener('slidetransitionend', mermaidRevealHelper)
36066
- Reveal.addEventListener('ready', mermaidRevealHelper)
36067
- await mermaid.run({
36068
- nodes: document.querySelectorAll('div.mermaid')
36069
- })
36070
- } else {
36071
- await mermaid.run({
36072
- nodes: document.querySelectorAll('div.mermaid')
36073
- })
36074
- }
36075
- </script>`;
36168
+ mermaidInitScript = `<script type="module">${buildMermaidExportScript(
36169
+ this.notebook.config,
36170
+ /zenuml/i.test(html)
36171
+ )}</script>`;
36076
36172
  }
36077
36173
  let wavedromScript = ``;
36078
36174
  let wavedromInitScript = ``;
@@ -36445,7 +36541,13 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36445
36541
  isForPrint: false,
36446
36542
  isForPrince: false,
36447
36543
  offline: true,
36448
- embedLocalImages: false,
36544
+ // Embed assets and images: the temp document lives outside the
36545
+ // crossnote build directory, and Safari/Firefox block cross-tree
36546
+ // `file://` subresources (vscode-mpe#2452 — KaTeX rendered twice
36547
+ // because its CSS never loaded). Chrome loads them either way.
36548
+ embedOfflineAssets: true,
36549
+ embedLocalImages: true,
36550
+ embedSVG: true,
36449
36551
  isForBrowser: true
36450
36552
  });
36451
36553
  const info = await tempOpen({
@@ -36579,47 +36681,66 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36579
36681
  executablePath,
36580
36682
  headless: true
36581
36683
  });
36582
- const info = await tempOpen({
36583
- prefix: "crossnote",
36584
- suffix: ".html"
36585
- });
36586
- fs14.writeFileSync(info.fd, html);
36587
- const page = await browser.newPage();
36588
- const loadPath = toFileURL(info.path) + (yamlConfig["isPresentationMode"] ? "?print-pdf" : "");
36589
- await page.goto(loadPath);
36590
- const chromeConfig = yamlConfig["chrome"] && typeof yamlConfig["chrome"] === "object" && !Array.isArray(yamlConfig["chrome"]) ? yamlConfig["chrome"] : void 0;
36591
- const puppeteerConfig2 = yamlConfig["puppeteer"] && typeof yamlConfig["puppeteer"] === "object" && !Array.isArray(yamlConfig["puppeteer"]) ? yamlConfig["puppeteer"] : void 0;
36592
- const puppeteerConfig = {
36593
- path: dest,
36594
- ...yamlConfig["isPresentationMode"] ? {} : { margin: { top: "1cm", bottom: "1cm", left: "1cm", right: "1cm" } },
36595
- printBackground: this.notebook.config.printBackground,
36596
- ...chromeConfig || puppeteerConfig2 || {}
36597
- };
36598
- let timeout = 0;
36599
- if (chromeConfig && chromeConfig["timeout"]) {
36600
- timeout = chromeConfig["timeout"];
36601
- } else if (puppeteerConfig2 && puppeteerConfig2["timeout"]) {
36602
- timeout = puppeteerConfig2["timeout"];
36603
- }
36604
- if (timeout && typeof timeout === "number") {
36605
- await new Promise((resolve21) => setTimeout(resolve21, timeout));
36606
- } else if (this.notebook.config.puppeteerWaitForTimeout && this.notebook.config.puppeteerWaitForTimeout > 0) {
36607
- await new Promise(
36608
- (resolve21) => setTimeout(resolve21, this.notebook.config.puppeteerWaitForTimeout)
36684
+ try {
36685
+ const info = await tempOpen({
36686
+ prefix: "crossnote",
36687
+ suffix: ".html"
36688
+ });
36689
+ fs14.writeFileSync(info.fd, html);
36690
+ const page = await browser.newPage();
36691
+ const loadPath = toFileURL(info.path) + (yamlConfig["isPresentationMode"] ? "?print-pdf" : "");
36692
+ await page.goto(loadPath);
36693
+ await page.waitForFunction(
36694
+ () => {
36695
+ const state = window.__crossnoteMermaidExport;
36696
+ return !document.querySelector("div.mermaid") || state?.status === "complete" || state?.status === "error";
36697
+ },
36698
+ { timeout: 3e4 }
36609
36699
  );
36700
+ const mermaidError = await page.evaluate(() => {
36701
+ const state = window.__crossnoteMermaidExport;
36702
+ return state?.status === "error" ? state.message : void 0;
36703
+ });
36704
+ if (mermaidError !== void 0) {
36705
+ throw new Error("Mermaid rendering failed: " + mermaidError);
36706
+ }
36707
+ const chromeConfig = yamlConfig["chrome"] && typeof yamlConfig["chrome"] === "object" && !Array.isArray(yamlConfig["chrome"]) ? yamlConfig["chrome"] : void 0;
36708
+ const puppeteerConfig2 = yamlConfig["puppeteer"] && typeof yamlConfig["puppeteer"] === "object" && !Array.isArray(yamlConfig["puppeteer"]) ? yamlConfig["puppeteer"] : void 0;
36709
+ const puppeteerConfig = {
36710
+ path: dest,
36711
+ ...yamlConfig["isPresentationMode"] ? {} : {
36712
+ margin: { top: "1cm", bottom: "1cm", left: "1cm", right: "1cm" }
36713
+ },
36714
+ printBackground: this.notebook.config.printBackground,
36715
+ ...chromeConfig || puppeteerConfig2 || {}
36716
+ };
36717
+ let timeout = 0;
36718
+ if (chromeConfig && chromeConfig["timeout"]) {
36719
+ timeout = chromeConfig["timeout"];
36720
+ } else if (puppeteerConfig2 && puppeteerConfig2["timeout"]) {
36721
+ timeout = puppeteerConfig2["timeout"];
36722
+ }
36723
+ if (timeout && typeof timeout === "number") {
36724
+ await new Promise((resolve21) => setTimeout(resolve21, timeout));
36725
+ } else if (this.notebook.config.puppeteerWaitForTimeout && this.notebook.config.puppeteerWaitForTimeout > 0) {
36726
+ await new Promise(
36727
+ (resolve21) => setTimeout(resolve21, this.notebook.config.puppeteerWaitForTimeout)
36728
+ );
36729
+ }
36730
+ if (fileType === "pdf") {
36731
+ await page.pdf(puppeteerConfig);
36732
+ } else {
36733
+ puppeteerConfig["fullPage"] = true;
36734
+ await page.screenshot(puppeteerConfig);
36735
+ }
36736
+ if (openFileAfterGeneration) {
36737
+ openFile(dest);
36738
+ }
36739
+ return dest;
36740
+ } finally {
36741
+ browser.close().catch(() => {
36742
+ });
36610
36743
  }
36611
- if (fileType === "pdf") {
36612
- await page.pdf(puppeteerConfig);
36613
- } else {
36614
- puppeteerConfig["fullPage"] = true;
36615
- await page.screenshot(puppeteerConfig);
36616
- }
36617
- browser.close().catch(() => {
36618
- });
36619
- if (openFileAfterGeneration) {
36620
- openFile(dest);
36621
- }
36622
- return dest;
36623
36744
  }
36624
36745
  /**
36625
36746
  * prince pdf file export
@@ -36851,7 +36972,7 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36851
36972
  let mathStyle = "";
36852
36973
  if (outputHTML.indexOf('class="katex"') > 0) {
36853
36974
  if (path19.extname(dest) === ".html" && ebookConfig["html"] && ebookConfig["html"]["cdn"]) {
36854
- mathStyle = `<link rel="stylesheet" href="https://${this.notebook.config.jsdelivrCdnHost}/npm/katex@0.16.47/dist/katex.min.css">`;
36975
+ mathStyle = `<link rel="stylesheet" href="https://${this.notebook.config.jsdelivrCdnHost}/npm/katex@0.19.1/dist/katex.min.css">`;
36855
36976
  } else {
36856
36977
  mathStyle = `<link rel="stylesheet" href="${toFileURL(
36857
36978
  path19.resolve(
@@ -37479,7 +37600,11 @@ sidebarTOCBtn.addEventListener('click', function(event) {
37479
37600
  const program = (0, import_child_process11.execFile)(
37480
37601
  pandocPath,
37481
37602
  args,
37482
- { cwd: this.fileDirectoryPath, maxBuffer: Infinity },
37603
+ {
37604
+ cwd: this.fileDirectoryPath,
37605
+ maxBuffer: Infinity,
37606
+ windowsHide: true
37607
+ },
37483
37608
  (error, stdout, stderr) => {
37484
37609
  if (error) {
37485
37610
  return reject(error);
@@ -37606,7 +37731,7 @@ Check "http://pandoc.org/installing.html" website.`;
37606
37731
  );
37607
37732
  }
37608
37733
  const $ = cheerio3.load(html);
37609
- if (this.notebook.config.markdownParser === "markdown_yo") {
37734
+ if (this.notebook.config.markdownParser === "markdown-yo") {
37610
37735
  normalizeMarkdownYoCodeBlocks($);
37611
37736
  normalizeMarkdownYoHeadings($);
37612
37737
  }