Aeolun / react-diff-viewer-continued

A simple and beautiful text diff viewer component made with Diff and React.
https://aeolun.github.io/react-diff-viewer-continued/
MIT License
113 stars 34 forks source link

renderContent highlightSyntax example error #10

Closed mcgrealife closed 1 year ago

mcgrealife commented 1 year ago

When attempting to add syntax highlighting, I encounter these errors:

Prism.highlight() interface now requires 3 args, not 2:

Prism.highlight() arg0 str undefined:

highlight-error-message-arg0-undefined

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",

xino1010 commented 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}
    />
  );
};
mcgrealife commented 1 year ago

@xino1010 ah! check for undefined – of course. Much appreciated :)