-
-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support ansi background color, fix #432
- Loading branch information
Showing
6 changed files
with
46 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,33 @@ | ||
/* eslint-disable no-irregular-whitespace */ | ||
import { expect, it } from 'vitest' | ||
import { | ||
getHighlighter, | ||
codeToHtml, | ||
} from '../src' | ||
|
||
it('renders ansi to html', async () => { | ||
const highlighter = await getHighlighter({ themes: ['monokai'] }) | ||
|
||
const out = highlighter.codeToHtml(`[0;30;43m WARN [0m using --force I sure hope you know what you are doing | ||
const out = await codeToHtml(`[0;30;43m WARN [0m 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: [0;32m+952[0m | ||
[0;32m++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[0m | ||
Progress: resolved [0;104m952[0m, reused [0;104m910[0m, downloaded [0;104m42[0m, added [0;104m952[0m, done | ||
Done in 15.7s`, { theme: 'monokai', lang: 'ansi' }) | ||
|
||
expect(out).toMatchInlineSnapshot(` | ||
"<pre class="shiki monokai" style="background-color:#272822;color:#F8F8F2" tabindex="0"><code><span class="line"><span style="color:#333333"> WARN </span><span style="color:#F8F8F2"> using --force I sure hope you know what you are doing</span></span> | ||
<span class="line"><span style="color:#F8F8F2">Scope: all 6 workspace projects</span></span> | ||
<span class="line"><span style="color:#F8F8F2">Lockfile is up to date, resolution step is skipped</span></span> | ||
<span class="line"><span style="color:#F8F8F2">Packages: </span><span style="color:#86B42B">+952</span></span> | ||
<span class="line"><span style="color:#86B42B">++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</span></span> | ||
<span class="line"><span style="color:#F8F8F2">Progress: resolved </span><span style="color:#F8F8F2">952</span><span style="color:#F8F8F2">, reused </span><span style="color:#F8F8F2">910</span><span style="color:#F8F8F2">, downloaded </span><span style="color:#F8F8F2">42</span><span style="color:#F8F8F2">, added </span><span style="color:#F8F8F2">952</span><span style="color:#F8F8F2">, done</span></span> | ||
<span class="line"><span style="color:#F8F8F2">Done in 15.7s</span></span></code></pre>" | ||
`) | ||
expect(out).toMatchFileSnapshot('./out/ansi.html') | ||
}) | ||
|
||
// https://github.com/shikijs/shiki/issues/432 | ||
it('renders ansi with background', async () => { | ||
const code = ` | ||
[0;32;1m❯[0m [0;32mpnpm[0m install --force[0m | ||
[0;30;43m WARN [0m using --force I sure hope you know what you are doing[0m | ||
Scope: all 6 workspace projects[0m | ||
Lockfile is up to date, resolution step is skipped[0m | ||
Packages: [0;32m+1038[0m[0m | ||
[0;32m++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[0m | ||
`.trim() | ||
|
||
const out = await codeToHtml(code, { theme: 'monokai', lang: 'ansi' }) | ||
|
||
expect(out).toMatchFileSnapshot('./out/ansi-background.html') | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.