Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: code component was missing support for meta string #11605

Merged
merged 6 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/odd-buttons-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"astro": minor
---

Adds support for passing a metastring when using the Code component.
Princesseuh marked this conversation as resolved.
Show resolved Hide resolved

The following code is equivalent to doing `` ```js astro=cool `` in Markdown.

```astro
---
import { Code } from "astro:components";
---

<Code code="console.log('Hello, Astro!')" lang={"js"} meta="astro=cool" />
```
Princesseuh marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 8 additions & 0 deletions packages/astro/components/Code.astro
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ interface Props extends Omit<HTMLAttributes<'pre'>, 'lang'> {
* @default "plaintext"
*/
lang?: BuiltinLanguage | SpecialLanguage | LanguageRegistration;
/**
* A metastring to pass to the highlighter.
*
* @default undefined
*/
meta?: string;
jcayzac marked this conversation as resolved.
Show resolved Hide resolved
/**
* The styling theme.
* Supports all themes listed here: https://shiki.style/themes
Expand Down Expand Up @@ -72,6 +78,7 @@ interface Props extends Omit<HTMLAttributes<'pre'>, 'lang'> {
const {
code,
lang = 'plaintext',
meta,
theme = 'github-dark',
themes = {},
defaultColor = 'light',
Expand Down Expand Up @@ -110,6 +117,7 @@ const highlighter = await getCachedHighlighter({

const html = await highlighter.highlight(code, typeof lang === 'string' ? lang : lang.name, {
inline,
meta,
attributes: rest as any,
});
---
Expand Down
Loading