From ccb58331464ff25b25d7385be700a00edce1ad4e Mon Sep 17 00:00:00 2001 From: Felix Koppe Date: Wed, 21 Feb 2024 13:02:31 +0100 Subject: [PATCH] fix: allow nullish color for colorReplacement, fix ansi highlighting with dark-plus, fix #597 (#598) --- packages/core/src/utils.ts | 2 +- packages/shiki/test/ansi.test.ts | 13 +++++++++++++ packages/shiki/test/out/ansi-dark-plus.html | 7 +++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 packages/shiki/test/out/ansi-dark-plus.html diff --git a/packages/core/src/utils.ts b/packages/core/src/utils.ts index 0214809bb..d4c690aa5 100644 --- a/packages/core/src/utils.ts +++ b/packages/core/src/utils.ts @@ -147,7 +147,7 @@ export function splitTokens< } export function applyColorReplacements(color: string, replacements?: Record): string { - return replacements?.[color.toLowerCase()] || color + return replacements?.[color?.toLowerCase()] || color } export function getTokenStyleObject(token: TokenStyles) { diff --git a/packages/shiki/test/ansi.test.ts b/packages/shiki/test/ansi.test.ts index dafaf3a7f..7e6da8b53 100644 --- a/packages/shiki/test/ansi.test.ts +++ b/packages/shiki/test/ansi.test.ts @@ -31,3 +31,16 @@ Packages: +1038 expect(out).toMatchFileSnapshot('./out/ansi-background.html') }) + +// https://github.com/shikijs/shiki/issues/597 +it('renders ansi to html with theme dark-plus', async () => { + const out = await codeToHtml(` WARN  using --force I sure hope you know what you are doing +Scope: all 6 workspace projects +Lockfile is up to date, resolution step is skipped +Packages: +952 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +Progress: resolved 952, reused 910, downloaded 42, added 952, done +Done in 15.7s`, { theme: 'dark-plus', lang: 'ansi' }) + + expect(out).toMatchFileSnapshot('./out/ansi-dark-plus.html') +}) diff --git a/packages/shiki/test/out/ansi-dark-plus.html b/packages/shiki/test/out/ansi-dark-plus.html new file mode 100644 index 000000000..d46118699 --- /dev/null +++ b/packages/shiki/test/out/ansi-dark-plus.html @@ -0,0 +1,7 @@ +
 WARN  using --force I sure hope you know what you are doing
+Scope: all 6 workspace projects
+Lockfile is up to date, resolution step is skipped
+Packages: +952
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Progress: resolved 952, reused 910, downloaded 42, added 952, done
+Done in 15.7s
\ No newline at end of file