Skip to content

Configuring EC-Twoslash

Expressive Code Twoslash (EC-Twoslash) is highly configurable, allowing you to tailor its behavior to fit your specific needs. This section provides an overview of the various configuration options available, including how to customize the appearance of code blocks, enable or disable specific features, and integrate with other tools.

Example Configuration:

ec.config.mjs
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.

@example

// ec.config.mjs
import { defineEcConfig } from 'astro-expressive-code'
export default defineEcConfig({
themes: ['dracula', 'github-light'],
styleOverrides: {
borderRadius: '0.5rem',
},
})

defineEcConfig
} from 'astro-expressive-code';
import
function ecTwoSlash(options?: PluginTwoslashOptions): ExpressiveCodePlugin

Add Twoslash support to your Expressive Code TypeScript code blocks.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

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.

@example

// ec.config.mjs
import { defineEcConfig } from 'astro-expressive-code'
export default defineEcConfig({
themes: ['dracula', 'github-light'],
styleOverrides: {
borderRadius: '0.5rem',
},
})

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.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

ecTwoSlash
()],
});

The instanceConfigs option allows for configuring the included twoslasher instances. This is useful for customizing the behavior of specific Twoslash instances based on the trigger and language. For example, you can configure one instance to handle TypeScript code blocks and another instance to handle Vue code blocks, each with its own set of options and transformations.

Type: boolean | RegExp Default: true

The explicitTrigger option determines how EC-Twoslash identifies which code blocks should be processed with Twoslash transformations. When set to true, EC-Twoslash will only process code blocks that contain an explicit trigger annotation (e.g., // @twoslash for JavaScript/TypeScript). When set to a regular expression, EC-Twoslash will use the provided regex to match against the content of the code blocks to determine if they should be processed. If set to false, EC-Twoslash will process all code blocks of the specified languages without requiring any trigger annotations.

Type: ReadonlyArray<string> Default: ["ts", "tsx", "vue"]
ec.config.mjs
import {
function defineEcConfig(config: StarlightExpressiveCodeOptions): StarlightExpressiveCodeOptions

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 Starlight 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.

@example

// ec.config.mjs
import { defineEcConfig } from '@astrojs/starlight/expressive-code'
export default defineEcConfig({
themes: ['starlight-dark', 'github-light'],
styleOverrides: {
borderRadius: '0.5rem',
},
})

defineEcConfig
} from "@astrojs/starlight/expressive-code";
import
function ecTwoSlash(options?: PluginTwoslashOptions): ExpressiveCodePlugin

Add Twoslash support to your Expressive Code TypeScript code blocks.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

ecTwoSlash
from "expressive-code-twoslash";
export default
function defineEcConfig(config: StarlightExpressiveCodeOptions): StarlightExpressiveCodeOptions

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 Starlight 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.

@example

// ec.config.mjs
import { defineEcConfig } from '@astrojs/starlight/expressive-code'
export default defineEcConfig({
themes: ['starlight-dark', 'github-light'],
styleOverrides: {
borderRadius: '0.5rem',
},
})

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.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

ecTwoSlash
({
PluginTwoslashOptions.instanceConfigs?: {
twoslash?: {
explicitTrigger?: boolean | RegExp;
languages?: ReadonlyArray<string>;
};
eslint?: {
explicitTrigger?: boolean | RegExp;
languages?: ReadonlyArray<string>;
};
} | undefined

Allows for configuring the included twoslasher instances and their triggers.

instanceConfigs
: {
twoslash?: {
explicitTrigger?: boolean | RegExp;
languages?: ReadonlyArray<string>;
} | undefined

Standard Twoslash instance configuration.

twoslash
: {
explicitTrigger?: boolean | RegExp | undefined

If true, requires twoslash to be present in the code block meta for this transformer to be applied.

If a RegExp, requires the RegExp to match a directive in the code block meta for this transformer to be applied.

If false, this transformer will be applied to all code blocks that match the specified languages.

It is recommended to keep this as true to avoid unnecessary processing.

@defaulttrue

explicitTrigger
: true,
languages?: readonly string[] | undefined

The languages to apply this transformer to.

@default["ts", "tsx", "vue"]

languages
: ["ts", "tsx", "vue"],
},
},
}),
],
});

