Skip to content

Commit

Permalink
fix: use Shiki's isSpecialLang to allow ansi codeblocks (#10540)
Browse files Browse the repository at this point in the history
* fix: use `isSpecialLang` instead of hardcode

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

* Add changeset
  • Loading branch information
imkunet committed Mar 25, 2024
1 parent 1cd2a74 commit c585528
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/eighty-pumpkins-float.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions packages/markdown/remark/src/shiki.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit c585528

Please sign in to comment.