1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | declare const hljs : HLJSApi;
|
8 |
|
9 | type HLJSApi = PublicApi & ModesAPI
|
10 |
|
11 | interface VuePlugin {
|
12 | install: (vue: any) => void
|
13 | }
|
14 |
|
15 | interface PublicApi {
|
16 | highlight: (languageName: string, code: string, ignoreIllegals?: boolean, continuation?: Mode) => HighlightResult
|
17 | highlightAuto: (code: string, languageSubset?: string[]) => AutoHighlightResult
|
18 | fixMarkup: (html: string) => string
|
19 | highlightBlock: (element: HTMLElement) => void
|
20 | configure: (options: Partial<HLJSOptions>) => void
|
21 | initHighlighting: () => void
|
22 | initHighlightingOnLoad: () => void
|
23 | registerLanguage: (languageName: string, language: LanguageFn) => void
|
24 | listLanguages: () => string[]
|
25 | registerAliases: (aliasList: string | string[], { languageName } : {languageName: string}) => void
|
26 | getLanguage: (languageName: string) => Language | undefined
|
27 | requireLanguage: (languageName: string) => Language | never
|
28 | autoDetection: (languageName: string) => boolean
|
29 | inherit: <T>(original: T, ...args: Record<string, any>[]) => T
|
30 | addPlugin: (plugin: HLJSPlugin) => void
|
31 | debugMode: () => void
|
32 | safeMode: () => void
|
33 | versionString: string
|
34 | vuePlugin: () => VuePlugin
|
35 | }
|
36 |
|
37 | interface ModesAPI {
|
38 | SHEBANG: (mode?: Partial<Mode> & {binary?: string | RegExp}) => Mode
|
39 | BACKSLASH_ESCAPE: Mode
|
40 | QUOTE_STRING_MODE: Mode
|
41 | APOS_STRING_MODE: Mode
|
42 | PHRASAL_WORDS_MODE: Mode
|
43 | COMMENT: (begin: string | RegExp, end: string | RegExp, modeOpts?: Mode | {}) => Mode
|
44 | C_LINE_COMMENT_MODE: Mode
|
45 | C_BLOCK_COMMENT_MODE: Mode
|
46 | HASH_COMMENT_MODE: Mode
|
47 | NUMBER_MODE: Mode
|
48 | C_NUMBER_MODE: Mode
|
49 | BINARY_NUMBER_MODE: Mode
|
50 | CSS_NUMBER_MODE: Mode
|
51 | REGEXP_MODE: Mode
|
52 | TITLE_MODE: Mode
|
53 | UNDERSCORE_TITLE_MODE: Mode
|
54 | METHOD_GUARD: Mode
|
55 | END_SAME_AS_BEGIN: (mode: Mode) => Mode
|
56 |
|
57 | IDENT_RE: string
|
58 | UNDERSCORE_IDENT_RE: string
|
59 | NUMBER_RE: string
|
60 | C_NUMBER_RE: string
|
61 | BINARY_NUMBER_RE: string
|
62 | RE_STARTERS_RE: string
|
63 | }
|
64 |
|
65 | type LanguageFn = (hljs?: HLJSApi) => Language
|
66 |
|
67 | interface HighlightResult {
|
68 | relevance : number
|
69 | value : string
|
70 | language? : string
|
71 | emitter : Emitter
|
72 | illegal : boolean
|
73 | top? : Language | CompiledMode
|
74 | illegalBy? : illegalData
|
75 | sofar? : string
|
76 | errorRaised? : Error
|
77 |
|
78 | second_best? : Omit<HighlightResult, 'second_best'>
|
79 | }
|
80 | interface AutoHighlightResult extends HighlightResult {}
|
81 |
|
82 | interface illegalData {
|
83 | msg: string
|
84 | context: string
|
85 | mode: CompiledMode
|
86 | }
|
87 |
|
88 | type PluginEvent =
|
89 | 'before:highlight'
|
90 | | 'after:highlight'
|
91 | | 'before:highlightBlock'
|
92 | | 'after:highlightBlock'
|
93 |
|
94 | type HLJSPlugin = {
|
95 | [K in PluginEvent]? : any
|
96 | }
|
97 |
|
98 | interface EmitterConstructor {
|
99 | new (opts: any): Emitter
|
100 | }
|
101 |
|
102 | interface HLJSOptions {
|
103 | noHighlightRe: RegExp
|
104 | languageDetectRe: RegExp
|
105 | classPrefix: string
|
106 | tabReplace?: string
|
107 | useBR: boolean
|
108 | languages?: string[]
|
109 | __emitter: EmitterConstructor
|
110 | }
|
111 |
|
112 | interface CallbackResponse {
|
113 | data: Record<string, any>
|
114 | ignoreMatch: () => void
|
115 | }
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 | type AnnotatedError = Error & {mode?: Mode | Language, languageName?: string, badRule?: Mode}
|
124 |
|
125 | type ModeCallback = (match: RegExpMatchArray, response: CallbackResponse) => void
|
126 | type HighlightedHTMLElement = HTMLElement & {result?: object, second_best?: object, parentNode: HTMLElement}
|
127 | type EnhancedMatch = RegExpMatchArray & {rule: CompiledMode, type: MatchType}
|
128 | type MatchType = "begin" | "end" | "illegal"
|
129 |
|
130 | interface Emitter {
|
131 | addKeyword(text: string, kind: string): void
|
132 | addText(text: string): void
|
133 | toHTML(): string
|
134 | finalize(): void
|
135 | closeAllNodes(): void
|
136 | openNode(kind: string): void
|
137 | closeNode(): void
|
138 | addSublanguage(emitter: Emitter, subLanguageName: string): void
|
139 | }
|
140 |
|
141 |
|
142 |
|
143 | interface ModeCallbacks {
|
144 | "on:end"?: Function,
|
145 | "on:begin"?: Function,
|
146 | }
|
147 |
|
148 | interface Mode extends ModeCallbacks, ModeDetails {
|
149 |
|
150 | }
|
151 |
|
152 | interface LanguageDetail {
|
153 | name?: string
|
154 | rawDefinition?: () => Language
|
155 | aliases?: string[]
|
156 | disableAutodetect?: boolean
|
157 | contains: (Mode)[]
|
158 | case_insensitive?: boolean
|
159 | keywords?: Record<string, any> | string
|
160 | compiled?: boolean,
|
161 | exports?: any
|
162 | }
|
163 |
|
164 | type Language = LanguageDetail & Partial<Mode>
|
165 |
|
166 | interface CompiledLanguage extends LanguageDetail, CompiledMode {
|
167 | compiled: true
|
168 | contains: CompiledMode[]
|
169 | keywords: Record<string, any>
|
170 | }
|
171 |
|
172 | type KeywordData = [string, number];
|
173 | type KeywordDict = Record<string, KeywordData>
|
174 |
|
175 | type CompiledMode = Omit<Mode, 'contains'> &
|
176 | {
|
177 | contains: CompiledMode[]
|
178 | keywords: KeywordDict
|
179 | data: Record<string, any>
|
180 | terminator_end: string
|
181 | keywordPatternRe: RegExp
|
182 | beginRe: RegExp
|
183 | endRe: RegExp
|
184 | illegalRe: RegExp
|
185 | matcher: any
|
186 | compiled: true
|
187 | starts?: CompiledMode
|
188 | parent?: CompiledMode
|
189 | }
|
190 |
|
191 | interface ModeDetails {
|
192 | begin?: RegExp | string
|
193 | end?: RegExp | string
|
194 | className?: string
|
195 | contains?: ("self" | Mode)[]
|
196 | endsParent?: boolean
|
197 | endsWithParent?: boolean
|
198 | endSameAsBegin?: boolean
|
199 | skip?: boolean
|
200 | excludeBegin?: boolean
|
201 | excludeEnd?: boolean
|
202 | returnBegin?: boolean
|
203 | returnEnd?: boolean
|
204 | __beforeBegin?: Function
|
205 | parent?: Mode
|
206 | starts?:Mode
|
207 | lexemes?: string | RegExp
|
208 | keywords?: Record<string, any> | string
|
209 | beginKeywords?: string
|
210 | relevance?: number
|
211 | illegal?: string | RegExp
|
212 | variants?: Mode[]
|
213 | cached_variants?: Mode[]
|
214 |
|
215 | subLanguage?: string | string[]
|
216 | compiled?: boolean
|
217 | label?: string
|
218 | }
|
219 |
|
220 |
|
221 |
|
222 |
|
223 | declare module 'highlight.js' {
|
224 | export = hljs;
|
225 | }
|
226 |
|
227 | declare module 'highlight.js/lib/core' {
|
228 | export = hljs;
|
229 | }
|
230 |
|
231 | declare module 'highlight.js/lib/core.js' {
|
232 | export = hljs;
|
233 | }
|
234 |
|
235 | declare module 'highlight.js/lib/languages/*' {
|
236 | export default function(hljs?: HLJSApi): LanguageDetail;
|
237 | }
|