For configuring the eslint Twoslasher instance, the options are the same as for the twoslash instance, but they will only apply to code blocks that match the trigger and language specified for the eslint instance. For example, you can configure the eslint instance to only process TypeScript code blocks that contain an eslint trigger annotation.

Type: boolean | RegExp Default: true
Type: ReadonlyArray<string> Default: ["ts", "tsx"]
ec.config.mjs
import {
function defineEcConfig(config: StarlightExpressiveCodeOptions): StarlightExpressiveCodeOptions

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 Starlight 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.

@example

// ec.config.mjs
import { defineEcConfig } from '@astrojs/starlight/expressive-code'
export default defineEcConfig({
themes: ['starlight-dark', 'github-light'],
styleOverrides: {
borderRadius: '0.5rem',
},
})

defineEcConfig
} from "@astrojs/starlight/expressive-code";
import
function ecTwoSlash(options?: PluginTwoslashOptions): ExpressiveCodePlugin

Add Twoslash support to your Expressive Code TypeScript code blocks.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

ecTwoSlash
from "expressive-code-twoslash";
export default
function defineEcConfig(config: StarlightExpressiveCodeOptions): StarlightExpressiveCodeOptions

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 Starlight 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.

@example

// ec.config.mjs
import { defineEcConfig } from '@astrojs/starlight/expressive-code'
export default defineEcConfig({
themes: ['starlight-dark', 'github-light'],
styleOverrides: {
borderRadius: '0.5rem',
},
})

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.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

ecTwoSlash
({
PluginTwoslashOptions.instanceConfigs?: {
twoslash?: {
explicitTrigger?: boolean | RegExp;
languages?: ReadonlyArray<string>;
};
eslint?: {
explicitTrigger?: boolean | RegExp;
languages?: ReadonlyArray<string>;
};
} | undefined

Allows for configuring the included twoslasher instances and their triggers.

instanceConfigs
: {
eslint?: {
explicitTrigger?: boolean | RegExp;
languages?: ReadonlyArray<string>;
} | undefined

ESLint Twoslash instance configuration.

Unlike the standard Twoslash instance, the ESLint Twoslash instance uses eslint as its meta trigger for code blocks, and it is designed to work with JavaScript and TypeScript code blocks that contain ESLint errors. When a code block is annotated with eslint, the ESLint Twoslash instance will parse the code and display any ESLint errors as annotations in the code block.

eslint
: {
explicitTrigger?: boolean | RegExp | undefined

If true, requires eslint to be present in the code block meta for this transformer to be applied.

If a RegExp, requires the RegExp to match a directive in the code block meta for this transformer to be applied.

If false, this transformer will be applied to all code blocks that match the specified languages.

It is recommended to keep this as true to avoid unnecessary processing.

explicitTrigger
: true,
languages?: readonly string[] | undefined

The languages to apply this transformer to.

@default["ts", "tsx"]

languages
: ["ts", "tsx"],
},
},
}),
],
});
Type: string Default: process.cwd()

Optionally specify the current working directory for the Twoslash instances. This can be useful if you want to change the base directory from which Twoslash resolves modules and files. By default, Twoslash uses the current working directory of the process, but you can set this option to any valid directory path to customize where Twoslash looks for files and modules.

ec.config.mjs
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.

@example

// ec.config.mjs
import { defineEcConfig } from 'astro-expressive-code'
export default defineEcConfig({
themes: ['dracula', 'github-light'],
styleOverrides: {
borderRadius: '0.5rem',
},
})

defineEcConfig
} from 'astro-expressive-code';
import
function ecTwoSlash(options?: PluginTwoslashOptions): ExpressiveCodePlugin

Add Twoslash support to your Expressive Code TypeScript code blocks.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

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.

@example

// ec.config.mjs
import { defineEcConfig } from 'astro-expressive-code'
export default defineEcConfig({
themes: ['dracula', 'github-light'],
styleOverrides: {
borderRadius: '0.5rem',
},
})

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.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

