aboutsummaryrefslogtreecommitdiff
path: root/packages/markdown/remark/src
diff options
context:
space:
mode:
authorGravatar Degreat <mail@degreat.co.uk> 2024-01-22 20:00:00 +0000
committerGravatar GitHub <noreply@github.com> 2024-01-22 20:00:00 +0000
commit2f81cffa9da9db0e2802d303f94feaee8d2f54ec (patch)
tree2b00f39e44e0270d411fed8b7b8900ed355f32a2 /packages/markdown/remark/src
parentad01642517bf0d5b11a5849039f3710d399930e6 (diff)
downloadastro-2f81cffa9da9db0e2802d303f94feaee8d2f54ec.tar.gz
astro-2f81cffa9da9db0e2802d303f94feaee8d2f54ec.tar.zst
astro-2f81cffa9da9db0e2802d303f94feaee8d2f54ec.zip
normalize class property (#9723)
* normalize class property * Add changeset * properly type return value * normalize styles, rename function * properly describe change Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev> --------- Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
Diffstat (limited to 'packages/markdown/remark/src')
-rw-r--r--packages/markdown/remark/src/shiki.ts10
1 files changed, 7 insertions, 3 deletions
diff --git a/packages/markdown/remark/src/shiki.ts b/packages/markdown/remark/src/shiki.ts
index 04b1bbcf6..492d5a821 100644
--- a/packages/markdown/remark/src/shiki.ts
+++ b/packages/markdown/remark/src/shiki.ts
@@ -1,5 +1,6 @@
import { bundledLanguages, createCssVariablesTheme, getHighlighter } from 'shikiji';
import { visit } from 'unist-util-visit';
+import type { Properties } from 'hast';
import type { ShikiConfig } from './types.js';
export interface ShikiHighlighter {
@@ -61,9 +62,8 @@ export async function createShikiHighlighter({
node.tagName = 'code';
}
- // Cast to string as shikiji will always pass them as strings instead of any other types
- const classValue = (node.properties.class as string) ?? '';
- const styleValue = (node.properties.style as string) ?? '';
+ const classValue = normalizePropAsString(node.properties.class) ?? '';
+ const styleValue = normalizePropAsString(node.properties.style) ?? '';
// Replace "shiki" class naming with "astro-code"
node.properties.class = classValue.replace(/shiki/g, 'astro-code');
@@ -129,6 +129,10 @@ export async function createShikiHighlighter({
};
}
+function normalizePropAsString(value: Properties[string]): string | null {
+ return Array.isArray(value) ? value.join(' ') : (value as string | null);
+}
+
/**
* shiki -> shikiji compat as we need to manually replace it
* @internal Exported for error overlay use only