From e20403697e3121bed473d7bcb3c82e03c2487129 Mon Sep 17 00:00:00 2001 From: Julien Cayzac Date: Sat, 3 Aug 2024 11:47:24 +0900 Subject: [PATCH 1/6] fix: code component was missing support for meta string Fixed #11604 --- packages/astro/components/Code.astro | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/astro/components/Code.astro b/packages/astro/components/Code.astro index 0cc639d7d577..5d4cfa05e0a4 100644 --- a/packages/astro/components/Code.astro +++ b/packages/astro/components/Code.astro @@ -23,6 +23,12 @@ interface Props extends Omit, 'lang'> { * @default "plaintext" */ lang?: BuiltinLanguage | SpecialLanguage | LanguageRegistration; + /** + * A metastring to pass to the highlighter. + * + * @default undefined + */ + meta?: string; /** * The styling theme. * Supports all themes listed here: https://shiki.style/themes @@ -72,6 +78,7 @@ interface Props extends Omit, 'lang'> { const { code, lang = 'plaintext', + meta, theme = 'github-dark', themes = {}, defaultColor = 'light', @@ -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, }); --- From 988f54d0c0af320d015fc043c142f4400ea85edc Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Mon, 5 Aug 2024 13:57:26 +0200 Subject: [PATCH 2/6] Create odd-buttons-pay.md --- .changeset/odd-buttons-pay.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .changeset/odd-buttons-pay.md diff --git a/.changeset/odd-buttons-pay.md b/.changeset/odd-buttons-pay.md new file mode 100644 index 000000000000..3ff2b8d9c367 --- /dev/null +++ b/.changeset/odd-buttons-pay.md @@ -0,0 +1,15 @@ +--- +"astro": minor +--- + +Adds support for passing a metastring when using the Code component. + +The following code is equivalent to doing `` ```js astro=cool `` in Markdown. + +```astro +--- +import { Code } from "astro:components"; +--- + + +``` From e3624a05ca4f01de2c90254bc1976e7e31db09e1 Mon Sep 17 00:00:00 2001 From: Julien Cayzac Date: Sat, 10 Aug 2024 09:13:16 +0900 Subject: [PATCH 3/6] : add reference link for meta prop --- packages/astro/components/Code.astro | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/astro/components/Code.astro b/packages/astro/components/Code.astro index 5d4cfa05e0a4..d1c019c60d1b 100644 --- a/packages/astro/components/Code.astro +++ b/packages/astro/components/Code.astro @@ -25,6 +25,7 @@ interface Props extends Omit, 'lang'> { lang?: BuiltinLanguage | SpecialLanguage | LanguageRegistration; /** * A metastring to pass to the highlighter. + * Allows passing information to transformers: https://shiki.style/guide/transformers#meta * * @default undefined */ From f1ab60c63f2f8736c15dffb7d19da10eb53a6392 Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Mon, 12 Aug 2024 17:02:08 +0200 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: Sarah Rainsberger --- .changeset/odd-buttons-pay.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.changeset/odd-buttons-pay.md b/.changeset/odd-buttons-pay.md index 3ff2b8d9c367..068fcd7b43fd 100644 --- a/.changeset/odd-buttons-pay.md +++ b/.changeset/odd-buttons-pay.md @@ -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 `` 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 --- import { Code } from "astro:components"; +import { transformerMetaHighlight } from '@shikijs/transformers'; --- - - + ``` From 16304d262847eb0f769de588d95a6ca6b55e3ea8 Mon Sep 17 00:00:00 2001 From: Sarah Rainsberger Date: Tue, 13 Aug 2024 08:36:27 -0300 Subject: [PATCH 5/6] Update .changeset/odd-buttons-pay.md --- .changeset/odd-buttons-pay.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/odd-buttons-pay.md b/.changeset/odd-buttons-pay.md index 068fcd7b43fd..564481efe7bc 100644 --- a/.changeset/odd-buttons-pay.md +++ b/.changeset/odd-buttons-pay.md @@ -9,8 +9,8 @@ This allows you to provide a value for [Shiki's `meta` attribute](https://shiki. The following example passes an option to highlight lines 1 and 3 to Shiki's `tranformerMetaHighlight`: ```astro -// src/pages/index.astro --- +// src/components/Card.astro import { Code } from "astro:components"; import { transformerMetaHighlight } from '@shikijs/transformers'; --- From 2d20fb752b83dd26ffcb2a7c558d41cfc45cdd03 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 14 Aug 2024 11:02:19 +0100 Subject: [PATCH 6/6] Update .changeset/odd-buttons-pay.md Co-authored-by: Sarah Rainsberger --- .changeset/odd-buttons-pay.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/odd-buttons-pay.md b/.changeset/odd-buttons-pay.md index 564481efe7bc..728068ef2a5f 100644 --- a/.changeset/odd-buttons-pay.md +++ b/.changeset/odd-buttons-pay.md @@ -2,7 +2,7 @@ "astro": minor --- -Adds a new property `meta` to Astro's built-in `` component. +Adds a new property `meta` to Astro's [built-in `` component](https://docs.astro.build/en/reference/api-reference/#code-). This allows you to provide a value for [Shiki's `meta` attribute](https://shiki.style/guide/transformers#meta) to pass options to transformers.