File tree Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -190,13 +190,31 @@ export function RawHighlightedCode({
190
190
return < div className = { className } dangerouslySetInnerHTML = { { __html : code } } /> ;
191
191
}
192
192
193
- function cleanCodeForCopy ( code :string ) {
193
+ function cleanCodeForCopy ( code : string ) {
194
194
return code
195
- . split ( '\n' )
196
- . filter ( line => ! line . includes ( '[!code highlight' ) )
197
- . join ( '\n' ) ;
195
+ . split ( "\n" )
196
+ . map ( line => {
197
+
198
+ line = line . replace ( / \s * \/ \/ \s * \[ ! c o d e .* ?\] / g, "" ) ;
199
+ line = line . replace ( / \s * < ! - - \s * \[ ! c o d e .* ?\] - - > / g, "" ) ;
200
+ line = line . replace ( / \s * # \s * \[ ! c o d e .* ?\] / g, "" ) ;
201
+
202
+
203
+ if ( / ^ [ + - ] / . test ( line . trim ( ) ) ) {
204
+ line = line . trim ( ) . slice ( 1 ) ;
205
+ }
206
+
207
+
208
+ if ( line . trim ( ) === "…" ) return "" ;
209
+
210
+ return line ;
211
+ } )
212
+ . filter ( line => line . trim ( ) !== "" )
213
+ . join ( "\n" )
214
+ . trim ( ) ;
198
215
}
199
216
217
+
200
218
function CodeExampleFilename ( { filename, code } : { filename : string ; code ?: string } ) {
201
219
return (
202
220
< div className = "flex justify-between px-3 pt-0.5 pb-1.5 text-xs/5 text-gray-400 dark:text-white/50" >
You can’t perform that action at this time.
0 commit comments