Skip to content

Commit 2741645

Browse files
committed
Support language aliases in highlightLanguages
Resolves #2798
1 parent 2b84c16 commit 2741645

File tree

5 files changed

+15
-21
lines changed

5 files changed

+15
-21
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ title: Changelog
99
- Add special handling for import types with type errors discarded with ts-expect-error, #2792.
1010
- Improved support for hosting TypeDoc with strict Content Security Policy rules, #2794.
1111
- Fixed low contrast in default colors for properties/accessors in light mode, #2795.
12+
- The `highlightLanguages` option now permits Shiki aliases to be specified rather than just the language ID, #2798.
1213

1314
### Thanks!
1415

src/lib/utils/highlighter.tsx

-8
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ for (const lang of shiki.bundledLanguagesInfo) {
1313

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

16-
const supportedLanguagesWithoutAliases = unique([
17-
...plaintextLanguages,
18-
...shiki.bundledLanguagesInfo.map((lang) => lang.id),
19-
]);
2016
const supportedLanguages: string[] = unique([
2117
...plaintextLanguages,
2218
...aliases.keys(),
@@ -149,10 +145,6 @@ export function getSupportedLanguages(): string[] {
149145
return supportedLanguages;
150146
}
151147

152-
export function getSupportedLanguagesWithoutAliases(): string[] {
153-
return supportedLanguagesWithoutAliases;
154-
}
155-
156148
export function getSupportedThemes(): string[] {
157149
return supportedThemes;
158150
}

src/lib/utils/options/help.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import {
55
ParameterType,
66
type DeclarationOption,
77
} from "./declaration.js";
8-
import {
9-
getSupportedLanguagesWithoutAliases,
10-
getSupportedThemes,
11-
} from "../highlighter.js";
8+
import { getSupportedLanguages, getSupportedThemes } from "../highlighter.js";
129
import type { TranslationProxy } from "../../internationalization/internationalization.js";
1310

1411
export interface ParameterHelp {
@@ -105,7 +102,7 @@ export function getOptionsHelp(
105102
output.push(
106103
"",
107104
"Supported highlighting languages:",
108-
...toEvenColumns(getSupportedLanguagesWithoutAliases(), 80),
105+
...toEvenColumns(getSupportedLanguages(), 80),
109106
);
110107

111108
output.push(

src/lib/utils/options/sources/typedoc.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { blockTags, inlineTags, modifierTags } from "../tsdoc-defaults.js";
1515
import { getEnumKeys } from "../../enum.js";
1616
import type { BundledTheme } from "@gerrit0/mini-shiki";
1717
import {
18-
getSupportedLanguagesWithoutAliases,
18+
getSupportedLanguages,
1919
getSupportedThemes,
2020
} from "../../highlighter.js";
2121
import { setDifference } from "../../set.js";
@@ -356,10 +356,7 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
356356
type: ParameterType.Array,
357357
defaultValue: OptionDefaults.highlightLanguages,
358358
validate(value, i18n) {
359-
const invalid = setDifference(
360-
value,
361-
getSupportedLanguagesWithoutAliases(),
362-
);
359+
const invalid = setDifference(value, getSupportedLanguages());
363360
if (invalid.size) {
364361
throw new Error(
365362
i18n.highlightLanguages_contains_invalid_languages_0(

src/test/utils/options/default-options.test.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ok, throws, strictEqual, doesNotThrow } from "assert";
1+
import { ok, throws, deepStrictEqual as equal, doesNotThrow } from "assert";
22
import { Options } from "../../../lib/utils/index.js";
33
import { Internationalization } from "../../../lib/internationalization/internationalization.js";
44

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

1616
throws(() =>
1717
opts.setValue("darkHighlightTheme", "randomTheme" as never),
1818
);
1919
opts.setValue("darkHighlightTheme", "github-light");
20-
strictEqual(opts.getValue("darkHighlightTheme"), "github-light");
20+
equal(opts.getValue("darkHighlightTheme"), "github-light");
21+
});
22+
});
23+
24+
describe("highlightLanguages", () => {
25+
it("Supports aliased languages", () => {
26+
opts.setValue("highlightLanguages", ["bash"]);
27+
equal(opts.getValue("highlightLanguages"), ["bash"]);
2128
});
2229
});
2330

0 commit comments

Comments
 (0)