docs-pages icon indicating copy to clipboard operation
docs-pages copied to clipboard

Better syntax highlighting for rust code

Open mattyg opened this issue 1 year ago • 5 comments

The syntax highlighting we're using in code examples doesn't clearly distinguish many of the syntax elements of rust code. This makes it far less readable.

For example, this is our docs: image

And this is vscode: image

mattyg avatar Mar 29 '24 17:03 mattyg

Ah yeah, I see what you're saying; this is kinda sad. But it's leagues better than Prism.js, which we'd been using before. I recently learned about another highlighting library; I'll see if I can remember where I filed it.

pdaoust avatar Oct 15 '24 18:10 pdaoust

I'm guessing it's the theme used by the syntax highlighting library that just needs to have different colors for more code elements. Some themes may not colorize all elements.

mattyg avatar Oct 15 '24 18:10 mattyg

could be -- although it may be that highlight.js doesn't have an expressive enough grammar for this. Here are two promising candidates, which both pride themselves on high-quality highlighting. I think they both take TextMate grammars, which means they could ostensibly mimic what VSCode does.

  • https://github.com/wooorm/starry-night
  • https://github.com/shikijs/shiki

Criteria:

  • JS
  • Easy to integrate with 11ty (ideal situation is a sync function that takes a code block string and a language and returns HTML)

pdaoust avatar Oct 15 '24 19:10 pdaoust

Testing: Here's Shiki, which claims it keeps parity with VSCode but can be used server-side. Using Dark Plus theme. A dead ringer for your VSCode screenshot.

Image

pdaoust avatar Oct 15 '24 20:10 pdaoust

Might be addressed by #574 . It looks like Docusaurus hard-codes Prism.js and there's little to no documentation on how to extend Docusaurus to, say, integrate other code highlighters. But either we were using the wrong Prism theme, or it didn't do really well one of the languages we use a lot of (probably Svelte). Anyhow, it'll be interesting to see what that spike uncovers.

pdaoust avatar Jun 02 '25 22:06 pdaoust