Skip to content

Commit

Permalink
feat: add highlight theme 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 73071b5 commit 4a6df9a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/lib/output/renderer.ts
Expand Up @@ -9,6 +9,7 @@

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 Down Expand Up @@ -83,6 +84,9 @@ export class Renderer extends ChildableComponent<
@BindOption("toc")
toc!: string[];

@BindOption("highlightTheme")
highlightTheme!: ShikiTheme;

/**
* Render the given project reflection to the specified output directory.
*
Expand All @@ -93,7 +97,7 @@ export class Renderer extends ChildableComponent<
project: ProjectReflection,
outputDirectory: string
): Promise<void> {
await loadHighlighter();
await loadHighlighter(this.highlightTheme);
if (
!this.prepareTheme() ||
!this.prepareOutputDirectory(outputDirectory)
Expand Down
5 changes: 3 additions & 2 deletions src/lib/utils/highlighter.ts
@@ -1,5 +1,6 @@
import { ok as assert } from "assert";
import * as shiki from "shiki";
import { Theme } from "shiki-themes";
import { Highlighter } from "shiki/dist/highlighter";
import { unique } from "./array";

Expand All @@ -22,10 +23,10 @@ const supportedLanguages = unique([

let highlighter: Highlighter | undefined;

export async function loadHighlighter() {
export async function loadHighlighter(theme: Theme) {
if (highlighter) return;
highlighter = await shiki.getHighlighter({
theme: "light-plus",
theme: theme || "light-plus",
});
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib/utils/options/declaration.ts
Expand Up @@ -79,6 +79,8 @@ export interface TypeDocOptionMap {
logLevel: typeof LogLevel;
listInvalidSymbolLinks: boolean;
markedOptions: unknown;

highlightTheme: string;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/lib/utils/options/sources/typedoc.ts
Expand Up @@ -120,6 +120,7 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
type: ParameterType.String,
defaultValue: "default",
});

options.addDeclaration({
name: "name",
help:
Expand Down Expand Up @@ -243,4 +244,9 @@ 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,
});
}

0 comments on commit 4a6df9a

Please sign in to comment.