source: node_modules/highlight.js/types/index.d.ts

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 7.2 KB
Line 
1/* eslint-disable no-unused-vars */
2/* eslint-disable no-use-before-define */
3// For TS consumers who use Node and don't have dom in their tsconfig lib, import the necessary types here.
4/// <reference lib="dom" />
5
6/* Public API */
7
8// eslint-disable-next-line
9declare const hljs : HLJSApi;
10
11type HLJSApi = PublicApi & ModesAPI
12
13interface VuePlugin {
14 install: (vue: any) => void
15}
16
17interface PublicApi {
18 highlight: (codeOrlanguageName: string, optionsOrCode: string | HighlightOptions, ignoreIllegals?: boolean, continuation?: Mode) => HighlightResult
19 highlightAuto: (code: string, languageSubset?: string[]) => AutoHighlightResult
20 fixMarkup: (html: string) => string
21 highlightBlock: (element: HTMLElement) => void
22 highlightElement: (element: HTMLElement) => void
23 configure: (options: Partial<HLJSOptions>) => void
24 initHighlighting: () => void
25 initHighlightingOnLoad: () => void
26 highlightAll: () => void
27 registerLanguage: (languageName: string, language: LanguageFn) => void
28 unregisterLanguage: (languageName: string) => void
29 listLanguages: () => string[]
30 registerAliases: (aliasList: string | string[], { languageName } : {languageName: string}) => void
31 getLanguage: (languageName: string) => Language | undefined
32 requireLanguage: (languageName: string) => Language | never
33 autoDetection: (languageName: string) => boolean
34 inherit: <T>(original: T, ...args: Record<string, any>[]) => T
35 addPlugin: (plugin: HLJSPlugin) => void
36 debugMode: () => void
37 safeMode: () => void
38 versionString: string
39 vuePlugin: () => VuePlugin
40}
41
42interface ModesAPI {
43 SHEBANG: (mode?: Partial<Mode> & {binary?: string | RegExp}) => Mode
44 BACKSLASH_ESCAPE: Mode
45 QUOTE_STRING_MODE: Mode
46 APOS_STRING_MODE: Mode
47 PHRASAL_WORDS_MODE: Mode
48 COMMENT: (begin: string | RegExp, end: string | RegExp, modeOpts?: Mode | {}) => Mode
49 C_LINE_COMMENT_MODE: Mode
50 C_BLOCK_COMMENT_MODE: Mode
51 HASH_COMMENT_MODE: Mode
52 NUMBER_MODE: Mode
53 C_NUMBER_MODE: Mode
54 BINARY_NUMBER_MODE: Mode
55 CSS_NUMBER_MODE: Mode
56 REGEXP_MODE: Mode
57 TITLE_MODE: Mode
58 UNDERSCORE_TITLE_MODE: Mode
59 METHOD_GUARD: Mode
60 END_SAME_AS_BEGIN: (mode: Mode) => Mode
61 // built in regex
62 IDENT_RE: string
63 UNDERSCORE_IDENT_RE: string
64 MATCH_NOTHING_RE: string
65 NUMBER_RE: string
66 C_NUMBER_RE: string
67 BINARY_NUMBER_RE: string
68 RE_STARTERS_RE: string
69}
70
71type LanguageFn = (hljs?: HLJSApi) => Language
72type CompilerExt = (mode: Mode, parent: Mode | Language | null) => void
73
74interface HighlightResult {
75 relevance : number
76 value : string
77 language? : string
78 emitter : Emitter
79 illegal : boolean
80 top? : Language | CompiledMode
81 illegalBy? : illegalData
82 sofar? : string
83 errorRaised? : Error
84 // * for auto-highlight
85 second_best? : Omit<HighlightResult, 'second_best'>
86 code?: string
87}
88interface AutoHighlightResult extends HighlightResult {}
89
90interface illegalData {
91 msg: string
92 context: string
93 mode: CompiledMode
94}
95
96type BeforeHighlightContext = {
97 code: string,
98 language: string,
99 result?: HighlightResult
100}
101type PluginEvent = keyof HLJSPlugin;
102type HLJSPlugin = {
103 'after:highlight'?: (result: HighlightResult) => void,
104 'before:highlight'?: (context: BeforeHighlightContext) => void,
105 'after:highlightElement'?: (data: { el: Element, result: HighlightResult, text: string}) => void,
106 'before:highlightElement'?: (data: { el: Element, language: string}) => void,
107 // TODO: Old API, remove with v12
108 'after:highlightBlock'?: (data: { block: Element, result: HighlightResult, text: string}) => void,
109 'before:highlightBlock'?: (data: { block: Element, language: string}) => void,
110}
111
112interface EmitterConstructor {
113 new (opts: any): Emitter
114}
115
116interface HighlightOptions {
117 language: string
118 ignoreIllegals?: boolean
119}
120
121interface HLJSOptions {
122 noHighlightRe: RegExp
123 languageDetectRe: RegExp
124 classPrefix: string
125 tabReplace?: string
126 useBR: boolean
127 languages?: string[]
128 __emitter: EmitterConstructor
129}
130
131interface CallbackResponse {
132 data: Record<string, any>
133 ignoreMatch: () => void
134 isMatchIgnored: boolean
135}
136
137/************
138 PRIVATE API
139 ************/
140
141/* for jsdoc annotations in the JS source files */
142
143type AnnotatedError = Error & {mode?: Mode | Language, languageName?: string, badRule?: Mode}
144
145type ModeCallback = (match: RegExpMatchArray, response: CallbackResponse) => void
146type HighlightedHTMLElement = HTMLElement & {result?: object, second_best?: object, parentNode: HTMLElement}
147type EnhancedMatch = RegExpMatchArray & {rule: CompiledMode, type: MatchType}
148type MatchType = "begin" | "end" | "illegal"
149
150 interface Emitter {
151 addKeyword(text: string, kind: string): void
152 addText(text: string): void
153 toHTML(): string
154 finalize(): void
155 closeAllNodes(): void
156 openNode(kind: string): void
157 closeNode(): void
158 addSublanguage(emitter: Emitter, subLanguageName: string): void
159 }
160
161/* modes */
162
163 interface ModeCallbacks {
164 "on:end"?: Function,
165 "on:begin"?: ModeCallback
166 }
167
168interface Mode extends ModeCallbacks, ModeDetails {
169
170}
171
172interface LanguageDetail {
173 name?: string
174 rawDefinition?: () => Language
175 aliases?: string[]
176 disableAutodetect?: boolean
177 contains: (Mode)[]
178 case_insensitive?: boolean
179 keywords?: Record<string, any> | string
180 isCompiled?: boolean,
181 exports?: any,
182 classNameAliases?: Record<string, string>
183 compilerExtensions?: CompilerExt[]
184 supersetOf?: string
185}
186
187type Language = LanguageDetail & Partial<Mode>
188
189interface CompiledLanguage extends LanguageDetail, CompiledMode {
190 isCompiled: true
191 contains: CompiledMode[]
192 keywords: Record<string, any>
193}
194
195type KeywordData = [string, number];
196type KeywordDict = Record<string, KeywordData>
197
198type CompiledMode = Omit<Mode, 'contains'> &
199 {
200 contains: CompiledMode[]
201 keywords: KeywordDict
202 data: Record<string, any>
203 terminatorEnd: string
204 keywordPatternRe: RegExp
205 beginRe: RegExp
206 endRe: RegExp
207 illegalRe: RegExp
208 matcher: any
209 isCompiled: true
210 starts?: CompiledMode
211 parent?: CompiledMode
212 }
213
214interface ModeDetails {
215 begin?: RegExp | string
216 match?: RegExp | string
217 end?: RegExp | string
218 className?: string
219 contains?: ("self" | Mode)[]
220 endsParent?: boolean
221 endsWithParent?: boolean
222 endSameAsBegin?: boolean
223 skip?: boolean
224 excludeBegin?: boolean
225 excludeEnd?: boolean
226 returnBegin?: boolean
227 returnEnd?: boolean
228 __beforeBegin?: Function
229 parent?: Mode
230 starts?:Mode
231 lexemes?: string | RegExp
232 keywords?: Record<string, any> | string
233 beginKeywords?: string
234 relevance?: number
235 illegal?: string | RegExp | Array<string | RegExp>
236 variants?: Mode[]
237 cachedVariants?: Mode[]
238 // parsed
239 subLanguage?: string | string[]
240 isCompiled?: boolean
241 label?: string
242}
243
244// deprecated API since v10
245// declare module 'highlight.js/lib/highlight.js';
246
247declare module 'highlight.js' {
248 export = hljs;
249}
250
251declare module 'highlight.js/lib/core' {
252 export = hljs;
253}
254
255declare module 'highlight.js/lib/core.js' {
256 export = hljs;
257}
258
259declare module 'highlight.js/lib/languages/*' {
260 export default function(hljs?: HLJSApi): LanguageDetail;
261}
Note: See TracBrowser for help on using the repository browser.