@oml/markdown 0.16.0 → 0.16.2

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.
@@ -75574,6 +75574,20 @@ ${serialized}`;
75574
75574
  }
75575
75575
 
75576
75576
  // src/static/browser-runtime.ts
75577
+ function expandWikilinksInHtml(html2) {
75578
+ return html2.replace(/(<[^>]*>)|\[\[([^\]]+)\]\]/g, (match2, tag, iri) => {
75579
+ if (tag !== void 0) {
75580
+ if (/^<[!?]/.test(tag) || /^<\/?[a-zA-Z][a-zA-Z0-9-]*(?:[\s>\/]|$)/.test(tag)) return tag;
75581
+ return tag.replace(/</g, "&lt;").replace(/>/g, "&gt;");
75582
+ }
75583
+ const trimmed = (iri ?? "").trim();
75584
+ if (!trimmed) return match2;
75585
+ const label = displayLabelFromIri(trimmed);
75586
+ const safeIri = trimmed.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
75587
+ const safeLabel = label.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
75588
+ return `<a class="wikilink" iri="${safeIri}" href="#" title="${safeIri}">${safeLabel}</a>`;
75589
+ });
75590
+ }
75577
75591
  var SUPPORTED = /* @__PURE__ */ new Set(["table", "tree", "graph", "chart", "diagram", "list", "text", "matrix", "table-editor"]);
75578
75592
  var wikilinkPreviewCard;
75579
75593
  var wikilinkPreviewHideTimer;
@@ -76058,9 +76072,9 @@ ${serialized}`;
76058
76072
  function getScriptSparqlCache() {
76059
76073
  return parseJsonNode("oml-md-script-sparql-cache", {});
76060
76074
  }
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";
76075
+ var PYTHON_PANEL_CACHE_STORAGE_KEY = "oml-md-python-panel-cache-v2";
76076
+ var R_PANEL_CACHE_STORAGE_KEY = "oml-md-r-panel-cache-v2";
76077
+ var JS_PANEL_CACHE_STORAGE_KEY = "oml-md-js-panel-cache-v2";
76064
76078
  var MAX_PYTHON_PANEL_CACHE_ENTRIES = 64;
76065
76079
  var MAX_R_PANEL_CACHE_ENTRIES = 64;
76066
76080
  var MAX_JS_PANEL_CACHE_ENTRIES = 64;
@@ -76159,7 +76173,7 @@ ${serialized}`;
76159
76173
  }
76160
76174
  function buildPythonPanelCacheKey(blockId, source, blockCache) {
76161
76175
  const page = `${window.location.origin}${window.location.pathname}${window.location.search}`;
76162
- return `python|${page}|${blockId}|${hash32(source)}|${hash32(JSON.stringify(blockCache))}`;
76176
+ return `python-v2|${page}|${blockId}|${hash32(source)}|${hash32(JSON.stringify(blockCache))}`;
76163
76177
  }
76164
76178
  function buildRPanelCacheKey(blockId, source, blockCache) {
76165
76179
  const page = `${window.location.origin}${window.location.pathname}${window.location.search}`;
@@ -76243,7 +76257,7 @@ ${serialized}`;
76243
76257
  const el = document.createElement("div");
76244
76258
  el.className = "oml-md-js-html-output";
76245
76259
  el.style.color = window.getComputedStyle(document.body).color;
76246
- el.innerHTML = html2;
76260
+ el.innerHTML = expandWikilinksInHtml(html2);
76247
76261
  container.appendChild(el);
76248
76262
  };
76249
76263
  const appendText = (text4) => {
@@ -76256,6 +76270,13 @@ ${serialized}`;
76256
76270
  const display = (content9) => {
76257
76271
  if (typeof content9 === "string") {
76258
76272
  appendHtml(content9);
76273
+ } else if (content9 instanceof Node) {
76274
+ clearStatus();
76275
+ const el = document.createElement("div");
76276
+ el.className = "oml-md-js-html-output";
76277
+ el.style.color = window.getComputedStyle(document.body).color;
76278
+ el.appendChild(content9);
76279
+ container.appendChild(el);
76259
76280
  } else {
76260
76281
  appendText(String(content9));
76261
76282
  }
@@ -76265,6 +76286,8 @@ ${serialized}`;
76265
76286
  };
76266
76287
  const table2 = (result) => sparqlResultToHtmlTable(result);
76267
76288
  const load = async (url) => loadScript(url);
76289
+ const update = async (_ops) => ({});
76290
+ const interactive = (html2, _ops) => html2;
76268
76291
  const savedLog = console.log;
76269
76292
  const savedWarn = console.warn;
76270
76293
  const savedError = console.error;
@@ -76284,8 +76307,8 @@ ${serialized}`;
76284
76307
  try {
76285
76308
  const AsyncFunction = Object.getPrototypeOf(async function() {
76286
76309
  }).constructor;
76287
- const fn = new AsyncFunction("display", "query", "table", "load", code2);
76288
- await fn(display, query, table2, load);
76310
+ const fn = new AsyncFunction("display", "query", "table", "load", "update", "interactive", code2);
76311
+ await fn(display, query, table2, load, update, interactive);
76289
76312
  clearStatus();
76290
76313
  return {};
76291
76314
  } catch (error2) {
@@ -76321,6 +76344,9 @@ ${serialized}`;
76321
76344
  const panel = makeScriptPanel();
