@@ -33,15 +33,20 @@ interface Props {
3333 * This takes precedence over the `code` prop.
3434 */
3535 filePath? : string
36+ /**
37+ * Defines if the `<Code>` component is nested inside an `<Example>` component or not.
38+ * @default false
39+ */
40+ nestedInExample? : boolean
3641}
3742
38- const { class : className, code, containerClass, fileMatch, filePath, lang } = Astro .props
43+ const { class : className, code, containerClass, fileMatch, filePath, lang, nestedInExample = false } = Astro .props
3944
4045let codeToDisplay = filePath
4146 ? fs .readFileSync (path .join (process .cwd (), filePath ), ' utf8' )
4247 : Array .isArray (code )
43- ? code .join (' \n ' )
44- : code
48+ ? code .join (' \n ' )
49+ : code
4550
4651if (filePath && fileMatch && codeToDisplay ) {
4752 const match = codeToDisplay .match (new RegExp (fileMatch ))
@@ -130,19 +135,23 @@ if (filePath && fileMatch && codeToDisplay) {
130135 })
131136</script >
132137
133- <div class:list ={ [' bd-code-snippet' , containerClass ]} >
138+ <div class:list ={ [{ ' bd-code-snippet' : ! nestedInExample } , containerClass ]} >
134139 {
135- Astro .slots .has (' pre' ) ? (
136- <slot name = " pre" />
137- ) : (
138- <div class = " bd-clipboard" >
139- <button type = " button" class = " btn-clipboard" >
140- <svg class = " bi" role = " img" aria-label = " Copy" >
141- <use xlink :href = " #clipboard" />
142- </svg >
143- </button >
144- </div >
145- )
140+ nestedInExample
141+ ? (<></>)
142+ : Astro .slots .has (' pre' )
143+ ? (
144+ <slot name = " pre" />
145+ )
146+ : (
147+ <div class = " bd-clipboard" >
148+ <button type = " button" class = " btn-clipboard" >
149+ <svg class = " bi" role = " img" aria-label = " Copy" >
150+ <use xlink :href = " #clipboard" />
151+ </svg >
152+ </button >
153+ </div >
154+ )
146155 }
147156 <div class =" highlight" >
148157 {
0 commit comments