Skip to content

Commit a68d742

Browse files
committed
Pull latest overtype-hard changes into the github-playground.
1 parent a124a16 commit a68d742

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

browser-extension/src/playgrounds/github-playground.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import hljs from "highlight.js";
12
import OverType from "../overtype/overtype";
23

34
export function githubPrNewCommentContentScript() {
45
if (window.location.hostname !== "github.com") {
56
return;
67
}
7-
8+
OverType.setCodeHighlighter(hljsHighlighter);
89
const ghCommentBox = document.getElementById(
910
"new_comment_field"
1011
) as HTMLTextAreaElement | null;
@@ -17,7 +18,7 @@ export function githubPrNewCommentContentScript() {
1718
padding: "var(--base-size-8)",
1819
});
1920
}
20-
}
21+
}
2122

2223
function modifyDOM(overtypeInput: HTMLTextAreaElement): HTMLElement {
2324
overtypeInput.classList.add("overtype-input");
@@ -31,3 +32,18 @@ function modifyDOM(overtypeInput: HTMLTextAreaElement): HTMLElement {
3132
overtypeContainer.classList.add("overtype-container");
3233
return overtypeContainer.parentElement!.closest("div")!;
3334
}
35+
36+
function hljsHighlighter(code: string, language: string) {
37+
try {
38+
if (language && hljs.getLanguage(language)) {
39+
const result = hljs.highlight(code, { language });
40+
return result.value;
41+
} else {
42+
const result = hljs.highlightAuto(code);
43+
return result.value;
44+
}
45+
} catch (error) {
46+
console.warn("highlight.js highlighting failed:", error);
47+
return code;
48+
}
49+
}

0 commit comments

Comments
 (0)