1- function formatCrateName ( crateTitleAndVersion ) {
2- const stringParts = crateTitleAndVersion . split ( " " , 2 ) ;
3- return stringParts [ 0 ] + ' = "' + stringParts [ 1 ] + '"' ;
4- }
5-
61( function ( ) {
72 const clipboard = document . getElementById ( "clipboard" ) ;
83 if ( clipboard ) {
@@ -14,23 +9,17 @@ function formatCrateName(crateTitleAndVersion) {
149 clipboard . innerHTML = resetClipboardIcon ;
1510 }
1611
17- function copyTextHandler ( ) {
18- const crateTitleAndVersion = document . getElementById ( "crate-title" ) ;
19- // On rustdoc pages, we use `textTransform: uppercase`, which copies as uppercase.
20- // To avoid that, reset the styles temporarily.
21- const oldTransform = crateTitleAndVersion . style . textTransform ;
22- crateTitleAndVersion . style . textTransform = "none" ;
23- const temporaryInput = document . createElement ( "input" ) ;
12+ async function copyTextHandler ( ) {
13+ const metadata = JSON . parse ( document . getElementById ( "crate-metadata" ) . innerText )
2414
15+ const temporaryInput = document . createElement ( "input" ) ;
2516 temporaryInput . type = "text" ;
26- temporaryInput . value = formatCrateName ( crateTitleAndVersion . innerText ) ;
17+ temporaryInput . value = ` ${ metadata . name } = " ${ metadata . version } "` ;
2718
2819 document . body . append ( temporaryInput ) ;
2920 temporaryInput . select ( ) ;
3021 document . execCommand ( "copy" ) ;
31-
3222 temporaryInput . remove ( ) ;
33- crateTitleAndVersion . style . textTransform = oldTransform ;
3423
3524 clipboard . textContent = "✓" ;
3625 if ( resetClipboardTimeout !== null ) {
0 commit comments