@oml/markdown 0.16.2 → 0.16.4

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.
@@ -70733,7 +70733,16 @@ ${serialized}`;
70733
70733
  return href;
70734
70734
  }
70735
70735
  try {
70736
- return new URL(href, window.location.href).toString();
70736
+ const params = new URLSearchParams(window.location.search);
70737
+ const isPreviewFrame = params.get("_oml_preview") === "1";
70738
+ let baseHref = document.baseURI || window.location.href;
70739
+ if (isPreviewFrame && window.parent && window.parent !== window) {
70740
+ try {
70741
+ baseHref = window.parent.document.baseURI || window.parent.location.href || baseHref;
70742
+ } catch {
70743
+ }
70744
+ }
70745
+ return new URL(href, baseHref).toString();
70737
70746
  } catch {
70738
70747
  return href;
70739
70748
  }
@@ -75737,7 +75746,12 @@ ${serialized}`;
75737
75746
  if (!href) {
75738
75747
  return;
75739
75748
  }
75740
- window.location.assign(href);
75749
+ const targetHref = new URL(href, document.baseURI).toString();
75750
+ if (window.parent && window.parent !== window) {
75751
+ window.parent.postMessage({ type: "oml-md:navigate", href: targetHref }, "*");
75752
+ } else {
75753
+ window.location.assign(targetHref);
75754
+ }
75741
75755
  });
75742
75756
  }
75743
75757
  function isHoverPreviewEnabled(event) {
@@ -75815,7 +75829,7 @@ ${serialized}`;
75815
75829
  }
75816
75830
  const card = ensureWikilinkPreviewCard();
75817
75831
  const iframe = document.createElement("iframe");
75818
- const iframeSrc = new URL(href, window.location.href);
75832
+ const iframeSrc = new URL(href, document.baseURI);
75819
75833
  iframeSrc.searchParams.set("_oml_preview", "1");
75820
75834
  iframe.src = iframeSrc.toString();
75821
75835
  iframe.style.width = "100%";
@@ -76072,6 +76086,23 @@ ${serialized}`;
76072
76086
  function getScriptSparqlCache() {
76073
76087
  return parseJsonNode("oml-md-script-sparql-cache", {});
76074
76088
  }
76089
+ function getScriptIncludeCache() {
76090
+ return parseJsonNode("oml-md-script-include-cache", {});
76091
+ }
76092
+ function extractIncludePaths(code2) {
76093
+ const re = /\binclude\s*\(\s*(?:"((?:[^"\\]|\\[\s\S])*)"|'((?:[^'\\]|\\[\s\S])*)'|`((?:[^`\\]|\\[\s\S])*)`)\s*\)/g;
76094
+ const seen = /* @__PURE__ */ new Set();
76095
+ let m;
76096
+ while ((m = re.exec(code2)) !== null) {
76097
+ seen.add(m[1] ?? m[2] ?? m[3]);
76098
+ }
76099
+ return [...seen];
76100
+ }
76101
+ function buildIncludePreamble(code2, cache5) {
76102
+ const paths = extractIncludePaths(code2);
76103
+ const parts = paths.map((p) => cache5[p] ?? "").filter(Boolean);
76104
+ return parts.length > 0 ? parts.join("\n") + "\n" : "";
76105
+ }
76075
76106
  var PYTHON_PANEL_CACHE_STORAGE_KEY = "oml-md-python-panel-cache-v2";
76076
76107
  var R_PANEL_CACHE_STORAGE_KEY = "oml-md-r-panel-cache-v2";
76077
76108
  var JS_PANEL_CACHE_STORAGE_KEY = "oml-md-js-panel-cache-v2";
