Skip to content

Commit

Permalink
refactor: avoid circular refs
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jan 14, 2024
1 parent 6e41739 commit 6968e6f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions packages/shikiji-core/src/tokenizer-ansi.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { createAnsiSequenceParser, createColorPalette, namedColors } from 'ansi-sequence-parser'
import type { ThemeRegistrationResolved, ThemedToken, TokenizeWithThemeOptions } from './types'
import { FontStyle } from './types'
import { applyColorReplacements } from './tokenizer'
import { splitLines } from '.'
import { applyColorReplacements, splitLines } from './utils'

export function tokenizeAnsiWithTheme(
theme: ThemeRegistrationResolved,
Expand Down
6 changes: 1 addition & 5 deletions packages/shikiji-core/src/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { IGrammar } from './textmate'
import { INITIAL } from './textmate'
import type { CodeToThemedTokensOptions, FontStyle, ShikiInternal, ThemeRegistrationResolved, ThemedToken, ThemedTokenScopeExplanation, TokenizeWithThemeOptions } from './types'
import { StackElementMetadata } from './stack-element-metadata'
import { isPlaintext, splitLines } from './utils'
import { applyColorReplacements, isPlaintext, splitLines } from './utils'
import { tokenizeAnsiWithTheme } from './tokenizer-ansi'

export function codeToThemedTokens(
Expand Down Expand Up @@ -198,7 +198,3 @@ function explainThemeScope(
}
return result
}

export function applyColorReplacements(color: string, replacements?: Record<string, string>): string {
return replacements?.[color.toLowerCase()] || color
}
4 changes: 4 additions & 0 deletions packages/shikiji-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ export function addClassToHast(node: Element, className: string | string[]) {
node.properties.class.push(c)
}
}

export function applyColorReplacements(color: string, replacements?: Record<string, string>): string {
return replacements?.[color.toLowerCase()] || color
}
2 changes: 1 addition & 1 deletion packages/shikiji-twoslash/style-rich.css
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
background-color: var(--twoslash-tag-bg);
border-left: 3px solid var(--twoslash-tag-color);
color: var(--twoslash-tag-color);
padding: 6px 6px;
padding: 6px 10px;
margin: 0.2em 0;
display: flex;
align-items: center;
Expand Down

0 comments on commit 6968e6f

Please sign in to comment.