· 1 min read
Change from prismjs to shiki
# Frontend This article was auto-translated from Chinese. Some nuances may be lost in translation.
shiki is a package that provides syntax highlighting for code. It’s relatively newer compared to other packages like highlightjs and prismjs, and not as widely known. shiki uses TextMate grammar as its tokenizer definition, which means you can directly utilize grammars from other sources without needing to write custom language definitions. This standardization also makes it easier to expand in the future.
Additionally, it offers a rich variety of supported languages and is simpler to configure. With many built-in themes available, I easily replaced my original prismjs setup. Installing gatsby-remark-shiki and applying the configuration was straightforward—what a win!
I encountered a few minor issues:
- I originally used react’s highlight, so I had to change everything to jsx or tsx.
- If you’re using
c++, you need to switch it tocpp.
Here’s what I came up with:
const Component = () => <MyComponent /> Related Posts
- What to Pay Attention to When Using Images on the FrontendBased on an article by Jake Archibald, this post organizes how modern responsive images should be written: why `width`/`height` still matter, when to use CSS `aspect-ratio`, how to choose between AVIF and WebP, and how to use `picture`/`source`/`srcset` for switching images on mobile.
- CSS field-sizing — Auto-Resize Form Elements with One Line of CSSMaking a textarea auto-resize used to require JavaScript to watch scrollHeight. CSS field-sizing: content replaces all of that in one line, supporting textarea, input, and select.
- Make Your Hyperlink Underlines Look Better: text-underline-offsetBy default, underlines sit very close to the text, and some designers dislike this style. Personally, I don’t think it looks very good either.
- Why Web Design Shouldn’t Chase Pixel PerfectOnly pay attention to Pixel Perfect when it really matters; otherwise, it often leads to a lose-lose situation.