Switching to PrismJS
❯
Awhile back, I posted about using HighlightJS to add some syntax highlighting. I saw that PrismJS has a very small core size, which means faster load times. I also thought it was easier to use than HighlightJS at least for my simple purposes. The downside is that it's not as good at language autodetection, but when writing code snippets I've found that needing to provide the language upfront isn't that big of a deal. Let's see how it goes!
import Prism from 'prismjs'
// When using Turbo with hotwire, page navigation happens without full reloads,
// so we need to re-run Prism's syntax highlighting on every Turbo page load.
// This ensures code blocks are properly highlighted even after AJAX page swaps.
document.addEventListener("turbo:load", () => Prism.highlightAll());