@@ -76287,7 +76318,9 @@ ${serialized}`;
76287
76318
  const table2 = (result) => sparqlResultToHtmlTable(result);
76288
76319
  const load = async (url) => loadScript(url);
76289
76320
  const update = async (_ops) => ({});
76290
- const interactive = (html2, _ops) => html2;
76321
+ const interactive = (_html, _ops) => "";
76322
+ const includeCache = getScriptIncludeCache();
76323
+ const includePreamble = buildIncludePreamble(code2, includeCache);
76291
76324
  const savedLog = console.log;
76292
76325
  const savedWarn = console.warn;
76293
76326
  const savedError = console.error;
@@ -76307,8 +76340,11 @@ ${serialized}`;
76307
76340
  try {
76308
76341
  const AsyncFunction = Object.getPrototypeOf(async function() {
76309
76342
  }).constructor;
76310
- const fn = new AsyncFunction("display", "query", "table", "load", "update", "interactive", code2);
76311
- await fn(display, query, table2, load, update, interactive);
76343
+ const include = async (_path) => {
76344
+ };
76345
+ const finalCode = includePreamble ? includePreamble + code2 : code2;
76346
+ const fn = new AsyncFunction("display", "query", "table", "load", "update", "interactive", "include", finalCode);
76347
+ await fn(display, query, table2, load, update, interactive, include);
76312
76348
  clearStatus();
76313
76349
  return {};
76314
76350
  } catch (error2) {
@@ -76348,7 +76384,7 @@ ${serialized}`;
76348
76384
  continue;
76349
76385
  }
76350
76386
  appendResult(panel, result);
76351
- if (!result.error) {
76387
+ if (!result.error && !panel.querySelector(".oml-md-js-empty")) {
76352
76388
  rememberJsPanelCache(cacheKey, panel.innerHTML);
76353
76389
  }
76354
76390
  }
@@ -76467,8 +76503,11 @@ def table(data):
76467
76503
  async def update(_operations):
76468
76504
  return {}
76469
76505
 
76470
- def interactive(html, _operations):
76471
- return str(html)
76506
+ def interactive(_html, _operations):
76507
+ return ''
76508
+
76509
+ def include(_path):
76510
+ pass
76472
76511
 
76473
76512
  async def js(code, **kwargs):
76474
76513
  code = code.replace('{{', '').replace('}}', '')
@@ -76540,8 +76579,9 @@ async def js(code, **kwargs):
76540
76579
  pyodide.setStdout({ batched: appendText });
76541
76580
  pyodide.setStderr({ batched: () => {
76542
76581
  } });
76582
+ const preamble = buildIncludePreamble(code2, getScriptIncludeCache());
76543
76583
  try {
76544
- await pyodide.runPythonAsync(code2);
76584
+ await pyodide.runPythonAsync(preamble ? preamble + code2 : code2);
76545
76585
  clearStatus();
76546
76586
  return {};
76547
76587
  } catch (error2) {
@@ -76620,7 +76660,8 @@ load <- function(pkg) {
76620
76660
  if (!requireNamespace(pkg, quietly=TRUE)) { webr::install(pkg) }
76621
76661
  library(pkg, character.only=TRUE)
76622
76662
  }
76623
- interactive <- function(html, operations) as.character(html)
76663
+ interactive <- function(html, operations) ''
76664
+ include <- function(path) invisible(NULL)
76624
76665
  js <- function(code, ...) {
76625
76666
  args <- list(...)
76626
76667
  code <- gsub('{{', '', code, fixed=TRUE)
@@ -76739,11 +76780,15 @@ ${colDefs},
76739
76780
  clearStatus();
76740
76781
  return { error: `R bootstrap failed: ${e instanceof Error ? e.message : String(e)}` };
76741
76782
  }
76783
+ const includePreamble = buildIncludePreamble(code2, getScriptIncludeCache());
76742
76784
  let finalCode = code2;
76743
76785
  if (prefetchResults.length > 0) {
76744
76786
  const queryMap = new Map(prefetchResults.map((r) => [r.sparql, r.varName]));
76745
76787
  finalCode = prefetchResults.map((r) => r.preamble).join("\n") + "\n" + rewriteRQueryCalls(code2, queryMap);
76746
76788
  }
76789
+ if (includePreamble) {
76790
+ finalCode = includePreamble + finalCode;
76791
+ }
76747
76792
  try {
76748
76793
  await webR.evalRVoid(
76749
76794
  ".oml_buf_ <- character(0)\ntryCatch({\n" + finalCode + '\n}, error = function(e) { .oml_buf_ <<- c(.oml_buf_, paste0("Error: ", conditionMessage(e))) })\n'