From a2e8e76c303e8d6f39c24c122905a10f06907997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Seery?= Date: Sun, 28 Aug 2022 08:23:37 -0300 Subject: [PATCH] chore: updated shiki (#4519) * Upgraded shiki * Use setColorReplacements * no-shadow * Changeset --- .changeset/big-guests-cry.md | 7 +++++ packages/astro/components/Code.astro | 5 ---- packages/astro/components/Shiki.js | 21 ++++++++++++++- packages/astro/package.json | 2 +- packages/integrations/mdx/package.json | 2 +- packages/integrations/mdx/src/remark-shiki.ts | 22 +++++++++++----- packages/markdown/remark/package.json | 2 +- packages/markdown/remark/src/remark-shiki.ts | 22 +++++++++++----- pnpm-lock.yaml | 26 ++++++++++++++----- 9 files changed, 82 insertions(+), 27 deletions(-) create mode 100644 .changeset/big-guests-cry.md diff --git a/.changeset/big-guests-cry.md b/.changeset/big-guests-cry.md new file mode 100644 index 000000000..4860fd51c --- /dev/null +++ b/.changeset/big-guests-cry.md @@ -0,0 +1,7 @@ +--- +'astro': patch +'@astrojs/mdx': patch +'@astrojs/markdown-remark': patch +--- + +Upgraded Shiki to v0.11.1 diff --git a/packages/astro/components/Code.astro b/packages/astro/components/Code.astro index ddeaac829..8a4d50c7f 100644 --- a/packages/astro/components/Code.astro +++ b/packages/astro/components/Code.astro @@ -38,11 +38,6 @@ const { code, lang = 'plaintext', theme = 'github-dark', wrap = false } = Astro. function repairShikiTheme(html: string): string { // Replace "shiki" class naming with "astro" html = html.replace('
}
+ */
 export function getHighlighter(opts) {
 	const key = stringify(opts);
 
@@ -17,7 +21,22 @@ export function getHighlighter(opts) {
 	}
 
 	// Start the async getHighlighter call and cache the Promise
-	const highlighter = getShikiHighlighter(opts);
+	const highlighter = getShikiHighlighter(opts).then((hl) => {
+		hl.setColorReplacements({
+			'#000001': 'var(--astro-code-color-text)',
+			'#000002': 'var(--astro-code-color-background)',
+			'#000004': 'var(--astro-code-token-constant)',
+			'#000005': 'var(--astro-code-token-string)',
+			'#000006': 'var(--astro-code-token-comment)',
+			'#000007': 'var(--astro-code-token-keyword)',
+			'#000008': 'var(--astro-code-token-parameter)',
+			'#000009': 'var(--astro-code-token-function)',
+			'#000010': 'var(--astro-code-token-string-expression)',
+			'#000011': 'var(--astro-code-token-punctuation)',
+			'#000012': 'var(--astro-code-token-link)',
+		});
+		return hl;
+	});
 	_resolvedHighlighters.set(key, highlighter);
 
 	return highlighter;
diff --git a/packages/astro/package.json b/packages/astro/package.json
index bdfb455a7..91b76ffc4 100644
--- a/packages/astro/package.json
+++ b/packages/astro/package.json
@@ -137,7 +137,7 @@
     "resolve": "^1.22.0",
     "rollup": "~2.77.0",
     "semver": "^7.3.7",
-    "shiki": "^0.10.1",
+    "shiki": "^0.11.1",
     "sirv": "^2.0.2",
     "slash": "^4.0.0",
     "string-width": "^5.1.2",
diff --git a/packages/integrations/mdx/package.json b/packages/integrations/mdx/package.json
index e3a5f12a9..0df60afda 100644
--- a/packages/integrations/mdx/package.json
+++ b/packages/integrations/mdx/package.json
@@ -40,7 +40,7 @@
     "remark-frontmatter": "^4.0.1",
     "remark-gfm": "^3.0.1",
     "remark-smartypants": "^2.0.0",
-    "shiki": "^0.10.1",
+    "shiki": "^0.11.1",
     "unist-util-visit": "^4.1.0",
     "vfile": "^5.3.2"
   },
diff --git a/packages/integrations/mdx/src/remark-shiki.ts b/packages/integrations/mdx/src/remark-shiki.ts
index 76a1d275f..7bb944ce6 100644
--- a/packages/integrations/mdx/src/remark-shiki.ts
+++ b/packages/integrations/mdx/src/remark-shiki.ts
@@ -14,7 +14,22 @@ const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }:
 	const cacheID: string = typeof theme === 'string' ? theme : theme.name;
 	let highlighterAsync = highlighterCacheAsync.get(cacheID);
 	if (!highlighterAsync) {
-		highlighterAsync = getHighlighter({ theme });
+		highlighterAsync = getHighlighter({ theme }).then((hl) => {
+			hl.setColorReplacements({
+				'#000001': 'var(--astro-code-color-text)',
+				'#000002': 'var(--astro-code-color-background)',
+				'#000004': 'var(--astro-code-token-constant)',
+				'#000005': 'var(--astro-code-token-string)',
+				'#000006': 'var(--astro-code-token-comment)',
+				'#000007': 'var(--astro-code-token-keyword)',
+				'#000008': 'var(--astro-code-token-parameter)',
+				'#000009': 'var(--astro-code-token-function)',
+				'#000010': 'var(--astro-code-token-string-expression)',
+				'#000011': 'var(--astro-code-token-punctuation)',
+				'#000012': 'var(--astro-code-token-link)',
+			});
+			return hl;
+		});
 		highlighterCacheAsync.set(cacheID, highlighterAsync);
 	}
 	const highlighter = await highlighterAsync;
@@ -52,11 +67,6 @@ const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }:
 
 			// Replace "shiki" class naming with "astro".
 			html = html.replace('
 {
+			hl.setColorReplacements({
+				'#000001': 'var(--astro-code-color-text)',
+				'#000002': 'var(--astro-code-color-background)',
+				'#000004': 'var(--astro-code-token-constant)',
+				'#000005': 'var(--astro-code-token-string)',
+				'#000006': 'var(--astro-code-token-comment)',
+				'#000007': 'var(--astro-code-token-keyword)',
+				'#000008': 'var(--astro-code-token-parameter)',
+				'#000009': 'var(--astro-code-token-function)',
+				'#000010': 'var(--astro-code-token-string-expression)',
+				'#000011': 'var(--astro-code-token-punctuation)',
+				'#000012': 'var(--astro-code-token-link)',
+			});
+			return hl;
+		});
 		highlighterCacheAsync.set(cacheID, highlighterAsync);
 	}
 	const highlighter = await highlighterAsync;
@@ -58,11 +73,6 @@ const remarkShiki = async (
 				'