ecTwoSlash
({
PluginTwoslashOptions.cwd?: string | undefined

Current working directory to resolve files from for includes and the virtual file system.

@defaultprocess.cwd()

cwd
: "/path/to/your/directory", // Set the current working directory for Twoslash
}),
],
});
Type: string Default: undefined

The tsConfigPath option allows you to specify the path to a custom tsconfig.json file that Twoslash should use when processing TypeScript code blocks. This is useful if you want to provide specific TypeScript compiler options or include/exclude certain files from the Twoslash transformations. By default, Twoslash will look for a tsconfig.json file in the current working directory, but you can set this option to point to any valid tsconfig.json file in your project.

ec.config.mjs
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.

@example

// ec.config.mjs
import { defineEcConfig } from 'astro-expressive-code'
export default defineEcConfig({
themes: ['dracula', 'github-light'],
styleOverrides: {
borderRadius: '0.5rem',
},
})

defineEcConfig
} from 'astro-expressive-code';
import
function ecTwoSlash(options?: PluginTwoslashOptions): ExpressiveCodePlugin

Add Twoslash support to your Expressive Code TypeScript code blocks.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

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.

@example

// ec.config.mjs
import { defineEcConfig } from 'astro-expressive-code'
export default defineEcConfig({
themes: ['dracula', 'github-light'],
styleOverrides: {
borderRadius: '0.5rem',
},
})

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.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

ecTwoSlash
({
PluginTwoslashOptions.tsConfigPath?: string | undefined

An optional path to a tsconfig.json file to use as the basis for the compiler options when running Twoslash.

If not provided, Twoslash will look for a tsconfig.json file in the cwd and use it if found. If no tsconfig.json file is found, Twoslash will use a default set of compiler options.

tsConfigPath
: "tsconfig-twoslash.json", // Specify a custom tsconfig.json file for Twoslash
}),
],
});
Type: boolean Default: true

The includeJsDoc option determines whether JSDoc comments should be included in the hover information provided by EC-Twoslash. When set to true, EC-Twoslash will include JSDoc comments in the hover popup, providing additional context and documentation for the code being hovered over. If set to false, JSDoc comments will be excluded from the hover information, resulting in a more concise hover popup that only includes type information and other relevant details.

ec.config.mjs
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.

@example

// ec.config.mjs
import { defineEcConfig } from 'astro-expressive-code'
export default defineEcConfig({
themes: ['dracula', 'github-light'],
styleOverrides: {
borderRadius: '0.5rem',
},
})

defineEcConfig
} from 'astro-expressive-code';
import
function ecTwoSlash(options?: PluginTwoslashOptions): ExpressiveCodePlugin

Add Twoslash support to your Expressive Code TypeScript code blocks.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

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.

@example

// ec.config.mjs
import { defineEcConfig } from 'astro-expressive-code'
export default defineEcConfig({
themes: ['dracula', 'github-light'],
styleOverrides: {
borderRadius: '0.5rem',
},
})

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.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

ecTwoSlash
({
PluginTwoslashOptions.includeJsDoc?: boolean | undefined

If true, includes JSDoc comments in the hover popup.

@defaulttrue

includeJsDoc
: false, // Exclude JSDoc comments from hover information
}),
],
});
Type: boolean Default: true

The allowNonStandardJsDocTags option determines whether non-standard JSDoc tags should be included in the hover information provided by EC-Twoslash. When set to true, EC-Twoslash will include non-standard JSDoc tags in the hover popup, allowing you to see custom documentation that may not be part of the standard JSDoc specification. If set to false, only standard JSDoc tags will be included in the hover information, resulting in a more streamlined hover popup that focuses on commonly used documentation tags.

ec.config.mjs
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.

@example

// ec.config.mjs
import { defineEcConfig } from 'astro-expressive-code'
export default defineEcConfig({
themes: ['dracula', 'github-light'],
styleOverrides: {
borderRadius: '0.5rem',
},
})

defineEcConfig
} from 'astro-expressive-code';
import
function ecTwoSlash(options?: PluginTwoslashOptions): ExpressiveCodePlugin

Add Twoslash support to your Expressive Code TypeScript code blocks.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

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.

@example

