· 1 min read

Switching from prismjs to shiki

This article was auto-translated from Chinese. Some nuances may be lost in translation.

shiki is a code syntax highlighting package that is relatively newer and less well-known compared to other libraries (like highlightjs and prismjs). shiki uses TextMate grammars for tokenization. Aside from being able to directly reuse grammars from elsewhere without writing custom language definitions, having a unified standard also makes future extensions much easier. Additionally, its language support is very rich, it is easier to configure, and it comes with many built-in themes, so I went ahead and replaced prismjs. Just installed gatsby-remark-shiki, applied the config, and was all set. Awesome!

Ran into a few minor issues:

  • Code previously highlighted with react had to be changed to jsx or tsx
  • If using c++, it needed to be changed to cpp

Here’s the result:

const Component = () => <MyComponent />

Related Posts

Explore Other Topics