From 4a6df9ad86da346ef8d66d1d5b2138158d9be12a Mon Sep 17 00:00:00 2001 From: Matthias Law Date: Wed, 27 Jan 2021 12:14:55 +1300 Subject: [PATCH] feat: add highlight theme option --- src/lib/output/renderer.ts | 6 +++++- src/lib/utils/highlighter.ts | 5 +++-- src/lib/utils/options/declaration.ts | 2 ++ src/lib/utils/options/sources/typedoc.ts | 6 ++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/lib/output/renderer.ts b/src/lib/output/renderer.ts index 0d3bb5a14..a2bf058c2 100644 --- a/src/lib/output/renderer.ts +++ b/src/lib/output/renderer.ts @@ -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"); @@ -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. * @@ -93,7 +97,7 @@ export class Renderer extends ChildableComponent< project: ProjectReflection, outputDirectory: string ): Promise { - await loadHighlighter(); + await loadHighlighter(this.highlightTheme); if ( !this.prepareTheme() || !this.prepareOutputDirectory(outputDirectory) diff --git a/src/lib/utils/highlighter.ts b/src/lib/utils/highlighter.ts index 8d194de26..9f2db7463 100644 --- a/src/lib/utils/highlighter.ts +++ b/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"; @@ -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", }); } diff --git a/src/lib/utils/options/declaration.ts b/src/lib/utils/options/declaration.ts index 671ea192b..2891aba72 100644 --- a/src/lib/utils/options/declaration.ts +++ b/src/lib/utils/options/declaration.ts @@ -79,6 +79,8 @@ export interface TypeDocOptionMap { logLevel: typeof LogLevel; listInvalidSymbolLinks: boolean; markedOptions: unknown; + + highlightTheme: string; } /** diff --git a/src/lib/utils/options/sources/typedoc.ts b/src/lib/utils/options/sources/typedoc.ts index cd848660b..80e4be18c 100644 --- a/src/lib/utils/options/sources/typedoc.ts +++ b/src/lib/utils/options/sources/typedoc.ts @@ -120,6 +120,7 @@ export function addTypeDocOptions(options: Pick) { type: ParameterType.String, defaultValue: "default", }); + options.addDeclaration({ name: "name", help: @@ -243,4 +244,9 @@ 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, + }); }