From e0ae8773849b8e5aaf66d0a2ab90ec32f6c70f13 Mon Sep 17 00:00:00 2001 From: bluwy Date: Mon, 9 Oct 2023 20:40:09 +0800 Subject: [PATCH] Cleanup markdoc shiki --- packages/integrations/markdoc/src/extensions/shiki.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/integrations/markdoc/src/extensions/shiki.ts b/packages/integrations/markdoc/src/extensions/shiki.ts index 8520902ec..9ca894245 100644 --- a/packages/integrations/markdoc/src/extensions/shiki.ts +++ b/packages/integrations/markdoc/src/extensions/shiki.ts @@ -25,6 +25,7 @@ const COLOR_REPLACEMENT_REGEX = new RegExp( const PRE_SELECTOR = /
([\+|\-])/g;
 const INLINE_STYLE_SELECTOR = /style="(.*?)"/;
+const INLINE_STYLE_SELECTOR_GLOBAL = /style="(.*?)"/g;
 
 /**
  * Note: cache only needed for dev server reloads, internal test suites, and manual calls to `Markdoc.transform` by the user.
@@ -99,7 +100,7 @@ export default async function shiki({
 					// theme.id for shiki -> shikiji compat
 					const themeName = typeof theme === 'string' ? theme : theme.name;
 					if (themeName === 'css-variables') {
-						html = html.replace(/style="(.*?)"/g, (m) => replaceCssVariables(m));
+						html = html.replace(INLINE_STYLE_SELECTOR_GLOBAL, (m) => replaceCssVariables(m));
 					}
 
 					// Use `unescapeHTML` to return `HTMLString` for Astro renderer to inline as HTML
@@ -113,6 +114,6 @@ export default async function shiki({
 /**
  * shiki -> shikiji compat as we need to manually replace it
  */
-export function replaceCssVariables(str: string) {
+function replaceCssVariables(str: string) {
 	return str.replace(COLOR_REPLACEMENT_REGEX, (match) => ASTRO_COLOR_REPLACEMENTS[match] || match);
 }