Skip to content

Commit

Permalink
Add Shiki's defaultColor option to <Code /> (#11391)
Browse files Browse the repository at this point in the history
  • Loading branch information
ARipeAppleByYoursTruly authored Jul 17, 2024
1 parent b46a78e commit 6f9b527
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-dodos-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': minor
---

Adds Shiki's [`defaultColor`](https://shiki.style/guide/dual-themes#without-default-color) option to the `<Code />` component, giving you more control in applying multiple themes
12 changes: 12 additions & 0 deletions packages/astro/components/Code.astro
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ interface Props extends Omit<HTMLAttributes<'pre'>, 'lang'> {
* Supports all themes found above; see https://shiki.style/guide/dual-themes for more information.
*/
themes?: Record<string, ThemePresets | ThemeRegistration | ThemeRegistrationRaw>;
/**
* Chooses a theme from the "themes" option that you've defined as the default styling theme.
* - <string>: one of the keys defined in the "themes" option. Will throw an error if the key is not defined.
* - false: disabled. You'll have to apply the styling theme yourself. No effect if the "themes" option is not set.
*
* See https://shiki.style/guide/dual-themes#without-default-color for more information.
*
* @default "light"
*/
defaultColor?: 'light' | 'dark' | string | false
/**
* Enable word wrapping.
* - true: enabled.
Expand Down Expand Up @@ -64,6 +74,7 @@ const {
lang = 'plaintext',
theme = 'github-dark',
themes = {},
defaultColor = 'light',
wrap = false,
inline = false,
transformers = [],
Expand Down Expand Up @@ -92,6 +103,7 @@ const highlighter = await getCachedHighlighter({
],
theme,
themes,
defaultColor,
wrap,
transformers,
});
Expand Down

0 comments on commit 6f9b527

Please sign in to comment.