From 655aed4840cae59e9abd64b4b585e60f1cfab209 Mon Sep 17 00:00:00 2001 From: Hippo Date: Mon, 29 Jan 2024 23:52:57 +0100 Subject: Add Starlight types to `defineEcConfig` and export `StarlightExpressiveCodeOptions` (#1437) --- .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 00000000..b2f7f10a --- /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 e789b085..3616c08d 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'; -- cgit