@oml/markdown 0.16.1 → 0.16.3

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
  }
@@ -75574,6 +75583,20 @@ ${serialized}`;
75574
75583
  }
75575
75584
 
75576
75585
  // src/static/browser-runtime.ts
75586
+ function expandWikilinksInHtml(html2) {
75587
+ return html2.replace(/(<[^>]*>)|\[\[([^\]]+)\]\]/g, (match2, tag, iri) => {
75588
+ if (tag !== void 0) {
75589
+ if (/^<[!?]/.test(tag) || /^<\/?[a-zA-Z][a-zA-Z0-9-]*(?:[\s>\/]|$)/.test(tag)) return tag;
75590
+ return tag.replace(/</g, "&lt;").replace(/>/g, "&gt;");
75591
+ }
75592
+ const trimmed = (iri ?? "").trim();
75593
+ if (!trimmed) return match2;
75594
+ const label = displayLabelFromIri(trimmed);
75595
+ const safeIri = trimmed.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
75596
+ const safeLabel = label.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
75597
+ return `<a class="wikilink" iri="${safeIri}" href="#" title="${safeIri}">${safeLabel}</a>`;
75598
+ });
75599
+ }
75577
75600
  var SUPPORTED = /* @__PURE__ */ new Set(["table", "tree", "graph", "chart", "diagram", "list", "text", "matrix", "table-editor"]);
75578
75601
  var wikilinkPreviewCard;
75579
75602
  var wikilinkPreviewHideTimer;
@@ -75723,7 +75746,12 @@ ${serialized}`;
75723
75746
  if (!href) {
75724
75747
  return;
75725
75748
  }
75726
- 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
+ }
75727
75755
  });
75728
75756
  }
75729
75757
  function isHoverPreviewEnabled(event) {
@@ -75801,7 +75829,7 @@ ${serialized}`;
75801
75829
  }
75802
75830
  const card = ensureWikilinkPreviewCard();
75803
75831
  const iframe = document.createElement("iframe");
75804
- const iframeSrc = new URL(href, window.location.href);
75832
+ const iframeSrc = new URL(href, document.baseURI);
75805
75833
  iframeSrc.searchParams.set("_oml_preview", "1");
75806
75834
  iframe.src = iframeSrc.toString();
75807
75835
  iframe.style.width = "100%";
@@ -76058,9 +76086,26 @@ ${serialized}`;
76058
76086
  function getScriptSparqlCache() {
76059
76087
  return parseJsonNode("oml-md-script-sparql-cache", {});
76060
76088
  }
76061
- var PYTHON_PANEL_CACHE_STORAGE_KEY = "oml-md-python-panel-cache-v1";
76062
- var R_PANEL_CACHE_STORAGE_KEY = "oml-md-r-panel-cache-v1";
76063
- var JS_PANEL_CACHE_STORAGE_KEY = "oml-md-js-panel-cache-v1";
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
+ }
76106
+ var PYTHON_PANEL_CACHE_STORAGE_KEY = "oml-md-python-panel-cache-v2";
76107
+ var R_PANEL_CACHE_STORAGE_KEY = "oml-md-r-panel-cache-v2";
76108
+ var JS_PANEL_CACHE_STORAGE_KEY = "oml-md-js-panel-cache-v2";
76064
76109
  var MAX_PYTHON_PANEL_CACHE_ENTRIES = 64;
76065
76110
  var MAX_R_PANEL_CACHE_ENTRIES = 64;
76066
76111
  var MAX_JS_PANEL_CACHE_ENTRIES = 64;
@@ -76159,7 +76204,7 @@ ${serialized}`;
76159
76204
  }
76160
76205
  function buildPythonPanelCacheKey(blockId, source, blockCache) {
76161
76206
  const page = `${window.location.origin}${window.location.pathname}${window.location.search}`;
76162
- return `python|${page}|${blockId}|${hash32(source)}|${hash32(JSON.stringify(blockCache))}`;
76207
+ return `python-v2|${page}|${blockId}|${hash32(source)}|${hash32(JSON.stringify(blockCache))}`;
76163
76208
  }
76164
76209
  function buildRPanelCacheKey(blockId, source, blockCache) {
76165
76210
  const page = `${window.location.origin}${window.location.pathname}${window.location.search}`;
@@ -76243,7 +76288,7 @@ ${serialized}`;
76243
76288
  const el = document.createElement("div");
76244
76289
  el.className = "oml-md-js-html-output";
76245
76290
  el.style.color = window.getComputedStyle(document.body).color;
