Skip to content

Commit 6567cbd

Browse files
committed
wip
1 parent 02fd993 commit 6567cbd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+896
-126
lines changed

.eslintrc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ module.exports = {
1717
"ecmaVersion": 2018,
1818
"sourceType": "module"
1919
},
20+
"parser": '@typescript-eslint/parser',
21+
"plugins": [
22+
"@typescript-eslint"
23+
],
2024
"rules": {
2125
"array-callback-return": "error",
2226
"block-scoped-var": "error",
@@ -27,7 +31,7 @@ module.exports = {
2731
// for now ignore diff between types of quoting
2832
"quotes": "off",
2933
// this is the style we are already using
30-
"operator-linebreak": ["error","after", { "overrides": { "?": "after", ":": "after" } }],
34+
"operator-linebreak": ["error","before", { "overrides": { "?": "after", ":": "after", "+": "after" } }],
3135
// sometimes we declare variables with extra spacing
3236
"indent": ["error", 2, {"VariableDeclarator":2}],
3337
// seems like a good idea not to use explicit undefined

global.d.ts

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

0 commit comments

Comments
 (0)