Skip to content

Commit

Permalink
fix: add validation to highlightTheme option
Browse files Browse the repository at this point in the history
  • Loading branch information
nzmattman authored and Gerrit0 committed Jan 29, 2021
1 parent 4a6df9a commit 7723ddf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/lib/utils/highlighter.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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,
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/lib/utils/options/declaration.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -80,7 +81,7 @@ export interface TypeDocOptionMap {
listInvalidSymbolLinks: boolean;
markedOptions: unknown;

highlightTheme: string;
highlightTheme: ShikiTheme;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/lib/utils/options/sources/typedoc.ts
Original file line number Diff line number Diff line change
@@ -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">) {
options.addDeclaration({
Expand Down Expand Up @@ -244,9 +245,20 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
"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(
", "
)}`
);
}
},
});
}

0 comments on commit 7723ddf

Please sign in to comment.