sarif-web-component icon indicating copy to clipboard operation
sarif-web-component copied to clipboard

Apply Syntax Hilighting to Code Snippets

Open gfs opened this issue 3 years ago • 2 comments

It would be great for embedded snippets to have syntax highlighting applied to them to make it easier to read the code.

gfs avatar Feb 15 '22 23:02 gfs

We do have limited syntax highlighting (code). I say "limited" as we are constrained by two things:

  • Frequently the code snippet is incomplete in a way confuses the syntax highlighter.
  • For payload/performance reasons, we stopped included all hljs languages by default in our componment.

Which language in particular are you having issues with? Perhaps we can make a tactical fix. Thanks!

jeffersonking avatar Feb 21 '22 09:02 jeffersonking

I've noticed that C# doesn't seem to work correctly. This is a screenshot from the component as embedded on Dev Ops. You can see that the n in new is blue but not the whole keyword, additionally the class/method call isn't colored.

image

I've had good results with prism.js for highlighting.

Here's the same sarif loaded and the snippet highlighted with prism (the colors are configurable): image

https://prismjs.com/

gfs avatar Feb 22 '22 18:02 gfs