@ox-content/vite-plugin 3.0.0-alpha.2 → 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.d.cts CHANGED
@@ -2173,9 +2173,9 @@ interface OxContentOptions {
2173
2173
  * Enable syntax highlighting for code blocks.
2174
2174
  *
2175
2175
  * When true, fenced and language-tagged inline code is highlighted with the
2176
- * native tree-sitter engine. Token colors are `--octc-shiki-*` custom
2177
- * properties (the `shiki` prefix is historical) so theme-color packages keep
2178
- * working. Languages with no native grammar stay unhighlighted.
2176
+ * native tree-sitter engine. Token colors are `--octc-syntax-*` custom
2177
+ * properties so theme-color packages resolve highlighting. Languages with no
2178
+ * native grammar stay unhighlighted.
2179
2179
  *
2180
2180
  * @default false
2181
2181
  */
package/dist/index.d.mts CHANGED
@@ -2173,9 +2173,9 @@ interface OxContentOptions {
2173
2173
  * Enable syntax highlighting for code blocks.
2174
2174
  *
2175
2175
  * When true, fenced and language-tagged inline code is highlighted with the
2176
- * native tree-sitter engine. Token colors are `--octc-shiki-*` custom
2177
- * properties (the `shiki` prefix is historical) so theme-color packages keep
2178
- * working. Languages with no native grammar stay unhighlighted.
2176
+ * native tree-sitter engine. Token colors are `--octc-syntax-*` custom
2177
+ * properties so theme-color packages resolve highlighting. Languages with no
2178
+ * native grammar stay unhighlighted.
2179
2179
  *
2180
2180
  * @default false
2181
2181
  */
package/dist/index.mjs CHANGED
@@ -132,8 +132,8 @@ function normalizeClassName(className) {
132
132
  * Highlights with the native tree-sitter engine, or `null` when it has no
133
133
  * grammar for `lang`.
134
134
  *
135
- * It emits `--octc-shiki-*` markup (the `shiki` prefix is historical) so
136
- * theme-color packages keep working.
135
+ * It emits `--octc-syntax-*` markup so theme-color packages resolve token
136
+ * colors.
137
137
  */
138
138
  function highlightNatively(code, lang) {
139
139
  try {
@@ -160,8 +160,8 @@ async function highlightDocumentNatively(html) {
160
160
  /**
161
161
  * Syntax highlighting with the native tree-sitter engine.
162
162
  *
163
- * Markup keeps the historical `<pre class="shiki css-variables">` wrapper and
164
- * `--octc-shiki-*` custom properties so theme-color packages keep working.
163
+ * Markup uses `<pre class="ox-highlight css-variables">` and `--octc-syntax-*`
164
+ * custom properties so theme-color packages resolve token colors.
165
165
  */
166
166
  const rehypeParse$3 = interopDefault(rehypeParsePlugin);
167
167
  const rehypeStringify$3 = interopDefault(rehypeStringifyPlugin);
@@ -205,7 +205,7 @@ function rehypeNativeHighlight() {
205
205
  highlightedCode.properties.className = [.../* @__PURE__ */ new Set([
206
206
  ...originalCodeClasses,
207
207
  ...highlightedClasses,
208
- "shiki-inline"
208
+ "ox-highlight-inline"
209
209
  ])];
210
210
  highlightedCode.properties["data-language"] = lang;
211
211
  return highlightedCode;
@@ -220,7 +220,7 @@ function rehypeNativeHighlight() {
220
220
  const child = node.children[i];
221
221
  if (child.type === "element" && child.tagName === "pre") {
222
222
  const codeElement = child.children.find((c) => c.type === "element" && c.tagName === "code");
223
- const alreadyHighlighted = normalizeClassName(child.properties?.className).includes("shiki");
223
+ const alreadyHighlighted = normalizeClassName(child.properties?.className).includes("ox-highlight");
224
224
  if (codeElement && !alreadyHighlighted) {
225
225
  const highlightedPre = highlightBlockCode(codeElement);
226
226
  if (highlightedPre) node.children[i] = highlightedPre;
@@ -1754,7 +1754,7 @@ async function transformOgp(html, ogpDataMap, options) {
1754
1754
  const SELF_CLOSING_EMBED_TAG = /<(GitHub|OgCard|Tweet|XPost|Bluesky|Spotify|StackBlitz|WebContainer|YouTube)((?:[^>"']|"[^"]*"|'[^']*')*?)\s*\/>/gi;
1755
1755
  /**
1756
1756
  * Custom embed tags are not HTML void elements, so a self-closing authoring
1757
- * form like `<GitHub ... />` reaches the HTML re-parsers (Shiki highlighting,
1757
+ * form like `<GitHub ... />` reaches the HTML re-parsers (syntax highlighting,
1758
1758
  * embed transforms) as an unclosed element that swallows the rest of the
1759
1759
  * document. Normalize to an explicit open/close pair before any rehype pass
1760
1760
  * runs.
@@ -2202,7 +2202,8 @@ async function applyTypedHover(source, html, options) {
2202
2202
  if (fences.length === 0) return html;
2203
2203
  try {
2204
2204
  return attachTypedHoverPayloads(html, await generateTypedHoverAttachments(fences, options.tsgoCommand));
2205
- } catch {
2205
+ } catch (error) {
2206
+ console.warn("[ox-content] typedHover failed; leaving the fence unannotated.", error);
2206
2207
  return html;
2207
2208
  }
2208
2209
  }
@@ -2294,10 +2295,16 @@ function normalizeFenceText(value) {
2294
2295
  return decodeHtmlEntities(value).replace(/\r\n/g, "\n").trim();
2295
2296
  }
2296
2297
  function decodeHtmlEntities(value) {
2297
- return value.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, "\"").replace(/&#39;/g, "'");
2298
+ return value.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&#39;/g, "'").replace(/&#x([0-9a-fA-F]+);/g, (_, hex) => {
2299
+ const code = Number.parseInt(hex, 16);
2300
+ return Number.isFinite(code) ? String.fromCodePoint(code) : "";
2301
+ }).replace(/&#(\d+);/g, (_, dec) => {
2302
+ const code = Number.parseInt(dec, 10);
2303
+ return Number.isFinite(code) ? String.fromCodePoint(code) : "";
2304
+ }).replace(/&amp;/g, "&");
2298
2305
  }
2299
2306
  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>`;
2300
- 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>`;
2307
+ 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>`;
2301
2308
  //#endregion
2302
2309
  //#region src/file-tree-options.ts
2303
2310
  const disabled = {