UNPKG

1.67 kBTypeScriptView Raw
1import { Theme } from './theme';
2/**
3 * Options passed to [[highlight]]
4 */
5export interface HighlightOptions {
6 /**
7 * Can be a name, file extension, alias etc. If omitted, tries to auto-detect language.
8 */
9 language?: string;
10 /**
11 * When present and evaluates to a true value, forces highlighting to finish even in case of
12 * detecting illegal syntax for the language instead of throwing an exception.
13 */
14 ignoreIllegals?: boolean;
15 /**
16 * Optional array of language names and aliases restricting detection to only those languages.
17 */
18 languageSubset?: string[];
19 /**
20 * Supply a custom theme where you override language tokens with own formatter functions. Every
21 * token that is not overriden falls back to the [[DEFAULT_THEME]]
22 */
23 theme?: Theme;
24}
25/**
26 * Apply syntax highlighting to `code` with ASCII color codes. The language is automatically
27 * detected if not set.
28 *
29 * ```ts
30 * import {highlight} from 'cli-highlight';
31 * import * as fs from 'fs';
32 *
33 * fs.readFile('package.json', 'utf8', (err: any, json: string) => {
34 * console.log('package.json:');
35 * console.log(highlight(json));
36 * });
37 * ```
38 *
39 * @param code The code to highlight
40 * @param options Optional options
41 */
42export declare function highlight(code: string, options?: HighlightOptions): string;
43/**
44 * Returns all supported languages
45 */
46export declare function listLanguages(): string[];
47/**
48 * Returns true if the language is supported
49 * @param name A language name, alias or file extension
50 */
51export declare function supportsLanguage(name: string): boolean;
52export default highlight;
53export * from './theme';