diff --git a/src/lib/utils/highlighter.ts b/src/lib/utils/highlighter.ts index 9f2db7463..d8f75bf5f 100644 --- a/src/lib/utils/highlighter.ts +++ b/src/lib/utils/highlighter.ts @@ -1,6 +1,6 @@ import { ok as assert } from "assert"; import * as shiki from "shiki"; -import { Theme } from "shiki-themes"; +import { Theme as ShikiTheme } from "shiki-themes"; import { Highlighter } from "shiki/dist/highlighter"; import { unique } from "./array"; @@ -23,10 +23,10 @@ const supportedLanguages = unique([ let highlighter: Highlighter | undefined; -export async function loadHighlighter(theme: Theme) { +export async function loadHighlighter(theme: ShikiTheme) { if (highlighter) return; highlighter = await shiki.getHighlighter({ - theme: theme || "light-plus", + theme, }); } diff --git a/src/lib/utils/options/declaration.ts b/src/lib/utils/options/declaration.ts index 2891aba72..301e8f1ff 100644 --- a/src/lib/utils/options/declaration.ts +++ b/src/lib/utils/options/declaration.ts @@ -1,4 +1,5 @@ import { LogLevel } from "../loggers"; +import { Theme as ShikiTheme } from "shiki-themes"; /** * An interface describing all TypeDoc specific options. Generated from a @@ -80,7 +81,7 @@ export interface TypeDocOptionMap { listInvalidSymbolLinks: boolean; markedOptions: unknown; - highlightTheme: string; + highlightTheme: ShikiTheme; } /** diff --git a/src/lib/utils/options/sources/typedoc.ts b/src/lib/utils/options/sources/typedoc.ts index 80e4be18c..cb6b66e0e 100644 --- a/src/lib/utils/options/sources/typedoc.ts +++ b/src/lib/utils/options/sources/typedoc.ts @@ -1,6 +1,7 @@ import { Options } from ".."; import { LogLevel } from "../../loggers"; import { ParameterType, ParameterHint } from "../declaration"; +import { BUNDLED_THEMES as ShikiThemes } from "shiki-themes"; export function addTypeDocOptions(options: Pick) { options.addDeclaration({ @@ -244,9 +245,20 @@ export function addTypeDocOptions(options: Pick) { "Specify the options passed to Marked, the Markdown parser used by TypeDoc", type: ParameterType.Mixed, }); + options.addDeclaration({ name: "highlightTheme", help: "Specifies the code highlighting theme.", type: ParameterType.String, + defaultValue: "light-plus", + validate: (value: string): void => { + if (!ShikiThemes.includes(value)) { + throw new Error( + `Highlight Theme must be one of the following: ${ShikiThemes.join( + ", " + )}` + ); + } + }, }); }