From 6a4c67399dcd0ac04266a94eb18dd6e5d17f18e8 Mon Sep 17 00:00:00 2001 From: Degreat Date: Fri, 19 Jan 2024 21:51:51 +0000 Subject: [PATCH] normalize styles, rename function --- packages/markdown/remark/src/shiki.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/markdown/remark/src/shiki.ts b/packages/markdown/remark/src/shiki.ts index a5befd620c2b..492d5a821eb3 100644 --- a/packages/markdown/remark/src/shiki.ts +++ b/packages/markdown/remark/src/shiki.ts @@ -62,10 +62,8 @@ export async function createShikiHighlighter({ node.tagName = 'code'; } - const classValue = normalizeMaybeArray(node.properties.class) ?? ''; - - // Cast to string as shikiji will always pass them as strings instead of any other types - 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'); @@ -131,7 +129,7 @@ export async function createShikiHighlighter({ }; } -function normalizeMaybeArray(value: Properties[string]): string | null { +function normalizePropAsString(value: Properties[string]): string | null { return Array.isArray(value) ? value.join(' ') : (value as string | null); }