index.d.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. * The continuation is an optional mode stack representing unfinished parsing. When present,
  17. * the function will restart parsing from this state instead of initializing a new one.
  18. *
  19. * See http://highlightjs.readthedocs.io/en/latest/api.html
  20. */
  21. continuation?: any;
  22. /**
  23. * Optional array of language names and aliases restricting detection to only those languages.
  24. */
  25. languageSubset?: string[];
  26. /**
  27. * Supply a custom theme where you override language tokens with own formatter functions. Every
  28. * token that is not overriden falls back to the [[DEFAULT_THEME]]
  29. */
  30. theme?: Theme;
  31. }
  32. /**
  33. * Apply syntax highlighting to `code` with ASCII color codes. The language is automatically
  34. * detected if not set.
  35. *
  36. * ```ts
  37. * import {highlight} from 'cli-highlight';
  38. * import * as fs from 'fs';
  39. *
  40. * fs.readFile('package.json', 'utf8', (err: any, json: string) => {
  41. * console.log('package.json:');
  42. * console.log(highlight(json));
  43. * });
  44. * ```
  45. *
  46. * @param code The code to highlight
  47. * @param options Optional options
  48. */
  49. export declare function highlight(code: string, options?: HighlightOptions): string;
  50. /**
  51. * Returns all supported languages
  52. */
  53. export declare function listLanguages(): string[];
  54. /**
  55. * Returns true if the language is supported
  56. * @param name A language name, alias or file extension
  57. */
  58. export declare function supportsLanguage(name: string): boolean;
  59. export default highlight;
  60. export * from './theme';