// ec.config.mjs
import { defineEcConfig } from 'astro-expressive-code'
export default defineEcConfig({
themes: ['dracula', 'github-light'],
styleOverrides: {
borderRadius: '0.5rem',
},
})

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.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

ecTwoSlash
({
PluginTwoslashOptions.allowNonStandardJsDocTags?: boolean | undefined

Allows non-standard JSDoc tags to be included in the hover popup.

Non-standard tags are tags that are not included in the default JSDoc tag list.

@example @customTag, @docs, @omglookatthis

@defaulttrue

allowNonStandardJsDocTags
: false, // Exclude non-standard JSDoc tags from hover information
}),
],
});
Type: TwoslashOptions Default: {}

The twoslashOptions option allows you to forward additional options directly to the twoslash preprocessor. This is useful for customizing the behavior of Twoslash itself, such as enabling specific features, configuring how code is processed, or adjusting the output of Twoslash transformations. For a full list of available options that can be forwarded to Twoslash, see the Twoslash documentation.

ec.config.mjs
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.

@example

// ec.config.mjs
import { defineEcConfig } from 'astro-expressive-code'
export default defineEcConfig({
themes: ['dracula', 'github-light'],
styleOverrides: {
borderRadius: '0.5rem',
},
})

defineEcConfig
} from 'astro-expressive-code';
import
function ecTwoSlash(options?: PluginTwoslashOptions): ExpressiveCodePlugin

Add Twoslash support to your Expressive Code TypeScript code blocks.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

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.

@example

// ec.config.mjs
import { defineEcConfig } from 'astro-expressive-code'
export default defineEcConfig({
themes: ['dracula', 'github-light'],
styleOverrides: {
borderRadius: '0.5rem',
},
})

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.

@paramoptions - Configuration options for the plugin.

@seehttps://twoslash.studiocms.dev for the full documentation.

@returnsA plugin object with the specified configuration.

ecTwoSlash
({
PluginTwoslashOptions.twoslashOptions?: TwoslashOptions | undefined

Options to forward to twoslash.

@default{}

twoslashOptions
: {
// Twoslash options go here
},
}),
],
});
Type: VueSpecificTwoslashOptions Default: {}

Options to forward to twoslash-vue.

This option is only used if the vue language is included in the languages option and will be ignored otherwise. It allows you to customize the behavior of the twoslash-vue preprocessor, which is responsible for handling Vue-specific features in EC-Twoslash. For a full list of available options that can be forwarded to twoslash-vue, see the Twoslash Vue documentation.

Type: CreateTwoslashESLintOptions Default: {}

Options to forward to twoslash-eslint.

This option is only used if the eslint instance is configured in the instanceConfigs option and will be ignored otherwise. It allows you to customize the behavior of the twoslash-eslint preprocessor, which is responsible for handling ESLint-specific features in EC-Twoslash. For a full list of available options that can be forwarded to twoslash-eslint, see the Twoslash ESLint documentation.

The VueSpecificTwoslashOptions type represents the options that can be forwarded to twoslash-vue, excluding the standard Twoslash options. This type is derived by omitting the keys of TwoslashOptions from CreateTwoslashVueOptions, ensuring that only Vue-specific options are included.

type VueSpecificTwoslashOptions = {
debugShowGeneratedCode?: boolean;
vueCompilerOptions?: Partial<RawVueCompilerOptions>;
}

The CreateTwoslashESLintOptions type represents the options that can be forwarded to twoslash-eslint, excluding the standard Twoslash options. This type is derived by omitting the keys of TwoslashOptions from CreateTwoslashESLintOptions, ensuring that only ESLint-specific options are included.

type CreateTwoslashESLintOptions = {
/**
* Flat configs for ESLint
*/
eslintConfig: Linter.FlatConfig[];
/**
* Custom code transform before sending to ESLint for verification
*
* This does not affect the code rendering
*/
eslintCodePreprocess?: (code: string) => string;
/**
* The current working directory for ESLint
*/
cwd?: string;
/**
* Include the parsed docs in the result
*
* @default true
*/
includeDocs?: boolean;
/**
* Merge error messages that has same range
* @default true
*/
mergeMessages?: boolean;
}