76246
- el.innerHTML = html2;
76291
+ el.innerHTML = expandWikilinksInHtml(html2);
76247
76292
  container.appendChild(el);
76248
76293
  };
76249
76294
  const appendText = (text4) => {
@@ -76256,6 +76301,13 @@ ${serialized}`;
76256
76301
  const display = (content9) => {
76257
76302
  if (typeof content9 === "string") {
76258
76303
  appendHtml(content9);
76304
+ } else if (content9 instanceof Node) {
76305
+ clearStatus();
76306
+ const el = document.createElement("div");
76307
+ el.className = "oml-md-js-html-output";
76308
+ el.style.color = window.getComputedStyle(document.body).color;
76309
+ el.appendChild(content9);
76310
+ container.appendChild(el);
76259
76311
  } else {
76260
76312
  appendText(String(content9));
76261
76313
  }
@@ -76265,6 +76317,10 @@ ${serialized}`;
76265
76317
  };
76266
76318
  const table2 = (result) => sparqlResultToHtmlTable(result);
76267
76319
  const load = async (url) => loadScript(url);
76320
+ const update = async (_ops) => ({});
76321
+ const interactive = (_html, _ops) => "";
76322
+ const includeCache = getScriptIncludeCache();
76323
+ const includePreamble = buildIncludePreamble(code2, includeCache);
76268
76324
  const savedLog = console.log;
76269
76325
  const savedWarn = console.warn;
76270
76326
  const savedError = console.error;
@@ -76284,8 +76340,11 @@ ${serialized}`;
76284
76340
  try {
76285
76341
  const AsyncFunction = Object.getPrototypeOf(async function() {
76286
76342
  }).constructor;
76287
- const fn = new AsyncFunction("display", "query", "table", "load", code2);
76288
- await fn(display, query, table2, load);
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);
76289
76348
  clearStatus();
76290
76349
  return {};
76291
76350
  } catch (error2) {
@@ -76321,8 +76380,11 @@ ${serialized}`;
76321
76380
  const panel = makeScriptPanel();
76322
76381
  pre.replaceWith(panel);
76323
76382
  const result = await executeJsCode(source, blockCache, panel);
76383
+ if (!panel.isConnected) {
76384
+ continue;
76385
+ }
76324
76386
  appendResult(panel, result);
76325
- if (!result.error) {
76387
+ if (!result.error && !panel.querySelector(".oml-md-js-empty")) {
76326
76388
  rememberJsPanelCache(cacheKey, panel.innerHTML);
76327
76389
  }
76328
76390
  }
@@ -76437,6 +76499,23 @@ def table(data):
76437
76499
  for r in rows
76438
76500
  )
76439
76501
  display(f'<div class="oml-md-table-wrapper"><table class="oml-md-table"><thead><tr>{hdr}</tr></thead><tbody>{bdy}</tbody></table></div>')
