@@ -33,15 +33,20 @@ interface Props {
33
33
* This takes precedence over the `code` prop.
34
34
*/
35
35
filePath? : string
36
+ /**
37
+ * Defines if the `<Code>` component is nested inside an `<Example>` component or not.
38
+ * @default false
39
+ */
40
+ nestedInExample? : boolean
36
41
}
37
42
38
- const { class : className, code, containerClass, fileMatch, filePath, lang } = Astro .props
43
+ const { class : className, code, containerClass, fileMatch, filePath, lang, nestedInExample = false } = Astro .props
39
44
40
45
let codeToDisplay = filePath
41
46
? fs .readFileSync (path .join (process .cwd (), filePath ), ' utf8' )
42
47
: Array .isArray (code )
43
- ? code .join (' \n ' )
44
- : code
48
+ ? code .join (' \n ' )
49
+ : code
45
50
46
51
if (filePath && fileMatch && codeToDisplay ) {
47
52
const match = codeToDisplay .match (new RegExp (fileMatch ))
@@ -130,19 +135,23 @@ if (filePath && fileMatch && codeToDisplay) {
130
135
})
131
136
</script >
132
137
133
- <div class:list ={ [' bd-code-snippet' , containerClass ]} >
138
+ <div class:list ={ [{ ' bd-code-snippet' : ! nestedInExample } , containerClass ]} >
134
139
{
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
+ )
146
155
}
147
156
<div class =" highlight" >
148
157
{
0 commit comments