0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-17 22:44:24 -05:00

fix: use Shiki's isSpecialLang to allow ansi codeblocks (#10540)

* fix: use `isSpecialLang` instead of hardcode

Hardcoding this value makes it impossible to use Shiki's `ansi` feature

* Add changeset
This commit is contained in:
Kyle Nguyen 2024-03-25 15:44:08 -04:00 committed by GitHub
parent 1cd2a74022
commit c585528f44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View file

@ -0,0 +1,6 @@
---
"@astrojs/markdown-remark": patch
---
This patch allows Shiki to use all of its reserved languages instead of the
previous behavior of forcing unknown languages to plaintext.

View file

@ -1,5 +1,5 @@
import type { Properties } from 'hast';
import { bundledLanguages, createCssVariablesTheme, getHighlighter } from 'shiki';
import { bundledLanguages, createCssVariablesTheme, getHighlighter, isSpecialLang } from 'shiki';
import { visit } from 'unist-util-visit';
import type { ShikiConfig } from './types.js';
@ -51,7 +51,7 @@ export async function createShikiHighlighter({
return {
highlight(code, lang = 'plaintext', options) {
if (lang !== 'plaintext' && !loadedLanguages.includes(lang)) {
if (!isSpecialLang(lang) && !loadedLanguages.includes(lang)) {
// eslint-disable-next-line no-console
console.warn(`[Shiki] The language "${lang}" doesn't exist, falling back to "plaintext".`);
lang = 'plaintext';