Skip to content

Commit

Permalink
fix: Import from shiki rather than shiki-themes
Browse files Browse the repository at this point in the history
Resolves #1496
  • Loading branch information
Gerrit0 committed Feb 6, 2021
1 parent 4185854 commit 1c37702
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/lib/output/renderer.ts
Expand Up @@ -9,7 +9,6 @@

import * as Path from "path";
import * as FS from "fs-extra";
import { Theme as ShikiTheme } from "shiki-themes";
// eslint-disable-next-line
const ProgressBar = require("progress");

Expand All @@ -23,7 +22,7 @@ import { DefaultTheme } from "./themes/DefaultTheme";
import { RendererComponent } from "./components";
import { Component, ChildableComponent } from "../utils/component";
import { BindOption } from "../utils";
import { loadHighlighter } from "../utils/highlighter";
import { loadHighlighter, ShikiTheme } from "../utils/highlighter";

/**
* The renderer processes a [[ProjectReflection]] using a [[BaseTheme]] instance and writes
Expand Down
3 changes: 2 additions & 1 deletion src/lib/utils/highlighter.ts
@@ -1,9 +1,10 @@
import { ok as assert } from "assert";
import * as shiki from "shiki";
import { Theme as ShikiTheme } from "shiki-themes";
import { Highlighter } from "shiki/dist/highlighter";
import { unique } from "./array";

export type ShikiTheme = Parameters<typeof import("shiki")["getTheme"]>[0];

// This is needed because Shiki includes some "fake" languages
// ts / js are expected by users to be equivalent to typescript / javascript

Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/options/declaration.ts
@@ -1,5 +1,5 @@
import { ShikiTheme } from "../highlighter";
import { LogLevel } from "../loggers";
import { Theme as ShikiTheme } from "shiki-themes";

/**
* An interface describing all TypeDoc specific options. Generated from a
Expand Down
7 changes: 7 additions & 0 deletions src/lib/utils/options/help.ts
Expand Up @@ -6,6 +6,7 @@ import {
DeclarationOption,
} from "./declaration";
import { getSupportedLanguages } from "../highlighter";
import { BUNDLED_THEMES } from "shiki";

export interface ParameterHelp {
names: string[];
Expand Down Expand Up @@ -94,5 +95,11 @@ export function getOptionsHelp(options: Options): string {
...toEvenColumns(getSupportedLanguages(), 80)
);

output.push(
"",
"Supported highlighting themes:",
...toEvenColumns(BUNDLED_THEMES, 80)
);

return output.join("\n");
}
33 changes: 16 additions & 17 deletions src/lib/utils/options/sources/typedoc.ts
@@ -1,7 +1,7 @@
import { Options } from "..";
import { LogLevel } from "../../loggers";
import { ParameterType, ParameterHint } from "../declaration";
import { BUNDLED_THEMES as ShikiThemes } from "shiki-themes";
import { BUNDLED_THEMES } from "shiki";

export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
options.addDeclaration({
Expand Down Expand Up @@ -121,6 +121,21 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
type: ParameterType.String,
defaultValue: "default",
});
options.addDeclaration({
name: "highlightTheme",
help: "Specifies the code highlighting theme.",
type: ParameterType.String,
defaultValue: "light-plus",
validate: (value: string): void => {
if (!BUNDLED_THEMES.includes(value)) {
throw new Error(
`highlightTheme must be one of the following: ${BUNDLED_THEMES.join(
", "
)}`
);
}
},
});

options.addDeclaration({
name: "name",
Expand Down Expand Up @@ -245,20 +260,4 @@ 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 1c37702

Please sign in to comment.