Skip to content

Commit

Permalink
fix(types) Fix some type definition issues (#3274)
Browse files Browse the repository at this point in the history
* fix(types) begin, match, end all now take arrays

* fix(types) _emit now a scope attribute, not mode attribute

* fix(types) do not forget about endScope

* remove dead code

* fix(types) make hljs not optional

* changelog
  • Loading branch information
joshgoebel committed Jul 23, 2021
1 parent 83ad2fb commit ba8735f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Version 11.2.0 (pending)

Parser:

- fix(types) Fix some type definition issues (#3274) [Josh Goebel][]

[Josh Goebel]: https://github.com/joshgoebel

## Version 11.1.0

Grammars:
Expand Down
2 changes: 1 addition & 1 deletion src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ const HLJS = function(hljs) {
}
}
do {
if (top.scope && !top.isMultiClass) {
if (top.scope) {
emitter.closeNode();
}
if (!top.skip && !top.subLanguage) {
Expand Down
12 changes: 6 additions & 6 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ declare module 'highlight.js' {
RE_STARTERS_RE: string
}

export type LanguageFn = (hljs?: HLJSApi) => Language
export type LanguageFn = (hljs: HLJSApi) => Language
export type CompilerExt = (mode: Mode, parent: Mode | Language | null) => void

export interface HighlightResult {
Expand Down Expand Up @@ -201,21 +201,21 @@ declare module 'highlight.js' {
illegalRe: RegExp
matcher: any
isCompiled: true
isMultiClass?: boolean
starts?: CompiledMode
parent?: CompiledMode
beginScope?: Record<number, string> & {_emit?: Record<number,boolean>, _multi?: boolean, _wrap?: string}
endScope?: Record<number, string> & {_emit?: Record<number,boolean>, _multi?: boolean, _wrap?: string}
}

interface ModeDetails {
begin?: RegExp | string
match?: RegExp | string
end?: RegExp | string
begin?: RegExp | string | (RegExp | string)[]
match?: RegExp | string | (RegExp | string)[]
end?: RegExp | string | (RegExp | string)[]
// deprecated in favor of `scope`
className?: string
_emit?: Record<number, boolean>
scope?: string | Record<number, string>
beginScope?: string | Record<number, string>
endScope?: string | Record<number, string>
contains?: ("self" | Mode)[]
endsParent?: boolean
endsWithParent?: boolean
Expand Down

0 comments on commit ba8735f

Please sign in to comment.