import { ShikiError as ShikiError$1 } from "@shikijs/types"; import { ShikiError, applyColorReplacements, codeToTokensBase as codeToTokensBase$1, codeToTokensWithThemes, codeToTokensWithThemes as codeToTokensWithThemes$1, createShikiInternal, createShikiInternalSync, createShikiPrimitive, createShikiPrimitive as createShikiPrimitive$1, createShikiPrimitiveAsync, createShikiPrimitiveAsync as createShikiPrimitiveAsync$1, getLastGrammarState, getLastGrammarStateFromMap, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, normalizeGetter, normalizeTheme, resolveColorReplacements, setLastGrammarStateToMap, splitLines, splitLines as splitLines$1, toArray, tokenizeWithTheme } from "@shikijs/primitive"; import { FontStyle } from "@shikijs/vscode-textmate"; import { toHtml } from "hast-util-to-html"; export * from "@shikijs/types" //#region src/utils/hast.ts /** * Utility to append class to a hast node * * If the `property.class` is a string, it will be splitted by space and converted to an array. */ function addClassToHast(node, className) { if (!className) return node; node.properties ||= {}; node.properties.class ||= []; if (typeof node.properties.class === "string") node.properties.class = node.properties.class.split(/\s+/g); if (!Array.isArray(node.properties.class)) node.properties.class = []; const targets = Array.isArray(className) ? className : className.split(/\s+/g); for (const c of targets) if (c && !node.properties.class.includes(c)) node.properties.class.push(c); return node; } //#endregion //#region src/utils/strings.ts /** * Creates a converter between index and position in a code block. * * Overflow/underflow are unchecked. */ function createPositionConverter(code) { const lines = splitLines$1(code, true).map(([line]) => line); function indexToPos(index) { if (index === code.length) return { line: lines.length - 1, character: lines[lines.length - 1].length }; let character = index; let line = 0; for (const lineText of lines) { if (character < lineText.length) break; character -= lineText.length; line++; } return { line, character }; } function posToIndex(line, character) { let index = 0; for (let i = 0; i < line; i++) index += lines[i].length; index += character; return index; } return { lines, indexToPos, posToIndex }; } /** * Guess embedded languages from given code and highlighter. * * When highlighter is provided, only bundled languages will be included. * * @param code - The code string to analyze * @param _lang - The primary language of the code (currently unused) * @param highlighter - Optional highlighter instance to validate languages * @returns Array of detected language identifiers * * @example * ```ts * // Detects 'javascript' from Vue SFC * guessEmbeddedLanguages('