Closed mcgrealife closed 1 year ago
const FileDiffs = () => {
const highlightSyntax = (str: string) =>
!str ? (
<div />
) : (
<pre
style={{ display: "inline" }}
dangerouslySetInnerHTML={{
__html: Prism.highlight(
str,
Prism.languages.javascript,
"javascript"
),
}}
/>
);
return (
<ReactDiffViewer
oldValue={oldCode}
newValue={newCode}
splitView={true}
renderContent={highlightSyntax}
/>
);
};
@xino1010 ah! check for undefined – of course. Much appreciated :)
When attempting to add syntax highlighting, I encounter these errors:
Prism.highlight() interface now requires 3 args, not 2:
__html: highlight(str, Prism.languages.javascript)
, however, it looks like the most recent interface has 3 args:__html: Prism.highlight(str, Prism.languages.javascript, 'javascript')
Prism.highlight() arg0
str
undefined:__html: Prism.highlight(oldCode, Prism.languages.javascript, 'javascript')
but then this shows the oldCode on both sides of the splitView!Any advice is appreciated!
packages:
"react": "18.2.0", "react-diff-viewer-continued": "^3.2.3", "prismjs": "^1.29.0", "@types/prismjs": "^1.26.0",