highlight.js

  • Version 11.11.1
  • Published
  • 5.43 MB
  • No dependencies
  • BSD-3-Clause license

Install

npm i highlight.js
yarn add highlight.js
pnpm add highlight.js

Overview

Syntax highlighting with language autodetection.

Index

Namespaces

namespace highlight.js

module 'highlight.js' {}

    variable hljs

    const hljs: HLJSApi;

      interface AutoHighlightResult

      interface AutoHighlightResult extends HighlightResult {}

        interface CallbackResponse

        interface CallbackResponse {}

          property data

          data: Record<string, any>;

            property ignoreMatch

            ignoreMatch: () => void;

              property isMatchIgnored

              isMatchIgnored: boolean;

                interface CompiledLanguage

                interface CompiledLanguage extends LanguageDetail, CompiledMode {}

                  property contains

                  contains: CompiledMode[];

                    property isCompiled

                    isCompiled: true;

                      property keywords

                      keywords: Record<string, any>;

                        interface Emitter

                        interface Emitter {}

                          method addText

                          addText: (text: string) => void;

                            method endScope

                            endScope: () => void;

                              method finalize

                              finalize: () => void;

                                method startScope

                                startScope: (name: string) => void;

                                  method toHTML

                                  toHTML: () => string;

                                    interface HighlightOptions

                                    interface HighlightOptions {}

                                      property ignoreIllegals

                                      ignoreIllegals?: boolean;

                                        property language

                                        language: string;

                                          interface HighlightResult

                                          interface HighlightResult {}

                                            property code

                                            code?: string;

                                              property errorRaised

                                              errorRaised?: Error;

                                                property illegal

                                                illegal: boolean;

                                                  property language

                                                  language?: string;

                                                    property relevance

                                                    relevance: number;

                                                      property secondBest

                                                      secondBest?: Omit<HighlightResult, 'second_best'>;

                                                        property value

                                                        value: string;

                                                          interface HLJSOptions

                                                          interface HLJSOptions {}

                                                            property classPrefix

                                                            classPrefix: string;

                                                              property cssSelector

                                                              cssSelector: string;

                                                                property ignoreUnescapedHTML

                                                                ignoreUnescapedHTML?: boolean;

                                                                  property languageDetectRe

                                                                  languageDetectRe: RegExp;

                                                                    property languages

                                                                    languages?: string[];

                                                                      property noHighlightRe

                                                                      noHighlightRe: RegExp;

                                                                        property throwUnescapedHTML

                                                                        throwUnescapedHTML?: boolean;

                                                                          interface illegalData

                                                                          interface illegalData {}

                                                                            property context

                                                                            context: string;

                                                                              property index

                                                                              index: number;

                                                                                property message

                                                                                message: string;

                                                                                  property mode

                                                                                  mode: CompiledMode;

                                                                                    property resultSoFar

                                                                                    resultSoFar: string;

                                                                                      interface LanguageDetail

                                                                                      interface LanguageDetail {}

                                                                                        property aliases

                                                                                        aliases?: string[];

                                                                                          property case_insensitive

                                                                                          case_insensitive?: boolean;

                                                                                            property classNameAliases

                                                                                            classNameAliases?: Record<string, string>;

                                                                                              property compilerExtensions

                                                                                              compilerExtensions?: CompilerExt[];

                                                                                                property contains

                                                                                                contains: Mode[];

                                                                                                  property disableAutodetect

                                                                                                  disableAutodetect?: boolean;

                                                                                                    property exports

                                                                                                    exports?: any;

                                                                                                      property isCompiled

                                                                                                      isCompiled?: boolean;

                                                                                                        property keywords

                                                                                                        keywords?: string | string[] | Record<string, string | string[] | RegExp>;

                                                                                                          property name

                                                                                                          name?: string;

                                                                                                            property rawDefinition

                                                                                                            rawDefinition?: () => Language;

                                                                                                              property supersetOf

                                                                                                              supersetOf?: string;

                                                                                                                property unicodeRegex

                                                                                                                unicodeRegex?: boolean;

                                                                                                                  interface Mode

                                                                                                                  interface Mode extends ModeCallbacks, ModeDetails {}

                                                                                                                    interface VuePlugin

                                                                                                                    interface VuePlugin {}

                                                                                                                      property install

                                                                                                                      install: (vue: any) => void;

                                                                                                                        type BeforeHighlightContext

                                                                                                                        type BeforeHighlightContext = {
                                                                                                                        code: string;
                                                                                                                        language: string;
                                                                                                                        result?: HighlightResult;
                                                                                                                        };

                                                                                                                          type CompiledMode

                                                                                                                          type CompiledMode = Omit<Mode, 'contains'> & {
                                                                                                                          begin?: RegExp | string;
                                                                                                                          end?: RegExp | string;
                                                                                                                          scope?: string;
                                                                                                                          contains: CompiledMode[];
                                                                                                                          keywords: KeywordDict;
                                                                                                                          data: Record<string, any>;
                                                                                                                          terminatorEnd: string;
                                                                                                                          keywordPatternRe: RegExp;
                                                                                                                          beginRe: RegExp;
                                                                                                                          endRe: RegExp;
                                                                                                                          illegalRe: RegExp;
                                                                                                                          matcher: any;
                                                                                                                          isCompiled: true;
                                                                                                                          starts?: CompiledMode;
                                                                                                                          parent?: CompiledMode;
                                                                                                                          beginScope?: CompiledScope;
                                                                                                                          endScope?: CompiledScope;
                                                                                                                          };

                                                                                                                            type CompiledScope

                                                                                                                            type CompiledScope = Record<number, string> & {
                                                                                                                            _emit?: Record<number, boolean>;
                                                                                                                            _multi?: boolean;
                                                                                                                            _wrap?: string;
                                                                                                                            };

                                                                                                                              type CompilerExt

                                                                                                                              type CompilerExt = (mode: Mode, parent: Mode | Language | null) => void;

                                                                                                                                type HighlightedHTMLElement

                                                                                                                                type HighlightedHTMLElement = HTMLElement & {
                                                                                                                                result?: object;
                                                                                                                                secondBest?: object;
                                                                                                                                parentNode: HTMLElement;
                                                                                                                                };

                                                                                                                                  type HLJSApi

                                                                                                                                  type HLJSApi = PublicApi & ModesAPI;

                                                                                                                                    type HLJSPlugin

                                                                                                                                    type HLJSPlugin = {
                                                                                                                                    'after:highlight'?: (result: HighlightResult) => void;
                                                                                                                                    'before:highlight'?: (context: BeforeHighlightContext) => void;
                                                                                                                                    'after:highlightElement'?: (data: {
                                                                                                                                    el: Element;
                                                                                                                                    result: HighlightResult;
                                                                                                                                    text: string;
                                                                                                                                    }) => void;
                                                                                                                                    'before:highlightElement'?: (data: { el: Element; language: string }) => void;
                                                                                                                                    // TODO: Old API, remove with v12
                                                                                                                                    'after:highlightBlock'?: (data: {
                                                                                                                                    block: Element;
                                                                                                                                    result: HighlightResult;
                                                                                                                                    text: string;
                                                                                                                                    }) => void;
                                                                                                                                    'before:highlightBlock'?: (data: { block: Element; language: string }) => void;
                                                                                                                                    };

                                                                                                                                      type Language

                                                                                                                                      type Language = LanguageDetail & Partial<Mode>;

                                                                                                                                        type LanguageFn

                                                                                                                                        type LanguageFn = (hljs: HLJSApi) => Language;

                                                                                                                                          type ModeCallback

                                                                                                                                          type ModeCallback = (match: RegExpMatchArray, response: CallbackResponse) => void;

                                                                                                                                            type PluginEvent

                                                                                                                                            type PluginEvent = keyof HLJSPlugin;

                                                                                                                                              namespace highlight.js/lib/languages/*

                                                                                                                                              module 'highlight.js/lib/languages/*' {}

                                                                                                                                                variable defineLanguage

                                                                                                                                                const defineLanguage: LanguageFn;

                                                                                                                                                  namespace highlight.js/private

                                                                                                                                                  module 'highlight.js/private' {}

                                                                                                                                                    type AnnotatedError

                                                                                                                                                    type AnnotatedError = Error & {
                                                                                                                                                    mode?: Mode | Language;
                                                                                                                                                    languageName?: string;
                                                                                                                                                    badRule?: Mode;
                                                                                                                                                    };

                                                                                                                                                      type EnhancedMatch

                                                                                                                                                      type EnhancedMatch = RegExpMatchArray & { rule: CompiledMode; type: MatchType };

                                                                                                                                                        type KeywordData

                                                                                                                                                        type KeywordData = [string, number];

                                                                                                                                                          type KeywordDict

                                                                                                                                                          type KeywordDict = Record<string, KeywordData>;

                                                                                                                                                            type MatchType

                                                                                                                                                            type MatchType = 'begin' | 'end' | 'illegal';

                                                                                                                                                              Package Files (1)

                                                                                                                                                              Dependencies (0)

                                                                                                                                                              No dependencies.

                                                                                                                                                              Dev Dependencies (34)

                                                                                                                                                              Peer Dependencies (0)

                                                                                                                                                              No peer dependencies.

                                                                                                                                                              Badge

                                                                                                                                                              To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                                              You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/highlight.js.

                                                                                                                                                              • Markdown
                                                                                                                                                                [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/highlight.js)
                                                                                                                                                              • HTML
                                                                                                                                                                <a href="https://www.jsdocs.io/package/highlight.js"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>