Skip to content

Commit 2a23230

Browse files
authored
fix: support ANSI language with multiple themes (#1259)
1 parent 69bec64 commit 2a23230

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

packages/core/src/highlight/code-to-tokens.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function codeToTokens(
4242
primitive,
4343
code,
4444
options,
45+
codeToTokensBase,
4546
)
4647

4748
grammarState = getLastGrammarStateFromMap(themeTokens)

packages/primitive/src/highlight/code-to-tokens-themes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ export function codeToTokensWithThemes(
1414
primitive: ShikiPrimitive,
1515
code: string,
1616
options: CodeToTokensWithThemesOptions,
17+
codeToTokensBaseFn: typeof codeToTokensBase = codeToTokensBase,
1718
): ThemedTokenWithVariants[][] {
1819
const themes = Object
1920
.entries(options.themes)
2021
.filter(i => i[1])
2122
.map(i => ({ color: i[0], theme: i[1]! }))
2223

2324
const themedTokens = themes.map((t) => {
24-
const tokens = codeToTokensBase(primitive, code, {
25+
const tokens = codeToTokensBaseFn(primitive, code, {
2526
...options,
2627
theme: t.theme,
2728
})

packages/shiki/test/ansi.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,13 @@ Done in 15.7s`, { theme: 'dark-plus', lang: 'ansi' })
4444

4545
await expect(out).toMatchFileSnapshot('./out/ansi-dark-plus.html')
4646
})
47+
48+
// https://github.com/shikijs/shiki/issues/1257
49+
it('renders ansi with multiple themes', async () => {
50+
const out = await codeToHtml('\x1B[32mhello\x1B[0m', {
51+
lang: 'ansi',
52+
themes: { light: 'github-light', dark: 'github-dark' },
53+
})
54+
55+
await expect(out).toMatchFileSnapshot('./out/ansi-multi-themes.html')
56+
})

packages/shiki/test/out/ansi-multi-themes.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)