This commit is contained in:
McShelby 2023-06-15 17:38:49 +00:00
parent dbfca7e19d
commit 3524f75bca
382 changed files with 12004 additions and 9258 deletions

View file

@ -503,11 +503,20 @@ function initCodeClipboard(){
var code = codeElements[i];
var text = code.textContent;
var inPre = code.parentNode.tagName.toLowerCase() == 'pre';
var isLineCell = code.querySelector( '.lnt' ); // avoid copy-to-clipboard for highlight shortcode in table lineno mode
if( inPre || text.length > 5 ){
if( !isLineCell && ( inPre || text.length > 5 ) ){
var clip = new ClipboardJS( '.copy-to-clipboard-button', {
text: function( trigger ){
var text = trigger.previousElementSibling && trigger.previousElementSibling.matches( 'code' ) && trigger.previousElementSibling.textContent;
if( !( trigger.previousElementSibling && trigger.previousElementSibling.matches( 'code' ) ) ){
return '';
}
// if highlight shortcode used in inline lineno mode, remove lineno nodes before generating text
var code = trigger.previousElementSibling.cloneNode( true );
Array.from( code.querySelectorAll( '.ln' ) ).forEach( function( lineno ){
lineno.remove();
});
var text = code.textContent;
// remove a trailing line break, this may most likely
// come from the browser / Hugo transformation
text = text.replace( /\n$/, '' );