Style Overrides
EC-Twoslash provides several options for customizing the appearance of code blocks, including the ability to override default styles. This section covers the various style override options available in EC-Twoslash, allowing you to tailor the look and feel of your code examples to better fit your project’s design.
Example Configuration:
import { function defineEcConfig(config: AstroExpressiveCodeOptions): AstroExpressiveCodeOptions
A utility function that helps you define an Expressive Code configuration object. It is meant
to be used inside the optional config file ec.config.mjs located in the root directory
of your Astro project, and its return value to be exported as the default export.
Expressive Code will automatically detect this file and use the exported configuration object
to override its own default settings.
Using this function is recommended, but not required. It just passes through the given object,
but it also provides type information for your editor's auto-completion and type checking.
defineEcConfig } from 'astro-expressive-code';import function ecTwoSlash(options?: PluginTwoslashOptions): ExpressiveCodePlugin
Add Twoslash support to your Expressive Code TypeScript code blocks.
ecTwoSlash from "expressive-code-twoslash";
export default function defineEcConfig(config: AstroExpressiveCodeOptions): AstroExpressiveCodeOptions
A utility function that helps you define an Expressive Code configuration object. It is meant
to be used inside the optional config file ec.config.mjs located in the root directory
of your Astro project, and its return value to be exported as the default export.
Expressive Code will automatically detect this file and use the exported configuration object
to override its own default settings.
Using this function is recommended, but not required. It just passes through the given object,
but it also provides type information for your editor's auto-completion and type checking.
defineEcConfig({ plugins?: (ExpressiveCodePlugin | ExpressiveCodePlugin[])[] | undefined
An optional array of plugins that should be used when rendering code blocks.
To add a plugin, import its initialization function and call it inside this array.
If the plugin has any configuration options, you can pass them to the initialization
function as an object containing your desired property values.
If any nested arrays are found inside the plugins array, they will be flattened
before processing.
plugins: [function ecTwoSlash(options?: PluginTwoslashOptions): ExpressiveCodePlugin
Add Twoslash support to your Expressive Code TypeScript code blocks.
ecTwoSlash()], styleOverrides?: Partial<{ frames: Partial<UnresolvedPluginStyleSettings<FramesStyleSettings>>; textMarkers: Partial<UnresolvedPluginStyleSettings<TextMarkersStyleSettings>>; twoSlash: Partial<UnresolvedPluginStyleSettings<TwoSlashStyleSettings>>; borderRadius: UnresolvedStyleValue; borderWidth: UnresolvedStyleValue; ... 24 more ...; scrollbarThumbHoverColor: UnresolvedStyleValue;}> | undefined
An optional set of style overrides that can be used to customize the appearance of
the rendered code blocks without having to write custom CSS.
The root level of this nested object contains core styles like colors, fonts, paddings
and more. Plugins can contribute their own style settings to this object as well.
For example, if the frames plugin is enabled, you can override its shadowColor by
setting styleOverrides.frames.shadowColor to a color value.
If any of the settings are not given, default values will be used or derived from the theme.
Tip: If your site uses CSS variables for styling, you can also use these overrides
to replace any core style with a CSS variable reference, e.g. var(--your-css-var).
styleOverrides: { twoSlash?: Partial<UnresolvedPluginStyleSettings<TwoSlashStyleSettings>> | undefined
twoSlash: { // Style override options go here }, },})Main Style Overrides
Section titled “Main Style Overrides”borderColor
Section titled “borderColor”({ theme }) => theme.colors["titleBar.border"] || lighten(theme.colors["editor.background"], theme.type === "dark" ? 0.5 : -0.15) || "transparent" Style (Border Color) for the Twoslash Popups
background
Section titled “background”({ theme }) => theme.colors["editor.background"] || theme.bg || "transparent" Style (Background) for the Twoslash Popups
hoverUnderlineColor
Section titled “hoverUnderlineColor”Style (Hover Underline color) for the Twoslash Popups
textColor
Section titled “textColor”({ theme }) => theme.colors["editor.foreground"] || theme.fg || "#ffffff", popupDocsMaxHeight: "200px" Style (Text Color) for the Twoslash Popups
popupDocMaxHeight
Section titled “popupDocMaxHeight”Style (Docs Max Element Height) for the Twoslash Popups
tagColor
Section titled “tagColor”({ theme }) => theme.colors["terminal.ansiBrightBlue"] || theme.colors["terminal.ansiBlue"] || theme.colors.blue || "#75beff" Style (Tag Color) for the Twoslash JSDoc Tags
Link Style Overrides
Section titled “Link Style Overrides”linkColor
Section titled “linkColor”({ theme }) => theme.colors["terminal.ansiBrightBlue"] || theme.colors["terminal.ansiBlue"] || theme.colors.blue || "#75beff" Style (Link Color) for the Twoslash Popups
linkColorHover
Section titled “linkColorHover”({ theme }) => theme.colors["terminal.ansiBrightCyan"] || theme.colors["terminal.ansiCyan"] || theme.colors.cyan || "#75ffff" Style (Link Hover Color) for the Twoslash Popups
linkColorVisited
Section titled “linkColorVisited”({ theme }) => theme.colors["terminal.ansiBrightMagenta"] || theme.colors["terminal.ansiMagenta"] || theme.colors.magenta || "#ff75be" Style (Link Visited Color) for the Twoslash Popups
linkColorActive
Section titled “linkColorActive”({ theme }) => theme.colors["terminal.ansiBrightGreen"] || theme.colors["terminal.ansiGreen"] || theme.colors.green || "#75ff75" Style (Link Active Color) for the Twoslash Popups
Highlight Style Overrides
Section titled “Highlight Style Overrides”highlightHue
Section titled “highlightHue”Style (Hue) for the Twoslash Highlights
Used to calculate the highlightBackground and highlightBorderColor styles
highlightDefaultLuminance
Section titled “highlightDefaultLuminance”Style (Luminance) for the Twoslash Highlights
Used to calculate the highlightBackground and highlightBorderColor styles
highlightDefaultChroma
Section titled “highlightDefaultChroma”Style (Chroma) for the Twoslash Highlights
Used to calculate the highlightBackground and highlightBorderColor styles
highlightBackgroundOpacity
Section titled “highlightBackgroundOpacity”Style (Background Opacity) for the Twoslash Highlights
Used to calculate the highlightBackground and highlightBorderColor styles
highlightBorderLuminance
Section titled “highlightBorderLuminance”Style (Border Luminance) for the Twoslash Highlights
Used to calculate the highlightBackground and highlightBorderColor styles
highlightBorderOpacity
Section titled “highlightBorderOpacity”Style (Border Opacity) for the Twoslash Highlights
Used to calculate the highlightBackground and highlightBorderColor styles
highlightBackground
Section titled “highlightBackground”Style (Background) for the Twoslash Highlights
highlightBorderColor
Section titled “highlightBorderColor”Style (Border) for the Twoslash Highlights
Annotation Style Overrides
Section titled “Annotation Style Overrides”errorColor
Section titled “errorColor”({ theme }) => theme.colors["terminal.ansiRed"] || theme.colors.red || "#ff5555" Style (Error Color) for the Twoslash Error/Custom Annotations
warnColor
Section titled “warnColor”({ theme }) => theme.colors["terminal.ansiYellow"] || theme.colors.yellow || "#ffff55" Style (Warning Color) for the Twoslash Custom Annotations
suggestionColor
Section titled “suggestionColor”({ theme }) => theme.colors["terminal.ansiGreen"] || theme.colors.green || "#55ff55" Style (Suggestion Color) for the Twoslash Custom Annotations
messageColor
Section titled “messageColor”({ theme }) => theme.colors["terminal.ansiBlue"] || theme.colors.blue || "#5555ff" Style (Message Color) for the Twoslash Custom Annotations
Completion Style Overrides
Section titled “Completion Style Overrides”cursorColor
Section titled “cursorColor”({ theme }) => theme.colors["editorCursor.foreground"] || theme.colors["editor.foreground"] || theme.fg Style (Cursor Color) for the Twoslash Completion Box
completionBoxBackground
Section titled “completionBoxBackground”({ theme }) => theme.colors["editorSuggestWidget.background"] || theme.colors["editor.background"] || theme.bg || lighten(theme.colors["editor.background"], theme.type === "dark" ? 0.5 : -0.15) || "transparent" Style (Background) for the Twoslash Completion Box
completionBoxBorder
Section titled “completionBoxBorder”({ theme }) => theme.colors["editorSuggestWidget.border"] || theme.colors["titleBar.border"] || lighten(theme.colors["editor.background"], theme.type === "dark" ? 0.5 : -0.15) || "transparent" Style (Border) for the Twoslash Completion Box
completionBoxColor
Section titled “completionBoxColor”({ theme }) => theme.colors["editorSuggestWidget.foreground"] || theme.colors["editor.foreground"] || theme.fg || "#ffffff" Style (Color) for the Twoslash Completion Box
completionBoxMatchedColor
Section titled “completionBoxMatchedColor”({ theme }) => theme.colors["editorSuggestWidget.highlightForeground"] || theme.colors["editor.findMatchBackground"] || theme.colors["terminal.ansiBrightCyan"] || theme.colors["terminal.ansiCyan"] || theme.colors.cyan || "#75ffff" Style (Matched Color) for the Twoslash Completion Box
completionBoxHoverBackground
Section titled “completionBoxHoverBackground”({ theme }) => theme.colors["editorSuggestWidget.selectedBackground"] || theme.colors["editor.findMatchHighlightBackground"] || "#888" Style (Hover Background) for the Twoslash Completion Box
completionIconString
Section titled “completionIconString”Style (String Icon) for the Twoslash Completion Icons
completionIconFunction
Section titled “completionIconFunction”Style (Function Icon) for the Twoslash Completion Icons
completionIconClass
Section titled “completionIconClass”Style (Class Icon) for the Twoslash Completion Icons
completionIconProperty
Section titled “completionIconProperty”Style (Property Icon) for the Twoslash Completion Icons
completionIconModule
Section titled “completionIconModule”Style (Module Icon) for the Twoslash Completion Icons
completionIconMethod
Section titled “completionIconMethod”Style (Method Icon) for the Twoslash Completion Icons
completionIconConstructor
Section titled “completionIconConstructor”Style (Constructor Icon) for the Twoslash Completion Icons
completionIconInterface
Section titled “completionIconInterface”Style (Interface Icon) for the Twoslash Completion Icons