File tree Expand file tree Collapse file tree
resources/views/documents/articles Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -497,14 +497,23 @@ function initLightbox() {
497497
498498 function addCopyButtons () {
499499 document .querySelectorAll (' pre' ).forEach (function (pre ) {
500- var codeBlock = pre .querySelector (' code' );
501500 var button = document .createElement (' button' );
502501 button .className = ' copy-btn' ;
503502 button .textContent = ' 复制' ;
504503
505504 button .addEventListener (' click' , function () {
505+ var codeLines = pre .querySelectorAll (' ol.linenums li' );
506506 var textArea = document .createElement (' textarea' );
507- textArea .value = codeBlock .textContent ;
507+ var codeText = ' ' ;
508+
509+ codeLines .forEach (function (line ) {
510+ var codeElement = line .querySelector (' code' );
511+ if (codeElement) {
512+ codeText += codeElement .innerText + ' \n ' ;
513+ }
514+ });
515+
516+ textArea .value = codeText .trim ();
508517 document .body .appendChild (textArea);
509518 textArea .select ();
510519 try {
@@ -526,7 +535,7 @@ function addCopyButtons() {
526535 pre .appendChild (button);
527536 });
528537 }
529-
538+
530539 function getCurrentArticleIndex () {
531540 var currentArticleId = {{ $article -> id } } ;
532541 var articles = @json ($articles );
You can’t perform that action at this time.
0 commit comments