Skip to content

Commit d2cb35d

Browse files
fix: export lang types for use in custom component (#14071)
Co-authored-by: Florian Lefebvre <[email protected]>
1 parent d271698 commit d2cb35d

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

.changeset/clever-numbers-sink.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Exposes the `Code` component `lang` prop type:
6+
7+
```ts
8+
import type { CodeLanguage } from "astro";
9+
```

packages/astro/components/Code.astro

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
---
22
import type { ThemePresets } from '@astrojs/markdown-remark';
3-
import type {
4-
BuiltinLanguage,
5-
LanguageRegistration,
6-
ShikiTransformer,
7-
SpecialLanguage,
8-
ThemeRegistration,
9-
ThemeRegistrationRaw,
10-
} from 'shiki';
3+
import type { ShikiTransformer, ThemeRegistration, ThemeRegistrationRaw } from 'shiki';
114
import { bundledLanguages } from 'shiki/langs';
125
import { getCachedHighlighter } from '../dist/core/shiki.js';
6+
import type { CodeLanguage } from '../dist/types/public';
137
import type { HTMLAttributes } from '../types';
148
159
interface Props extends Omit<HTMLAttributes<'pre'>, 'lang'> {
@@ -22,7 +16,7 @@ interface Props extends Omit<HTMLAttributes<'pre'>, 'lang'> {
2216
*
2317
* @default "plaintext"
2418
*/
25-
lang?: BuiltinLanguage | SpecialLanguage | LanguageRegistration;
19+
lang?: CodeLanguage;
2620
/**
2721
* A metastring to pass to the highlighter.
2822
* Allows passing information to transformers: https://shiki.style/guide/transformers#meta

packages/astro/src/types/public/common.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { BundledLanguage, LanguageRegistration, SpecialLanguage } from 'shiki';
12
import type { OmitIndexSignature, Simplify } from '../../type-utils.js';
23
import type { APIContext } from './context.js';
34

@@ -180,3 +181,5 @@ export type InferGetStaticPropsType<T> = T extends (
180181

181182
export type Params = Record<string, string | undefined>;
182183
export type Props = Record<string, unknown>;
184+
185+
export type CodeLanguage = BundledLanguage | LanguageRegistration | SpecialLanguage;

0 commit comments

Comments
 (0)