import { IPlugin, EmptyNode } from '@m2d/core'; /** * Standard token classification for syntax highlighting. */ type TokenType = "keyword" | "string" | "comment" | "number" | "function" | "operator" | "punctuation" | "boolean" | "builtin" | "variable" | "diffAdd" | "diffDelete" | "diffHeader" | "text"; /** * Single token representation. */ interface Token { type: TokenType; value: string; } /** * A line of code with associated tokens and diff status. */ interface CodeLine { diffType?: "add" | "delete" | "header" | "none"; tokens: Token[]; raw: string; } /** * Theme color specification for code syntax highlighting. */ interface ICodeTheme { name?: string; text: string; background: string; keyword: string; string: string; comment: string; number: string; function: string; operator: string; punctuation: string; boolean: string; builtin: string; variable: string; gutterText: string; gutterBackground: string; diffAddBackground: string; diffAddText: string; diffDeleteBackground: string; diffDeleteText: string; border?: string; diffHeader?: string; } /** * Built-in preset theme names. */ type PresetThemeName = "github-light" | "github-dark" | "monokai" | "executive-print"; /** * Configuration options for the code plugin. */ interface ICodePluginOptions { /** * Active theme name or custom theme object. * @default "github-light" */ theme?: PresetThemeName | (string & {}) | ICodeTheme; /** * Additional custom themes catalog mapped by name. */ customThemes?: Record>; /** * Whether to display line numbers in a gutter column. * @default false */ lineNumbers?: boolean; /** * Starting line number for gutter. * @default 1 */ gutterStart?: number; /** * Width percentage allocated to gutter column when lineNumbers is true. * Auto-calculated based on line count if not specified. */ gutterWidthPercent?: number; /** * Monospace font family for code blocks and inline code runs. * @default "Consolas" */ fontFamily?: string; /** * Font size in half-points (e.g. 19 = 9.5pt, 20 = 10pt, 24 = 12pt). * @default 19 */ fontSize?: number; /** * Block presentation type when lineNumbers is false: * - "table": renders a padded single-cell table with background shading and border. * - "paragraph": renders as a native shaded Paragraph. * @default "table" */ blockType?: "table" | "paragraph"; /** * Whether to intercept and highlight inlineCode MDAST nodes. * @default true */ highlightInline?: boolean; /** * Whether to detect and style git diff additions and deletions. * @default true */ diffHighlight?: boolean; /** * Number of spaces to replace tab (\t) characters with. * @default 2 */ tabSize?: number; /** * Optional custom tokenizer override. */ tokenizer?: (code: string, language?: string) => Token[][]; } type CodePluginFactory = (options?: ICodePluginOptions) => IPlugin; declare const defaultCodeOptions: Required>; /** * Maps a token type to its respective theme color. */ declare const getTokenColor: (type: TokenType, theme: ICodeTheme) => string; /** * Code highlighting and formatting plugin for md2docx. */ declare const codePlugin: CodePluginFactory; /** * Default alias export. */ declare const code: CodePluginFactory; /** * Sanitizes hex color string by stripping leading # and trimming whitespace. */ declare const cleanHex: (hex?: string) => string; declare const GITHUB_LIGHT_THEME: ICodeTheme; declare const GITHUB_DARK_THEME: ICodeTheme; declare const MONOKAI_THEME: ICodeTheme; declare const EXECUTIVE_PRINT_THEME: ICodeTheme; declare const THEMES: Record; /** * Resolves theme configuration from name or custom object. */ declare const resolveTheme: (themeOption?: PresetThemeName | (string & {}) | ICodeTheme, customThemes?: Record>) => ICodeTheme; type Language = "javascript" | "python" | "json" | "jsonc" | "bash" | "html" | "css" | "scss" | "less" | "sql" | "markdown" | "generic"; /** * Normalizes input language string or alias to a canonical supported grammar name. */ declare const normalizeLanguage: (language?: string) => Language; /** * Tokenizes entire code block string into a flat token list. * Adheres to fundamental compiler lexical precedence: * 1. Whitespace & universal newlines (\r\n, \n, standalone \r) * 2. Comments (line & block) * 3. Strings & prefixed literals (e.g. f"...", r"...", `...`) * 4. Context-sensitive RegExp literals (JavaScript) * 5. Numbers (hex, binary, float, bigint, complex, CSS hex colors) * 6. Identifiers + O(1) Set classifications (keywords, builtins, booleans, functions) * 7. Operators (longest match first) & Punctuation * 8. Fallback character preservation */ declare const tokenizeCode: (source: string, language?: string) => Token[]; /** * Splits flat tokens across newlines (CRLF, LF, or standalone CR) into per-line token arrays. */ declare const splitTokensIntoLines: (tokens: Token[]) => Token[][]; /** * High-level tokenizer breaking code into per-line token arrays. */ declare const tokenize: (code: string, language?: string) => Token[][]; /** * Parses source code into structured lines with tokens and git diff metadata. */ declare const parseCodeLines: (code: string, language?: string, diffHighlight?: boolean, customTokenizer?: (code: string, lang?: string) => Token[][]) => CodeLine[]; export { EXECUTIVE_PRINT_THEME, GITHUB_DARK_THEME, GITHUB_LIGHT_THEME, MONOKAI_THEME, THEMES, cleanHex, code, codePlugin, defaultCodeOptions, getTokenColor, normalizeLanguage, parseCodeLines, resolveTheme, splitTokensIntoLines, tokenize, tokenizeCode }; export type { CodeLine, CodePluginFactory, ICodePluginOptions, ICodeTheme, Language, PresetThemeName, Token, TokenType };