@ox-content/vite-plugin 3.0.0-alpha.3 → 3.0.0-alpha.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.
package/dist/index.cjs CHANGED
@@ -140,8 +140,8 @@ function normalizeClassName(className) {
140
140
  * Highlights with the native tree-sitter engine, or `null` when it has no
141
141
  * grammar for `lang`.
142
142
  *
143
- * It emits `--octc-shiki-*` markup (the `shiki` prefix is historical) so
144
- * theme-color packages keep working.
143
+ * It emits `--octc-syntax-*` markup so theme-color packages resolve token
144
+ * colors.
145
145
  */
146
146
  function highlightNatively(code, lang) {
147
147
  try {
@@ -168,8 +168,8 @@ async function highlightDocumentNatively(html) {
168
168
  /**
169
169
  * Syntax highlighting with the native tree-sitter engine.
170
170
  *
171
- * Markup keeps the historical `<pre class="shiki css-variables">` wrapper and
172
- * `--octc-shiki-*` custom properties so theme-color packages keep working.
171
+ * Markup uses `<pre class="ox-highlight css-variables">` and `--octc-syntax-*`
172
+ * custom properties so theme-color packages resolve token colors.
173
173
  */
174
174
  const rehypeParse$3 = require_interop.interopDefault(rehype_parse.default);
175
175
  const rehypeStringify$3 = require_interop.interopDefault(rehype_stringify.default);
@@ -213,7 +213,7 @@ function rehypeNativeHighlight() {
213
213
  highlightedCode.properties.className = [.../* @__PURE__ */ new Set([
214
214
  ...originalCodeClasses,
215
215
  ...highlightedClasses,
216
- "shiki-inline"
216
+ "ox-highlight-inline"
217
217
  ])];
218
218
  highlightedCode.properties["data-language"] = lang;
219
219
  return highlightedCode;
@@ -228,7 +228,7 @@ function rehypeNativeHighlight() {
228
228
  const child = node.children[i];
229
229
  if (child.type === "element" && child.tagName === "pre") {
230
230
  const codeElement = child.children.find((c) => c.type === "element" && c.tagName === "code");
231
- const alreadyHighlighted = normalizeClassName(child.properties?.className).includes("shiki");
231
+ const alreadyHighlighted = normalizeClassName(child.properties?.className).includes("ox-highlight");
232
232
  if (codeElement && !alreadyHighlighted) {
233
233
  const highlightedPre = highlightBlockCode(codeElement);
234
234
  if (highlightedPre) node.children[i] = highlightedPre;
@@ -1762,7 +1762,7 @@ async function transformOgp(html, ogpDataMap, options) {
1762
1762
  const SELF_CLOSING_EMBED_TAG = /<(GitHub|OgCard|Tweet|XPost|Bluesky|Spotify|StackBlitz|WebContainer|YouTube)((?:[^>"']|"[^"]*"|'[^']*')*?)\s*\/>/gi;
1763
1763
  /**
1764
1764
  * Custom embed tags are not HTML void elements, so a self-closing authoring
1765
- * form like `<GitHub ... />` reaches the HTML re-parsers (Shiki highlighting,
1765
+ * form like `<GitHub ... />` reaches the HTML re-parsers (syntax highlighting,
1766
1766
  * embed transforms) as an unclosed element that swallows the rest of the
1767
1767
  * document. Normalize to an explicit open/close pair before any rehype pass
1768
1768
  * runs.
@@ -2210,7 +2210,8 @@ async function applyTypedHover(source, html, options) {
2210
2210
  if (fences.length === 0) return html;
2211
2211
  try {
2212
2212
  return attachTypedHoverPayloads(html, await generateTypedHoverAttachments(fences, options.tsgoCommand));
2213
- } catch {
2213
+ } catch (error) {
2214
+ console.warn("[ox-content] typedHover failed; leaving the fence unannotated.", error);
2214
2215
  return html;
2215
2216
  }
2216
2217
  }
@@ -2302,10 +2303,16 @@ function normalizeFenceText(value) {
2302
2303
  return decodeHtmlEntities(value).replace(/\r\n/g, "\n").trim();
2303
2304
  }
2304
2305
  function decodeHtmlEntities(value) {
2305
- return value.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, "\"").replace(/&#39;/g, "'");
2306
+ return value.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&#39;/g, "'").replace(/&#x([0-9a-fA-F]+);/g, (_, hex) => {
2307
+ const code = Number.parseInt(hex, 16);
2308
+ return Number.isFinite(code) ? String.fromCodePoint(code) : "";
2309
+ }).replace(/&#(\d+);/g, (_, dec) => {
2310
+ const code = Number.parseInt(dec, 10);
2311
+ return Number.isFinite(code) ? String.fromCodePoint(code) : "";
2312
+ }).replace(/&amp;/g, "&");
2306
2313
  }
2307
2314
  const TYPED_HOVER_STYLE = `<style data-ox-typed-hover-style>.ox-typed-hover-token{cursor:help;text-decoration:underline dotted}.ox-typed-hover-overlay{position:fixed;z-index:50;max-width:36rem;padding:.35rem .55rem;border:1px solid #444;border-radius:4px;background:#1e1e1e;color:#d4d4d4;font:12px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap;pointer-events:none}</style>`;
2308
- const TYPED_HOVER_CLIENT = `<script data-ox-typed-hover-runtime>(function(){if(window.__oxTypedHover)return;window.__oxTypedHover=1;var tip=document.createElement("div");tip.className="ox-typed-hover-overlay";tip.setAttribute("role","tooltip");tip.hidden=true;document.body.appendChild(tip);function payload(token){var pre=token.closest(".ox-typed-hover");var data=pre&&pre.nextElementSibling;if(!data||!data.classList.contains("ox-typed-hover-data"))return null;try{return JSON.parse(data.textContent||"")}catch(e){return null}}function show(token){var data=payload(token);var item=data&&data.hovers[Number(token.getAttribute("data-ox-typed-hover"))];if(!item)return;tip.textContent=item.type;tip.hidden=false;var box=token.getBoundingClientRect();tip.style.left=Math.max(8,box.left)+"px";tip.style.top=Math.max(8,box.top-tip.offsetHeight-8)+"px"}function hide(){tip.hidden=true}document.addEventListener("mouseover",function(e){var t=e.target.closest(".ox-typed-hover-token");if(t)show(t)});document.addEventListener("mouseout",function(e){var t=e.target.closest(".ox-typed-hover-token");if(t&&!t.contains(e.relatedTarget))hide()});document.addEventListener("focusin",function(e){var t=e.target.closest(".ox-typed-hover-token");if(t)show(t)});document.addEventListener("focusout",function(e){if(!e.relatedTarget||!e.relatedTarget.closest(".ox-typed-hover-token"))hide()});document.addEventListener("keydown",function(e){if(e.key==="Escape")hide()})})();<\/script>`;
2315
+ const TYPED_HOVER_CLIENT = `<script data-ox-typed-hover-runtime>(function(){if(window.__oxTypedHover)return;window.__oxTypedHover=1;var tip=document.createElement("div");tip.className="ox-typed-hover-overlay";tip.setAttribute("role","tooltip");tip.hidden=true;document.body.appendChild(tip);function payload(token){var pre=token.closest(".ox-typed-hover");if(!pre)return null;var host=pre.closest(".ox-code")||pre;var data=host.nextElementSibling;if(!data||!data.classList.contains("ox-typed-hover-data"))return null;try{return JSON.parse(data.textContent||"")}catch(e){return null}}function show(token){var data=payload(token);var item=data&&data.hovers[Number(token.getAttribute("data-ox-typed-hover"))];if(!item)return;tip.textContent=item.type;tip.hidden=false;var box=token.getBoundingClientRect();tip.style.left=Math.max(8,box.left)+"px";tip.style.top=Math.max(8,box.top-tip.offsetHeight-8)+"px"}function hide(){tip.hidden=true}document.addEventListener("mouseover",function(e){var t=e.target.closest(".ox-typed-hover-token");if(t)show(t)});document.addEventListener("mouseout",function(e){var t=e.target.closest(".ox-typed-hover-token");if(t&&!t.contains(e.relatedTarget))hide()});document.addEventListener("focusin",function(e){var t=e.target.closest(".ox-typed-hover-token");if(t)show(t)});document.addEventListener("focusout",function(e){if(!e.relatedTarget||!e.relatedTarget.closest(".ox-typed-hover-token"))hide()});document.addEventListener("keydown",function(e){if(e.key==="Escape")hide()})})();<\/script>`;
2309
2316
  //#endregion
2310
2317
  //#region src/file-tree-options.ts
2311
2318
  const disabled = {