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
Changes from 1 commit
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: 11 additions & 4 deletions .changeset/odd-buttons-pay.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
"astro": minor
---

Adds support for passing a metastring when using the Code component.
Adds a new property `meta` to Astro's built-in `<Code />` component.

The following code is equivalent to doing `` ```js astro=cool `` in Markdown.
This allows you to provide a value for [Shiki's `meta` attribute](https://shiki.style/guide/transformers#meta) to pass options to transformers.

The following example passes an option to highlight lines 1 and 3 to Shiki's `tranformerMetaHighlight`:

```astro
// src/pages/index.astro
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably would not be a page, since it doesn't have a layout and just calls a component, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! We could fix this by changing it to be a component URL, or by adding some HTML comment for "missing stuff". I'll update to a component name, but the other would be fine if you want to suggest it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is invalid Astro markup. Comments above the --- mark are not allowed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'oh, great catch! I'm so spoiled living in the docs repo... (we always just use title= there)

---
import { Code } from "astro:components";
import { transformerMetaHighlight } from '@shikijs/transformers';
---

<Code code="console.log('Hello, Astro!')" lang={"js"} meta="astro=cool" />
<Code
code={code}
lang="js"
transformers={[transformerMetaHighlight()]}
meta="{1,3}" />
```
Loading