Skip to content

Commit 4c66eac

Browse files
fix(web): highlight Scala code blocks (#958)
Co-authored-by: Rinat S <rinat.suleimanov@jetbrains.com>
1 parent d3d97c6 commit 4c66eac

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎apps/web/src/lib/highlighter.test.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
11
import { expect, test } from "bun:test";
2-
import { SHIKI_FILE_LANGUAGES } from "./highlighter";
2+
import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
3+
import {
4+
chatShikiLanguageId,
5+
createChatHighlighter,
6+
SHIKI_FILE_LANGUAGES,
7+
shikiLanguageId,
8+
} from "./highlighter";
39

410
test("the Monaco Shiki language registration list has no duplicate ids", () => {
511
const ids = SHIKI_FILE_LANGUAGES.map((language) => language.id);
612
expect(new Set(ids).size).toBe(ids.length);
713
});
814

15+
test("Scala is recognized for chat fences and Scala files", () => {
16+
const scala = SHIKI_FILE_LANGUAGES.find((language) => language.id === "scala");
17+
expect(scala?.extensions).toContain(".scala");
18+
expect(scala?.chat).toBe(true);
19+
expect(shikiLanguageId("Scala")).toBe("scala");
20+
expect(chatShikiLanguageId("scala")).toBe("scala");
21+
});
22+
23+
test("a Scala chat fence renders with Shiki tokens", async () => {
24+
const highlight = createChatHighlighter(createJavaScriptRegexEngine);
25+
const html = await highlight('object Greeting { val message: String = "hello" }', "scala");
26+
expect(html).not.toBeNull();
27+
expect(html).toContain("<span");
28+
});
29+
930
test("every Monaco language id is supplied by its Shiki grammar", async () => {
1031
const modules = await Promise.all(SHIKI_FILE_LANGUAGES.map((language) => language.load()));
1132
for (const [index, language] of SHIKI_FILE_LANGUAGES.entries()) {

‎apps/web/src/lib/highlighter.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ export const SHIKI_FILE_LANGUAGES: readonly ShikiFileLanguage[] = [
139139
aliases: ["Kotlin", "kt", "kts"],
140140
load: () => import("@shikijs/langs/kotlin"),
141141
},
142+
{
143+
id: "scala",
144+
extensions: [".scala"],
145+
aliases: ["Scala"],
146+
chat: true,
147+
load: () => import("@shikijs/langs/scala"),
148+
},
142149
{
143150
id: "swift",
144151
extensions: [".swift"],

0 commit comments

Comments
 (0)