-
-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Expressive Code to Starlight (#742)
Co-authored-by: Sarah Rainsberger <[email protected]> Co-authored-by: Chris Swithinbank <[email protected]> Co-authored-by: HiDeoo <[email protected]> Co-authored-by: Kevin Zuniga Cuellar <[email protected]> Co-authored-by: Lorenzo Lewis <[email protected]> Co-authored-by: Genteure <[email protected]> Co-authored-by: trueberryless <[email protected]>
- Loading branch information
1 parent
6d14b4f
commit c6a4bcb
Showing
18 changed files
with
4,298 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
'@astrojs/starlight': minor | ||
--- | ||
|
||
Adds Expressive Code as Starlight’s default code block renderer | ||
|
||
⚠️ **Potentially breaking change:** | ||
This addition changes how Markdown code blocks are rendered. By default, Starlight will now use [Expressive Code](https://github.com/expressive-code/expressive-code/tree/main/packages/astro-expressive-code). | ||
If you were already customizing how code blocks are rendered and don't want to use the [features provided by Expressive Code](https://starlight.astro.build/guides/authoring-content/#expressive-code-features), you can preserve the previous behavior by setting the new config option `expressiveCode` to `false`. | ||
|
||
If you had previously added Expressive Code manually to your Starlight project, you can now remove the manual set-up in `astro.config.mjs`: | ||
|
||
- Move your configuration to Starlight’s new `expressiveCode` option. | ||
- Remove the `astro-expressive-code` integration. | ||
|
||
For example: | ||
|
||
```diff | ||
import starlight from '@astrojs/starlight'; | ||
import { defineConfig } from 'astro/config'; | ||
- import expressiveCode from 'astro-expressive-code'; | ||
|
||
export default defineConfig({ | ||
integrations: [ | ||
- expressiveCode({ | ||
- themes: ['rose-pine'], | ||
- }), | ||
starlight({ | ||
title: 'My docs', | ||
+ expressiveCode: { | ||
+ themes: ['rose-pine'], | ||
+ }, | ||
}), | ||
], | ||
}); | ||
``` | ||
|
||
Note that the built-in Starlight version of Expressive Code sets some opinionated defaults that are different from the `astro-expressive-code` defaults. You may need to set some `styleOverrides` if you wish to keep styles exactly the same. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/starlight/integrations/expressive-code/exports.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* @file This file is exported by Starlight as `@astrojs/starlight/expressive-code` | ||
* and can be used in your site's configuration to customize Expressive Code. | ||
* | ||
* It provides access to all of the Expressive Code classes and functions without having | ||
* to install `astro-expressive-code` as an additional dependency into your project | ||
* (and thereby risiking version conflicts). | ||
* | ||
* For example, you can use this to load custom themes from a JSONC file (JSON with comments) | ||
* that would otherwise be difficult to import, and pass them to the `themes` option: | ||
* | ||
* @example | ||
* ```js | ||
* // astro.config.mjs | ||
* import fs from 'node:fs'; | ||
* import { defineConfig } from 'astro/config'; | ||
* import starlight from '@astrojs/starlight'; | ||
* import { ExpressiveCodeTheme } from '@astrojs/starlight/expressive-code'; | ||
* | ||
* const jsoncString = fs.readFileSync(new URL(`./my-theme.jsonc`, import.meta.url), 'utf-8'); | ||
* const myTheme = ExpressiveCodeTheme.fromJSONString(jsoncString); | ||
* | ||
* export default defineConfig({ | ||
* integrations: [ | ||
* starlight({ | ||
* title: 'My Starlight site', | ||
* expressiveCode: { | ||
* themes: [myTheme], | ||
* }, | ||
* }), | ||
* ], | ||
* }); | ||
* ``` | ||
*/ | ||
|
||
export * from 'astro-expressive-code'; |
Oops, something went wrong.