From b8471aa76fcefdd3205c649a185efb2561791720 Mon Sep 17 00:00:00 2001 From: Fuma Nama <76240755+fuma-nama@users.noreply.github.com> Date: Thu, 24 Oct 2024 21:58:12 +0800 Subject: [PATCH] fix(rehype): support special languages (#808) --- packages/rehype/src/core.ts | 3 ++- packages/rehype/test/fixtures/a.core.out.html | 3 ++- packages/rehype/test/fixtures/a.md | 4 ++++ packages/rehype/test/fixtures/a.out.html | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/rehype/src/core.ts b/packages/rehype/src/core.ts index 15c439b0f..3a838a5dd 100644 --- a/packages/rehype/src/core.ts +++ b/packages/rehype/src/core.ts @@ -6,6 +6,7 @@ import type { Root } from 'hast' import type { Transformer } from 'unified' import type { RehypeShikiHandler } from './handlers' import type { RehypeShikiCoreOptions } from './types' +import { isSpecialLang } from 'shiki/core' import { visit } from 'unist-util-visit' import { InlineCodeHandlers, PreHandler } from './handlers' @@ -92,7 +93,7 @@ function rehypeShikiFromHighlighter( if (!lang) return defaultLanguage - if (highlighter.getLoadedLanguages().includes(lang)) + if (highlighter.getLoadedLanguages().includes(lang) || isSpecialLang(lang)) return lang if (lazy) { diff --git a/packages/rehype/test/fixtures/a.core.out.html b/packages/rehype/test/fixtures/a.core.out.html index d3bde0c59..29dc0724b 100644 --- a/packages/rehype/test/fixtures/a.core.out.html +++ b/packages/rehype/test/fixtures/a.core.out.html @@ -4,4 +4,5 @@
Should fallback to default language
\ No newline at end of file
+Should fallback to default language
+Special languages should be styled
\ No newline at end of file
diff --git a/packages/rehype/test/fixtures/a.md b/packages/rehype/test/fixtures/a.md
index b9894b044..244fc3744 100644
--- a/packages/rehype/test/fixtures/a.md
+++ b/packages/rehype/test/fixtures/a.md
@@ -11,4 +11,8 @@ console.log(a)
```
Should fallback to default language
+```
+
+```plaintext
+Special languages should be styled
```
\ No newline at end of file
diff --git a/packages/rehype/test/fixtures/a.out.html b/packages/rehype/test/fixtures/a.out.html
index 0484fac46..67530087f 100644
--- a/packages/rehype/test/fixtures/a.out.html
+++ b/packages/rehype/test/fixtures/a.out.html
@@ -4,4 +4,5 @@ Should fallback to default language
\ No newline at end of file
+Should fallback to default language
+Special languages should be styled
\ No newline at end of file