File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,9 +7,12 @@ const CODE_FENCE_LANGUAGE_REGEX = /(?:^|\s)language-([^\s]+)/;
77
88export function extractFenceLanguage ( className : string | undefined ) : string {
99 const match = className ?. match ( CODE_FENCE_LANGUAGE_REGEX ) ;
10- const raw = match ?. [ 1 ] ?? "text" ;
10+ return highlighterLanguageOf ( match ?. [ 1 ] ?? "text" ) ;
11+ }
12+
13+ export function highlighterLanguageOf ( language : string ) : string {
1114 // Shiki doesn't bundle a gitignore grammar; ini is a close match.
12- return raw === "gitignore" ? "ini" : raw ;
15+ return language === "gitignore" ? "ini" : language ;
1316}
1417
1518const FENCE_TITLE_ATTR_REGEX = / (?: ^ | \s ) (?: t i t l e | f i l e (?: n a m e ) ? ) = (?: " ( [ ^ " ] + ) " | ' ( [ ^ ' ] + ) ' | ( \S + ) ) / i;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import type { Node as ProseMirrorNode } from "@tiptap/pm/model";
66import type { DiffThemeName } from "~/lib/diffRendering" ;
77import { languageOfInfoString } from "~/composer-code-languages" ;
88import { getSyntaxHighlighterPromise } from "~/lib/syntaxHighlighting" ;
9+ import { highlighterLanguageOf } from "./chat/MarkdownCodeBlock.logic" ;
910
1011interface HighlightedBlock {
1112 readonly signature : string ;
@@ -119,8 +120,9 @@ export function composerCodeBlockHighlight(options: {
119120 void Promise . allSettled (
120121 pending . map ( async ( { node } ) => {
121122 // Stored info includes metadata after the language; Shiki needs only the name.
122- const language =
123- languageOfInfoString ( String ( node . attrs . language ?? "" ) ) || "text" ;
123+ const language = highlighterLanguageOf (
124+ languageOfInfoString ( String ( node . attrs . language ?? "" ) ) || "text" ,
125+ ) ;
124126 const signature = blockSignature ( node , theme ) ;
125127 // Cache failure as plain text to clear retained colors.
126128 const highlighter = await getSyntaxHighlighterPromise ( language ) . catch ( ( ) => null ) ;
You can’t perform that action at this time.
0 commit comments