import { ShjCoreOptions, ShjCoreTerminalOptions, ShjCoreTokenizeOptions, ShjDisplayMode, ShjLanguage, ShjLanguageAlias, ShjLanguageComponent, ShjLanguageDefinition, ShjLanguageModule, ShjLanguages, ShjMatcher, ShjOptions, ShjSubLanguage, ShjTerminalOptions, ShjTheme, ShjThemeName, ShjThemePair, ShjToken, ShjTokenRef, ShjTokenizeOptions, ShjTokenized } from "./_chunks/types.mjs"; import { detectLanguage } from "./_chunks/detect.mjs"; /** * Split a string into its tokens, without rendering anything * * This is the layer every other function is built on: use it to render the * tokens yourself, to feed another output format, or to inspect a grammar. * * The tokens are returned in source order, never empty, and their `text` is * raw — nothing is escaped — so concatenating them gives the input back. Text * that no rule matched is returned as a token without a `type`, and an unknown * language or a broken grammar yields the whole code as a single untyped token * rather than throwing. * * A token may span line breaks: a block comment, a template literal or a run * of plain text is one token however many lines it covers. To render per line, * tokenize the whole code once and split the tokens on `\n` — tokenizing each * line on its own silently mis-highlights everything that crosses a break. * * The `type` is the key a {@link ShjTheme} assigns a color to. The one style * the theme does not carry is the italic `cmnt` is rendered with in html, * which is a convention of that output rather than theme data. * * @example * tokenize('let a = 1', { lang: 'js', languages: { js } }); * // [ * // { text: 'let', type: 'kwd' }, * // { text: ' a ' }, * // { text: '=', type: 'oper' }, * // { text: ' ' }, * // { text: '1', type: 'num' } * // ] * * @example * // the registry applies to sub-languages too * tokenize(code, { lang: 'mine', languages: { mine } }); * * @example * // group into lines, keeping tokens that span a break intact * const lines = [[]]; * for (const { text, type } of tokenize(code, { lang: 'js', languages: { js } })) * text.split('\n').forEach((part, i) => { * if (i) lines.push([]); * if (part) lines.at(-1).push({ text: part, type }); * }); * * @function tokenize * @param {string} code The code * @param {ShjCoreTokenizeOptions} opt Customization options * @returns {ShjTokenized[]} The tokens, in source order */ declare function tokenize(code: string, opt: ShjCoreTokenizeOptions): ShjTokenized[]; /** * Highlight a string and return the content of a code block: the tokens, and * the line numbers when the code is multiline * * Use {@link codeToHtml} to get the code block itself. * * With `classes: true` the tokens carry a `shj-` class instead of an * inline color, and the gutter is left to the stylesheet. * * @example * elm.innerHTML = highlightText(code, { lang: 'js', languages: { js }, theme: dark }); * * @function highlightText * @param {string} code The code * @param {ShjCoreOptions} opt Customization options * @returns {string} The highlighted string */ declare function highlightText(code: string, opt: ShjCoreOptions): string; /** * Highlight a string and return the markup of a complete code block * * The colors of the theme are inlined, so the result is self contained and * needs no stylesheet. Pass `classes: true` to emit class names instead and * style the block yourself. * * @example * html += codeToHtml(code, { lang: 'js', languages: { js }, theme: githubDark }); * html += codeToHtml(code, { lang: 'mine', languages: { mine }, theme: githubDark }); * * @example * // no `style` attribute anywhere: bring your own stylesheet * html += codeToHtml(code, { lang: 'js', languages: { js }, classes: true }); * * @function codeToHtml * @param {string} code The code * @param {ShjCoreOptions} opt Customization options * @returns {string} The markup of the code block */ declare function codeToHtml(code: string, opt: ShjCoreOptions): string; /** * Highlight a string and return a string that can directly be printed * * The colors of the theme are emitted as 24 bit escape sequences. A color a * terminal cannot be given — anything that is not hex, such as the custom * properties of the `cssVariables` theme — leaves its tokens uncolored. * * @example * console.log(codeToAnsi(code, { lang: 'js', languages: { js }, theme: atomDark })); * * @function codeToAnsi * @param {string} code The code * @param {ShjCoreTerminalOptions} opt Customization options * @returns {string} The highlighted string */ declare function codeToAnsi(code: string, opt: ShjCoreTerminalOptions): string; /** * Highlight and print a given string * * @example * printHighlight(code, { lang: 'js', languages: { js }, theme: atomDark }); * * @function printHighlight * @param {string} code The code * @param {ShjCoreTerminalOptions} opt Customization options */ declare const printHighlight: (code: string, opt: ShjCoreTerminalOptions) => void; export { type ShjCoreOptions, type ShjCoreTerminalOptions, type ShjCoreTokenizeOptions, type ShjDisplayMode, type ShjLanguage, type ShjLanguageAlias, type ShjLanguageComponent, type ShjLanguageDefinition, type ShjLanguageModule, type ShjLanguages, type ShjMatcher, type ShjOptions, type ShjSubLanguage, type ShjTerminalOptions, type ShjTheme, type ShjThemeName, type ShjThemePair, type ShjToken, type ShjTokenRef, type ShjTokenizeOptions, type ShjTokenized, codeToAnsi, codeToHtml, detectLanguage, highlightText, printHighlight, tokenize };