@@ -2,12 +2,17 @@ import { useMemo } from "react";
22import { parsePatchFiles , type FileDiffMetadata } from "@pierre/diffs" ;
33import { FileDiff , WorkerPoolContextProvider } from "@pierre/diffs/react" ;
44import { parseDiff } from "../../../utils/diff" ;
5+ import { highlightLine , languageFromPath } from "../../../utils/syntax" ;
56import { workerFactory } from "../../../utils/diffsWorker" ;
67import {
78 DIFF_VIEWER_HIGHLIGHTER_OPTIONS ,
89 DIFF_VIEWER_SCROLL_CSS ,
910} from "../../design-system/diff/diffViewerTheme" ;
10- import { normalizePatchName , parseRawDiffLines } from "./GitDiffViewer.utils" ;
11+ import {
12+ isFallbackRawDiffLineHighlightable ,
13+ normalizePatchName ,
14+ parseRawDiffLines ,
15+ } from "./GitDiffViewer.utils" ;
1116
1217type PierreDiffBlockProps = {
1318 diff : string ;
@@ -60,6 +65,10 @@ export function PierreDiffBlock({
6065 }
6166 return parseRawDiffLines ( diff ) ;
6267 } , [ diff ] ) ;
68+ const fallbackLanguage = useMemo (
69+ ( ) => languageFromPath ( displayPath ) ,
70+ [ displayPath ] ,
71+ ) ;
6372
6473 const diffOptions = useMemo (
6574 ( ) => ( {
@@ -91,14 +100,26 @@ export function PierreDiffBlock({
91100 </ div >
92101 ) : (
93102 < div className = "diff-viewer-output diff-viewer-output-flat diff-viewer-output-raw" >
94- { parsedLines . map ( ( line , index ) => (
95- < div
96- key = { index }
97- className = { `diff-viewer-raw-line diff-viewer-raw-line-${ line . type } ` }
98- >
99- { line . text }
100- </ div >
101- ) ) }
103+ { parsedLines . map ( ( line , index ) => {
104+ const highlighted = highlightLine (
105+ line . text ,
106+ isFallbackRawDiffLineHighlightable ( line . type )
107+ ? fallbackLanguage
108+ : null ,
109+ ) ;
110+
111+ return (
112+ < div
113+ key = { index }
114+ className = { `diff-viewer-raw-line diff-viewer-raw-line-${ line . type } ` }
115+ >
116+ < span
117+ className = "diff-line-content"
118+ dangerouslySetInnerHTML = { { __html : highlighted } }
119+ />
120+ </ div >
121+ ) ;
122+ } ) }
102123 </ div >
103124 ) }
104125 </ WorkerPoolContextProvider >
0 commit comments