76322
76345
  pre.replaceWith(panel);
76323
76346
  const result = await executeJsCode(source, blockCache, panel);
76347
+ if (!panel.isConnected) {
76348
+ continue;
76349
+ }
76324
76350
  appendResult(panel, result);
76325
76351
  if (!result.error) {
76326
76352
  rememberJsPanelCache(cacheKey, panel.innerHTML);
@@ -76437,6 +76463,20 @@ def table(data):
76437
76463
  for r in rows
76438
76464
  )
76439
76465
  display(f'<div class="oml-md-table-wrapper"><table class="oml-md-table"><thead><tr>{hdr}</tr></thead><tbody>{bdy}</tbody></table></div>')
76466
+
76467
+ async def update(_operations):
76468
+ return {}
76469
+
76470
+ def interactive(html, _operations):
76471
+ return str(html)
76472
+
76473
+ async def js(code, **kwargs):
76474
+ code = code.replace('{{', '').replace('}}', '')
76475
+ for k, v in kwargs.items():
76476
+ code = code.replace(f'{{{k}}}', str(v))
76477
+ code = code.replace('', '{').replace('', '}')
76478
+ result = await _js_eval(code)
76479
+ return result.to_py() if hasattr(result, 'to_py') else result
76440
76480
  `;
76441
76481
  var pyodideExecQueue = Promise.resolve();
76442
76482
  async function executePyCode(code2, blockCache, container) {
@@ -76466,7 +76506,7 @@ def table(data):
76466
76506
  const el = document.createElement("div");
76467
76507
  el.className = "oml-md-js-html-output";
76468
76508
  el.style.color = window.getComputedStyle(document.body).color;
76469
- el.innerHTML = html2;
76509
+ el.innerHTML = expandWikilinksInHtml(html2);
76470
76510
  container.appendChild(el);
76471
76511
  };
76472
76512
  const appendText = (text4) => {
@@ -76491,6 +76531,12 @@ def table(data):
76491
76531
  }
76492
76532
  pyodide.globals.set("_js_display", appendHtml);
76493
76533
  pyodide.globals.set("_js_query", (sparql) => blockCache[sparql] ?? { success: false, columns: [], rows: [], error: "SPARQL not pre-fetched" });
76534
+ pyodide.globals.set("_js_update", async (_opsJson) => ({}));
76535
+ pyodide.globals.set("_js_eval", async (code3) => {
76536
+ const AsyncFunction = Object.getPrototypeOf(async function() {
76537
+ }).constructor;
76538
+ return new AsyncFunction(code3)();
76539
+ });
76494
76540
  pyodide.setStdout({ batched: appendText });
76495
76541
  pyodide.setStderr({ batched: () => {
76496
76542
  } });
@@ -76521,6 +76567,9 @@ def table(data):
76521
76567
  const panel = makeScriptPanel();
76522
76568
  pre.replaceWith(panel);
76523
76569
  const result = await executePyCode(source, blockCache, panel);
76570
+ if (!panel.isConnected) {
76571
+ continue;
76572
+ }
76524
76573
  appendResult(panel, result);
76525
76574
  if (!result.error) {
76526
76575
  rememberPythonPanelCache(cacheKey, panel.innerHTML);
@@ -76571,6 +76620,20 @@ load <- function(pkg) {
76571
76620
  if (!requireNamespace(pkg, quietly=TRUE)) { webr::install(pkg) }
76572
76621
  library(pkg, character.only=TRUE)
76573
76622
  }
76623
+ interactive <- function(html, operations) as.character(html)
76624
+ js <- function(code, ...) {
76625
+ args <- list(...)
76626
+ code <- gsub('{{', '', code, fixed=TRUE)
76627
+ code <- gsub('}}', '', code, fixed=TRUE)
76628
+ for (nm in names(args)) {
76629
+ code <- gsub(paste0('{', nm, '}'), as.character(args[[nm]]), code, fixed=TRUE)
76630
+ }
76631
+ code <- gsub('', '{', code, fixed=TRUE)
76632
+ code <- gsub('', '}', code, fixed=TRUE)
76633
+ webr::eval_js(paste0('(async()=>{
76634
+ ', code, '
76635
+ })()'))
76636
+ }
76574
76637
  `;
76575
76638
  function buildRDataFrameCode(result, varName) {
76576
76639
  const rStr = (s) => '"' + s.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "") + '"';
@@ -76647,7 +76710,7 @@ ${colDefs},
76647
76710
  const el = document.createElement("div");
76648
76711
  el.className = "oml-md-js-html-output";
76649
76712
  el.style.color = window.getComputedStyle(document.body).color;
76650
- el.innerHTML = html2;
76713
+ el.innerHTML = expandWikilinksInHtml(html2);
76651
76714
  container.appendChild(el);
76652
76715
  };
76653
76716
  const appendText = (text4) => {
@@ -76712,6 +76775,9 @@ ${colDefs},
76712
76775
  const panel = makeScriptPanel();
76713
76776
  pre.replaceWith(panel);
76714
76777
  const result = await executeRCode(source, blockCache, panel);
76778
+ if (!panel.isConnected) {
76779
+ continue;
76780
+ }
76715
76781
  appendResult(panel, result);
76716
76782
  if (!result.error) {
76717
76783
  rememberRPanelCache(cacheKey, panel.innerHTML);