From c585528f446ccca3d4c643f4af5d550b93c18902 Mon Sep 17 00:00:00 2001 From: Kyle Nguyen Date: Mon, 25 Mar 2024 15:44:08 -0400 Subject: [PATCH] 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 --- .changeset/eighty-pumpkins-float.md | 6 ++++++ packages/markdown/remark/src/shiki.ts | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changeset/eighty-pumpkins-float.md diff --git a/.changeset/eighty-pumpkins-float.md b/.changeset/eighty-pumpkins-float.md new file mode 100644 index 000000000000..9550a18ceeec --- /dev/null +++ b/.changeset/eighty-pumpkins-float.md @@ -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. diff --git a/packages/markdown/remark/src/shiki.ts b/packages/markdown/remark/src/shiki.ts index ff1589dac153..fc35c6e92b33 100644 --- a/packages/markdown/remark/src/shiki.ts +++ b/packages/markdown/remark/src/shiki.ts @@ -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';