From 4598bf4b6c8129f7ac10e313b1d496b7982e2b30 Mon Sep 17 00:00:00 2001 From: hippotastic <6137925+hippotastic@users.noreply.github.com> Date: Mon, 29 Jan 2024 17:51:43 +0100 Subject: [PATCH] Add Starlight types to `defineEcConfig` and export `StarlightExpressiveCodeOptions` --- .changeset/calm-roses-joke.md | 7 ++++ .../integrations/expressive-code/exports.ts | 32 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 .changeset/calm-roses-joke.md diff --git a/.changeset/calm-roses-joke.md b/.changeset/calm-roses-joke.md new file mode 100644 index 00000000000..b2f7f10a6d7 --- /dev/null +++ b/.changeset/calm-roses-joke.md @@ -0,0 +1,7 @@ +--- +'@astrojs/starlight': patch +--- + +Adds Starlight-specific types to `defineEcConfig` function and exports `StarlightExpressiveCodeOptions`. + +This provides Starlight types and IntelliSense support for your Expressive Code configuration options inside an `ec.config.mjs` file. See the [Expressive Code documentation](https://expressive-code.com/key-features/code-component/#using-an-ecconfigmjs-file) for more information. diff --git a/packages/starlight/integrations/expressive-code/exports.ts b/packages/starlight/integrations/expressive-code/exports.ts index e789b0857a4..3616c08d2df 100644 --- a/packages/starlight/integrations/expressive-code/exports.ts +++ b/packages/starlight/integrations/expressive-code/exports.ts @@ -35,4 +35,36 @@ export * from 'astro-expressive-code'; +import type { StarlightExpressiveCodeOptions } from './index'; + +export type { 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 + * ```js + * // ec.config.mjs + * import { defineEcConfig } from '@astrojs/starlight/expressive-code' + * + * export default defineEcConfig({ + * themes: ['starlight-dark', 'github-light'], + * styleOverrides: { + * borderRadius: '0.5rem', + * }, + * }) + * ``` + */ +export function defineEcConfig(config: StarlightExpressiveCodeOptions) { + return config; +} + export { getStarlightEcConfigPreprocessor } from './index';