From 4ccaf4c41adbd5409e6c151d49cc4c2f896cdc31 Mon Sep 17 00:00:00 2001 From: flakey5 <73616808+flakey5@users.noreply.github.com> Date: Wed, 5 Mar 2025 13:09:59 -0800 Subject: [PATCH] fix: some shiki deprecation warnings Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com> --- shiki.config.mjs | 3 -- src/constants.mjs | 50 ++++++++++++++++----- src/generators/legacy-html/assets/style.css | 12 ++--- src/utils/highlighter.mjs | 8 +++- 4 files changed, 52 insertions(+), 21 deletions(-) diff --git a/shiki.config.mjs b/shiki.config.mjs index aab14243..2bbc8f95 100644 --- a/shiki.config.mjs +++ b/shiki.config.mjs @@ -1,7 +1,5 @@ 'use strict'; -import { getWasmInstance } from '@shikijs/core/wasm-inlined'; - import cLanguage from 'shiki/langs/c.mjs'; import coffeeScriptLanguage from 'shiki/langs/coffeescript.mjs'; import cPlusPlusLanguage from 'shiki/langs/cpp.mjs'; @@ -24,7 +22,6 @@ import darkTheme from 'shiki/themes/catppuccin-mocha.mjs'; * @type {import('@shikijs/core').HighlighterCoreOptions} */ export default { - loadWasm: getWasmInstance, // Only register the themes we need, to support light/dark theme themes: [lightTheme, darkTheme], // Only register the languages that the API docs use diff --git a/src/constants.mjs b/src/constants.mjs index 803bd2db..d84ec91c 100644 --- a/src/constants.mjs +++ b/src/constants.mjs @@ -125,17 +125,45 @@ export const DOC_SLUG_ENVIRONMENT = 'environment-variables-1'; // JavaScript globals types within the MDN JavaScript docs // @see DOC_MDN_BASE_URL_JS_GLOBALS export const DOC_TYPES_MAPPING_GLOBALS = { - ...Object.fromEntries([ - 'AggregateError', 'Array', 'ArrayBuffer', 'DataView', 'Date', 'Error', - 'EvalError', 'Function', 'Map', 'NaN', 'Object', 'Promise', 'Proxy', 'RangeError', - 'ReferenceError', 'RegExp', 'Set', 'SharedArrayBuffer', 'SyntaxError', 'Symbol', - 'TypeError', 'URIError', 'WeakMap', 'WeakSet', - - 'TypedArray', - 'Float32Array', 'Float64Array', - 'Int8Array', 'Int16Array', 'Int32Array', - 'Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', - ].map(e => [e, e])), + ...Object.fromEntries( + [ + 'AggregateError', + 'Array', + 'ArrayBuffer', + 'DataView', + 'Date', + 'Error', + 'EvalError', + 'Function', + 'Map', + 'NaN', + 'Object', + 'Promise', + 'Proxy', + 'RangeError', + 'ReferenceError', + 'RegExp', + 'Set', + 'SharedArrayBuffer', + 'SyntaxError', + 'Symbol', + 'TypeError', + 'URIError', + 'WeakMap', + 'WeakSet', + + 'TypedArray', + 'Float32Array', + 'Float64Array', + 'Int8Array', + 'Int16Array', + 'Int32Array', + 'Uint8Array', + 'Uint8ClampedArray', + 'Uint16Array', + 'Uint32Array', + ].map(e => [e, e]) + ), bigint: 'BigInt', 'WebAssembly.Instance': 'WebAssembly/Instance', }; diff --git a/src/generators/legacy-html/assets/style.css b/src/generators/legacy-html/assets/style.css index 9086b6b4..f2fcb3a5 100644 --- a/src/generators/legacy-html/assets/style.css +++ b/src/generators/legacy-html/assets/style.css @@ -75,8 +75,9 @@ html { } body { - font-family: Lato, 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', - Verdana, Tahoma, sans-serif; + font-family: + Lato, 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Verdana, + Tahoma, sans-serif; margin: 0; padding: 0; color: var(--color-text-primary); @@ -137,8 +138,8 @@ code, .pre, span.type, a.type { - font-family: SFMono-Regular, Menlo, Consolas, 'Liberation Mono', - 'Courier New', monospace; + font-family: + SFMono-Regular, Menlo, Consolas, 'Liberation Mono', 'Courier New', monospace; font-size: 0.9em; } @@ -1031,7 +1032,8 @@ kbd { margin-right: 10px; margin-top: -2px; height: 1.5rem; - transition-property: background-color, border-color, color, box-shadow, filter; + transition-property: + background-color, border-color, color, box-shadow, filter; transition-duration: 0.3s; cursor: pointer; } diff --git a/src/utils/highlighter.mjs b/src/utils/highlighter.mjs index 53bb8e22..9ad32c8d 100644 --- a/src/utils/highlighter.mjs +++ b/src/utils/highlighter.mjs @@ -5,7 +5,8 @@ import { h as createElement } from 'hastscript'; import { toString } from 'hast-util-to-string'; import { SKIP, visit } from 'unist-util-visit'; -import { getSingletonHighlighterCore } from '@shikijs/core'; +import { createHighlighterCoreSync } from '@shikijs/core'; +import { createJavaScriptRegexEngine } from '@shikijs/engine-javascript'; import shikiConfig from '../../shiki.config.mjs'; @@ -14,7 +15,10 @@ import shikiConfig from '../../shiki.config.mjs'; const languagePrefix = 'language-'; // Creates a Singleton instance for Shiki's syntax highlighter using WASM -const shikiHighlighter = await getSingletonHighlighterCore(shikiConfig); +const shikiHighlighter = createHighlighterCoreSync({ + ...shikiConfig, + engine: createJavaScriptRegexEngine(), +}); // Creates a static button element which is used for the "copy" button // within codeboxes for copying the code to the clipboard