react-diff-viewer-continued icon indicating copy to clipboard operation
react-diff-viewer-continued copied to clipboard

Bug- prism fails if the text in a code is empty line

Open ObaidAshiq opened this issue 2 years ago • 1 comments

Description When the user try to view the diff in split mode, if the old code and new code have, some empty line, prism throws error for syntax highlighting

Step to reproduce

  1. Use the Syntax Highlighting example
  2. Add some empty lines in new code variable, in the beggining (These variables should contain string value)
  3. Set split mode to true

Screenshot of error image

Screenshot when split mode is false image

Code sanbox image Link Code sandbox example

ObaidAshiq avatar Apr 24 '24 07:04 ObaidAshiq

This is more of a prism bug. And can be easily addressed with:

function highlightSyntax(code: string | undefined) {
  if (!code) {
    return <pre style={{ display: "inline" }} />;
  }

  return (
    <pre
      style={{ display: "inline" }}
      dangerouslySetInnerHTML={{
        __html: Prism.highlight(code, Prism.languages.cpp, "cpp"),
      }}
    />
  );
}

DaBenjle avatar May 19 '25 20:05 DaBenjle