DEV Community

Babu Annamalai
Babu Annamalai

Posted on • Originally published at mysticmind.dev

VitePress fenced code block syntax highlighting quirks with .NET or other languages.

This post was originally published at https://mysticmind.dev/vitepress-fenced-code-block-syntax-highlighting-quirks-with-net-or-other-languages

VitePress uses Shiki for syntax highlighting which is a fantastic library. Shiki automatically fetches language grammar from VSCode so the language names etc for the fenced code block comes from it.

For .NET, the language names captured are csharp and fsharp by default. This means that the syntax highlighting will work only if you use csharp or fsharp. But idiomatic usage use the file extensions cs and fs for syntax highlighting so this tends to be an issue. I did send a PR to Shiki to resolve this. But there are many moving parts i.e. Shiki will need to do a release with the fix then VitePress picking it up and in turn do a release.

If you are stuck, not only with .NET languages or any other language as well, there is a easy fix under your control. Edit your VitePress config.js file and add the following:

import { BUNDLED_LANGUAGES } from 'shiki'

// Include `cs` as alias for csharp
BUNDLED_LANGUAGES
  .find(lang => lang.id === 'csharp').aliases.push('cs');

// Include `fs` as alias for fsharp
BUNDLED_LANGUAGES
  .find(lang => lang.id === 'fsharp').aliases.push('fs');
Enter fullscreen mode Exit fullscreen mode

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay