import type { CSSProperties } from 'react'; import type { PlatformBlocksTheme } from '../../core/theme/types'; import type { CodeBlockToken } from './types'; /** * Normalizes language identifiers to standard values for syntax highlighting */ export declare function normalizeLanguage(lang: string): string; /** * Whether `lang` is a shell dialect. Accepts raw ids as well as the output of * `normalizeLanguage`, so callers don't have to normalize first. */ export declare function isShellLanguage(lang: string | undefined): boolean; /** * Highlighting language for a file name, so multi-file code blocks can label a * tab `data.ts` and still highlight it as TypeScript. */ export declare function languageFromFileName(fileName: string): string; /** * Official language logo for a file tab, where one exists in the brand registry. * `CodeBlock` prefers this over the generic Tabler glyph so a `.ts` tab carries * the TypeScript mark the way an editor's file tree would. */ export declare function brandFromFileName(fileName: string): 'typescript' | 'css' | undefined; /** * Icon name (from the bundled Tabler set) for a file tab. Used for extensions * with no language logo, so those group into code / data / prose / style rather * than getting a per-extension glyph; pass `file.icon` to override either. */ export declare function iconFromFileName(fileName: string): string; /** * Parses highlight line specifications like "1", "3-5", "7,9-12" into a Set of line numbers. * Entries may be plain numbers (docs frontmatter yields `highlightLines: [3, 5]`), so each * spec is coerced to a string before parsing. */ export declare function parseHighlightLines(specs: Array | undefined, total: number): Set; /** * Color schemes for different code block variants */ export type SyntaxColorMap = Record; export interface SyntaxColorOptions { /** * Background the code sits on. Token shades are picked for contrast against * it, so a themed or overridden surface still yields legible highlighting. * Accepts hex or `rgb()`/`rgba()`. */ surface?: string; } /** * Type emphasis per token, shared by the web (Prism) and native renderers so * both read the same. Kept separate from the color map because `colors.text` * lets consumers override colors without inheriting our weights. */ export declare const SYNTAX_TOKEN_EMPHASIS: Partial>; /** * Contrast math needs an opaque hex. Accepts hex or `rgb()`/`rgba()`, and * composites translucent colors over `behind` so the measured ratio matches what * the reader actually sees. */ export declare function toOpaqueHex(color: string | undefined, behind: string): string; export declare function getSyntaxColors(theme: PlatformBlocksTheme, isDark: boolean, variant?: 'code' | 'terminal' | 'hacker', overrides?: Partial>, options?: SyntaxColorOptions): SyntaxColorMap; /** * Builds a react-syntax-highlighter (Prism) theme object from a resolved syntax * color map, so the web highlighter uses the same theme-derived palette as the * native tokenizer instead of a generic prebuilt Prism theme. */ export declare function buildPrismTheme(colors: SyntaxColorMap, baseColor: string, fontFamily?: string): Record; /** One rule for the built-in tokenizer. */ export interface SyntaxPattern { token: CodeBlockToken; pattern: RegExp; color: string; /** * Color this capture group rather than the whole match, for rules that need * left context — a preceding space, a pipe — to decide but must not swallow * it. The group has to sit at the *end* of the match: its offset is derived * from the two lengths, which avoids a lookbehind (still unsupported on the * older Safari and Hermes builds this ships to, and a parse-time error there, * not a runtime one). */ group?: number; } /** * Regex patterns for the built-in tokenizer, ordered by precedence: the first * pattern to claim a range wins, so a keyword inside a string or a quote inside * a comment can't be re-colored by a later pattern. Patterns run against the * whole source, not one line at a time, so block comments and template literals * keep their color across line breaks. * * `language` selects the grammar. Anything that isn't a shell dialect gets the * JavaScript/TSX set, which is what every language fell back to before shell * existed — a `bash` block came out as good as plain text, since none of the JS * patterns match a command line except the operator rule catching the hyphens * and slash in a package name. */ export declare function getSyntaxPatterns(colors: ReturnType, language?: string): SyntaxPattern[]; /** One rendered run of source text. Emphasis mirrors the Prism theme's. */ export interface NativeSyntaxToken { text: string; color: string; fontStyle?: 'italic'; fontWeight?: '500' | '600'; } export interface NativeHighlighterOptions extends SyntaxColorOptions { /** Color for text no pattern claims — identifiers, JSX text, whitespace. */ baseColor?: string; /** * Grammar to tokenize with. Shell dialects get the shell patterns; everything * else gets the JavaScript/TSX set. `variant: 'terminal'` implies shell. */ language?: string; } /** * Built-in tokenizer used wherever Prism isn't available (native, and web bundles * that can't resolve `react-syntax-highlighter`). It scans the whole source once, * letting higher-precedence patterns claim their ranges first, then slices the * claimed ranges back into per-line token runs. */ export declare function createNativeHighlighter(theme: PlatformBlocksTheme, isDark: boolean, variant?: 'code' | 'terminal' | 'hacker', overrides?: Partial>, options?: NativeHighlighterOptions): (code: string) => NativeSyntaxToken[][];