Skip to content

Commit

Permalink
Support language aliases in highlightLanguages
Browse files Browse the repository at this point in the history
Resolves #2798
  • Loading branch information
Gerrit0 committed Dec 4, 2024
1 parent 2b84c16 commit 2741645
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ title: Changelog
- Add special handling for import types with type errors discarded with ts-expect-error, #2792.
- Improved support for hosting TypeDoc with strict Content Security Policy rules, #2794.
- Fixed low contrast in default colors for properties/accessors in light mode, #2795.
- The `highlightLanguages` option now permits Shiki aliases to be specified rather than just the language ID, #2798.

### Thanks!

Expand Down
8 changes: 0 additions & 8 deletions src/lib/utils/highlighter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ for (const lang of shiki.bundledLanguagesInfo) {

const plaintextLanguages = ["txt", "text"];

const supportedLanguagesWithoutAliases = unique([
...plaintextLanguages,
...shiki.bundledLanguagesInfo.map((lang) => lang.id),
]);
const supportedLanguages: string[] = unique([
...plaintextLanguages,
...aliases.keys(),
Expand Down Expand Up @@ -149,10 +145,6 @@ export function getSupportedLanguages(): string[] {
return supportedLanguages;
}

export function getSupportedLanguagesWithoutAliases(): string[] {
return supportedLanguagesWithoutAliases;
}

export function getSupportedThemes(): string[] {
return supportedThemes;
}
Expand Down
7 changes: 2 additions & 5 deletions src/lib/utils/options/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import {
ParameterType,
type DeclarationOption,
} from "./declaration.js";
import {
getSupportedLanguagesWithoutAliases,
getSupportedThemes,
} from "../highlighter.js";
import { getSupportedLanguages, getSupportedThemes } from "../highlighter.js";
import type { TranslationProxy } from "../../internationalization/internationalization.js";

export interface ParameterHelp {
Expand Down Expand Up @@ -105,7 +102,7 @@ export function getOptionsHelp(
output.push(
"",
"Supported highlighting languages:",
...toEvenColumns(getSupportedLanguagesWithoutAliases(), 80),
...toEvenColumns(getSupportedLanguages(), 80),
);

output.push(
Expand Down
7 changes: 2 additions & 5 deletions src/lib/utils/options/sources/typedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { blockTags, inlineTags, modifierTags } from "../tsdoc-defaults.js";
import { getEnumKeys } from "../../enum.js";
import type { BundledTheme } from "@gerrit0/mini-shiki";
import {
getSupportedLanguagesWithoutAliases,
getSupportedLanguages,
getSupportedThemes,
} from "../../highlighter.js";
import { setDifference } from "../../set.js";
Expand Down Expand Up @@ -356,10 +356,7 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
type: ParameterType.Array,
defaultValue: OptionDefaults.highlightLanguages,
validate(value, i18n) {
const invalid = setDifference(
value,
getSupportedLanguagesWithoutAliases(),
);
const invalid = setDifference(value, getSupportedLanguages());
if (invalid.size) {
throw new Error(
i18n.highlightLanguages_contains_invalid_languages_0(
Expand Down
13 changes: 10 additions & 3 deletions src/test/utils/options/default-options.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ok, throws, strictEqual, doesNotThrow } from "assert";
import { ok, throws, deepStrictEqual as equal, doesNotThrow } from "assert";
import { Options } from "../../../lib/utils/index.js";
import { Internationalization } from "../../../lib/internationalization/internationalization.js";

Expand All @@ -11,13 +11,20 @@ describe("Default Options", () => {
opts.setValue("lightHighlightTheme", "randomTheme" as never),
);
opts.setValue("lightHighlightTheme", "github-light");
strictEqual(opts.getValue("lightHighlightTheme"), "github-light");
equal(opts.getValue("lightHighlightTheme"), "github-light");

throws(() =>
opts.setValue("darkHighlightTheme", "randomTheme" as never),
);
opts.setValue("darkHighlightTheme", "github-light");
strictEqual(opts.getValue("darkHighlightTheme"), "github-light");
equal(opts.getValue("darkHighlightTheme"), "github-light");
});
});

describe("highlightLanguages", () => {
it("Supports aliased languages", () => {
opts.setValue("highlightLanguages", ["bash"]);
equal(opts.getValue("highlightLanguages"), ["bash"]);
});
});

Expand Down

0 comments on commit 2741645

Please sign in to comment.