Skip to content

Commit

Permalink
fix(types): separate out deprecated highlight overload (#3987)
Browse files Browse the repository at this point in the history
Minor thing in the type definitions I noticed. The .js makes it clear that the old API looks like `highlight(lang, code, ignoreIllegals)`, and the new API looks like `highlight(code, {lang, ignoreIllegals})`.

The types on the other hand imply you could do things like `highlight(code, {lang: ...}, true)` - but that `true` would be ignored at runtime.

So this separates the two forms into function overloads, and adds a `/** @deprecated */` tag to the old form so IDEs will hint not to use it.
  • Loading branch information
mmkal authored Feb 20, 2024
1 parent 4b45a2b commit 8e61102
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Developer Tool:

- enh(tools): order CSS options picklist [David Schach][]
- enh(tools): remove duplicate CSS options [David Schach][]
- (typescript): deprecate old `highlight` API [Misha Kaletsky][]

Themes:

Expand Down Expand Up @@ -279,6 +280,7 @@ Grammars:
[Mousetail]: https://github.com/mousetail
[Gabriel Gonçalves]: https://github.com/KTSnowy
[Nikita Sobolev]: https://github.com/sobolevn
[Misha Kaletsky]: https://github.com/mmkal

## Version 11.5.0

Expand Down
4 changes: 3 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ declare module 'highlight.js' {
}

interface PublicApi {
highlight: (codeOrLanguageName: string, optionsOrCode: string | HighlightOptions, ignoreIllegals?: boolean) => HighlightResult
highlight(code: string, options: HighlightOptions): HighlightResult
/** @deprecated use `higlight(code, {lang: ..., ignoreIllegals: ...})` */
highlight(languageName: string, code: string, ignoreIllegals?: boolean): HighlightResult
highlightAuto: (code: string, languageSubset?: string[]) => AutoHighlightResult
highlightBlock: (element: HTMLElement) => void
highlightElement: (element: HTMLElement) => void
Expand Down

0 comments on commit 8e61102

Please sign in to comment.