76502
+
76503
+ async def update(_operations):
76504
+ return {}
76505
+
76506
+ def interactive(_html, _operations):
76507
+ return ''
76508
+
76509
+ def include(_path):
76510
+ pass
76511
+
76512
+ async def js(code, **kwargs):
76513
+ code = code.replace('{{', '').replace('}}', '')
76514
+ for k, v in kwargs.items():
76515
+ code = code.replace(f'{{{k}}}', str(v))
76516
+ code = code.replace('', '{').replace('', '}')
76517
+ result = await _js_eval(code)
76518
+ return result.to_py() if hasattr(result, 'to_py') else result
76440
76519
  `;
76441
76520
  var pyodideExecQueue = Promise.resolve();
76442
76521
  async function executePyCode(code2, blockCache, container) {
@@ -76466,7 +76545,7 @@ def table(data):
76466
76545
  const el = document.createElement("div");
76467
76546
  el.className = "oml-md-js-html-output";
76468
76547
  el.style.color = window.getComputedStyle(document.body).color;
76469
- el.innerHTML = html2;
76548
+ el.innerHTML = expandWikilinksInHtml(html2);
76470
76549
  container.appendChild(el);
76471
76550
  };
76472
76551
  const appendText = (text4) => {
@@ -76491,11 +76570,18 @@ def table(data):
76491
76570
  }
76492
76571
  pyodide.globals.set("_js_display", appendHtml);
76493
76572
  pyodide.globals.set("_js_query", (sparql) => blockCache[sparql] ?? { success: false, columns: [], rows: [], error: "SPARQL not pre-fetched" });
76573
+ pyodide.globals.set("_js_update", async (_opsJson) => ({}));
76574
+ pyodide.globals.set("_js_eval", async (code3) => {
76575
+ const AsyncFunction = Object.getPrototypeOf(async function() {
76576
+ }).constructor;
76577
+ return new AsyncFunction(code3)();
76578
+ });
76494
76579
  pyodide.setStdout({ batched: appendText });
76495
76580
  pyodide.setStderr({ batched: () => {
76496
76581
  } });
76582
+ const preamble = buildIncludePreamble(code2, getScriptIncludeCache());
76497
76583
  try {
76498
- await pyodide.runPythonAsync(code2);
76584
+ await pyodide.runPythonAsync(preamble ? preamble + code2 : code2);
76499
76585
  clearStatus();
76500
76586
  return {};
76501
76587
  } catch (error2) {
@@ -76521,6 +76607,9 @@ def table(data):
76521
76607
  const panel = makeScriptPanel();
76522
76608
  pre.replaceWith(panel);
76523
76609
  const result = await executePyCode(source, blockCache, panel);
76610
+ if (!panel.isConnected) {
76611
+ continue;
76612
+ }
76524
76613
  appendResult(panel, result);
76525
76614
  if (!result.error) {
76526
76615
  rememberPythonPanelCache(cacheKey, panel.innerHTML);
@@ -76571,6 +76660,21 @@ load <- function(pkg) {
76571
76660
  if (!requireNamespace(pkg, quietly=TRUE)) { webr::install(pkg) }
76572
76661
  library(pkg, character.only=TRUE)
76573
76662
  }
76663
+ interactive <- function(html, operations) ''
76664
+ include <- function(path) invisible(NULL)
76665
+ js <- function(code, ...) {
76666
+ args <- list(...)
76667
+ code <- gsub('{{', '', code, fixed=TRUE)
76668
+ code <- gsub('}}', '', code, fixed=TRUE)
76669
+ for (nm in names(args)) {
76670
+ code <- gsub(paste0('{', nm, '}'), as.character(args[[nm]]), code, fixed=TRUE)
76671
+ }
76672
+ code <- gsub('', '{', code, fixed=TRUE)
76673
+ code <- gsub('', '}', code, fixed=TRUE)
76674
+ webr::eval_js(paste0('(async()=>{
76675
+ ', code, '
76676
+ })()'))
76677
+ }
76574
76678
  `;
76575
76679
  function buildRDataFrameCode(result, varName) {
76576
76680
  const rStr = (s) => '"' + s.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "") + '"';
@@ -76647,7 +76751,7 @@ ${colDefs},
76647
76751
  const el = document.createElement("div");
76648
76752
  el.className = "oml-md-js-html-output";
76649
76753
  el.style.color = window.getComputedStyle(document.body).color;
76650
- el.innerHTML = html2;
76754
+ el.innerHTML = expandWikilinksInHtml(html2);
76651
76755
  container.appendChild(el);
76652
76756
  };
76653
76757
  const appendText = (text4) => {
@@ -76676,11 +76780,15 @@ ${colDefs},
76676
76780
  clearStatus();
76677
76781
  return { error: `R bootstrap failed: ${e instanceof Error ? e.message : String(e)}` };
76678
76782
  }
76783
+ const includePreamble = buildIncludePreamble(code2, getScriptIncludeCache());
76679
76784
  let finalCode = code2;
76680
76785
  if (prefetchResults.length > 0) {
76681
76786
  const queryMap = new Map(prefetchResults.map((r) => [r.sparql, r.varName]));
76682
76787
  finalCode = prefetchResults.map((r) => r.preamble).join("\n") + "\n" + rewriteRQueryCalls(code2, queryMap);
76683
76788
  }
76789
+ if (includePreamble) {
76790
+ finalCode = includePreamble + finalCode;
76791
+ }
76684
76792
  try {
76685
76793
  await webR.evalRVoid(
76686
76794
  ".oml_buf_ <- character(0)\ntryCatch({\n" + finalCode + '\n}, error = function(e) { .oml_buf_ <<- c(.oml_buf_, paste0("Error: ", conditionMessage(e))) })\n'
@@ -76712,6 +76820,9 @@ ${colDefs},
76712
76820
  const panel = makeScriptPanel();
76713
76821
  pre.replaceWith(panel);
76714
76822
  const result = await executeRCode(source, blockCache, panel);
76823
+ if (!panel.isConnected) {
76824
+ continue;
76825
+ }
76715
76826
  appendResult(panel, result);
76716
76827
  if (!result.error) {
76717
76828
  rememberRPanelCache(cacheKey, panel.innerHTML);