]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Docs: fix missing "Copy to clipboard" tooltips when `<Example>` was used, not just... main
authorLouis-Maxime Piton <louismaxime.piton@orange.com>
Sun, 10 Aug 2025 17:38:15 +0000 (19:38 +0200)
committerGitHub <noreply@github.com>
Sun, 10 Aug 2025 17:38:15 +0000 (19:38 +0200)
Co-authored-by: Julien Déramond <juderamond@gmail.com>
site/src/components/shortcodes/Code.astro
site/src/components/shortcodes/Example.astro

index 231002a50b622fed5c884f6983b596de7b07e2e4..ba2c61165fed41c81e28e6e2ffc8b3d7d4189f4b 100644 (file)
@@ -33,15 +33,20 @@ interface Props {
    * This takes precedence over the `code` prop.
    */
   filePath?: string
+  /**
+   * Defines if the `<Code>` component is nested inside an `<Example>` 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) {
   })
 </script>
 
-<div class:list={['bd-code-snippet', containerClass]}>
+<div class:list={[{ 'bd-code-snippet': !nestedInExample }, containerClass]}>
   {
-    Astro.slots.has('pre') ? (
-      <slot name="pre" />
-    ) : (
-      <div class="bd-clipboard">
-        <button type="button" class="btn-clipboard">
-          <svg class="bi" role="img" aria-label="Copy">
-            <use xlink:href="#clipboard" />
-          </svg>
-        </button>
-      </div>
-    )
+    nestedInExample
+      ? (<></>)
+      : Astro.slots.has('pre')
+        ? (
+          <slot name="pre" />
+        )
+        : (
+          <div class="bd-clipboard">
+            <button type="button" class="btn-clipboard">
+              <svg class="bi" role="img" aria-label="Copy">
+                <use xlink:href="#clipboard" />
+              </svg>
+            </button>
+          </div>
+        )
   }
   <div class="highlight">
     {
index a09fffeb31fbb2649bab6fdeec03760d58e5e73c..044e1af4d408ed0b404c32cf637717ca0d4350ec 100644 (file)
@@ -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
             </div>
           </div>
         )}
-        <div class="highlight">
-          <Prism code={simplifiedMarkup} lang={lang} />
-        </div>
+        <Code code={simplifiedMarkup} lang={lang} nestedInExample={true} />
       </>
     )
   }