@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 +17 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +17 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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-
|
|
2177
|
-
* properties
|
|
2178
|
-
*
|
|
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-
|
|
2177
|
-
* properties
|
|
2178
|
-
*
|
|
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-
|
|
136
|
-
*
|
|
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
|
|
164
|
-
*
|
|
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
|
-
"
|
|
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("
|
|
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 (
|
|
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(/</g, "<").replace(/>/g, ">").replace(/&
|
|
2298
|
+
return value.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, "\"").replace(/'/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(/&/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
|
|
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 = {
|