index.d.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { Theme } from './theme';
  2. /**
  3. * Options passed to [[highlight]]
  4. */
  5. export 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. */
  42. export declare function highlight(code: string, options?: HighlightOptions): string;
  43. /**
  44. * Returns all supported languages
  45. */
  46. export declare function listLanguages(): string[];
  47. /**
  48. * Returns true if the language is supported
  49. * @param name A language name, alias or file extension
  50. */
  51. export declare function supportsLanguage(name: string): boolean;
  52. export default highlight;
  53. export * from './theme';