From 6d3345b24c7e58ccb3f228d9395996b3c3f5a216 Mon Sep 17 00:00:00 2001 From: Louis-Maxime Piton Date: Sun, 10 Aug 2025 19:38:15 +0200 Subject: [PATCH] Docs: fix missing "Copy to clipboard" tooltips when `` was used, not just `` (#41582) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Co-authored-by: Julien Déramond --- site/src/components/shortcodes/Code.astro | 39 ++++++++++++-------- site/src/components/shortcodes/Example.astro | 6 +-- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/site/src/components/shortcodes/Code.astro b/site/src/components/shortcodes/Code.astro index 231002a50b..ba2c61165f 100644 --- a/site/src/components/shortcodes/Code.astro +++ b/site/src/components/shortcodes/Code.astro @@ -33,15 +33,20 @@ interface Props { * This takes precedence over the `code` prop. */ filePath?: string + /** + * Defines if the `` component is nested inside an `` component or not. + * @default false + */ + nestedInExample?: boolean } -const { class: className, code, containerClass, fileMatch, filePath, lang } = Astro.props +const { class: className, code, containerClass, fileMatch, filePath, lang, nestedInExample = false } = Astro.props let codeToDisplay = filePath ? fs.readFileSync(path.join(process.cwd(), filePath), 'utf8') : Array.isArray(code) - ? code.join('\n') - : code + ? code.join('\n') + : code if (filePath && fileMatch && codeToDisplay) { const match = codeToDisplay.match(new RegExp(fileMatch)) @@ -130,19 +135,23 @@ if (filePath && fileMatch && codeToDisplay) { }) -
+
{ - Astro.slots.has('pre') ? ( - - ) : ( -
- -
- ) + nestedInExample + ? (<>) + : Astro.slots.has('pre') + ? ( + + ) + : ( +
+ +
+ ) }
{ diff --git a/site/src/components/shortcodes/Example.astro b/site/src/components/shortcodes/Example.astro index a09fffeb31..044e1af4d4 100644 --- a/site/src/components/shortcodes/Example.astro +++ b/site/src/components/shortcodes/Example.astro @@ -1,6 +1,6 @@ --- import { replacePlaceholdersInHtml } from '@libs/placeholder' -import { Prism } from '@astrojs/prism' +import Code from '@components/shortcodes/Code.astro' interface Props { /** @@ -96,9 +96,7 @@ const simplifiedMarkup = markup
)} -
- -
+ ) } -- 2.47.2