File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
browser-extension/src/playgrounds Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change 1+ import hljs from "highlight.js" ;
12import OverType from "../overtype/overtype" ;
23
34export 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
2223function 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+ }
You can’t perform that action at this time.
0 commit comments