From d319d92d9871d6a84e374834feb121585764e6fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Thu, 15 Jun 2023 23:17:27 +0200 Subject: [PATCH] syntaxhighlight: fix behavior for noClasses=true #569 --- static/css/theme.css | 8 ++++---- static/js/theme.js | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/static/css/theme.css b/static/css/theme.css index 8735c1da55..3daea9b864 100644 --- a/static/css/theme.css +++ b/static/css/theme.css @@ -667,17 +667,17 @@ pre code { } /* increase code column to full width if highlight shortcode was used in table lineno mode */ -td.lntd:nth-child(2){ +div.highlight td:nth-child(2){ width: 100%; } /* remove border from lineno column if highlight shortcode was used in table lineno mode */ -td.lntd > pre.chroma:not(.pre-code) { +div.highlight td > pre:not(.pre-code) { border-bottom-right-radius: 0; border-right-width: 0; border-top-right-radius: 0; } -td.lntd:nth-child(2) pre { +div.highlight td:nth-child(2) pre { border-bottom-left-radius: 0; border-top-left-radius: 0; } @@ -1981,6 +1981,6 @@ html[dir="rtl"] #sidebar ul.collapsible-menu > li > label > i.fa-chevron-right { border-width: 0; } /* re-add border on code column if a single in tab and highlight shortcode was used in table lineno mode */ -#body .tab-content-text > div.highlight:only-child td.lntd:nth-child(2) pre { +#body .tab-content-text > div.highlight:only-child td:nth-child(2) pre { border-left-width: 1px; } diff --git a/static/js/theme.js b/static/js/theme.js index ed23396561..b771b90ea6 100644 --- a/static/js/theme.js +++ b/static/js/theme.js @@ -503,7 +503,10 @@ 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 + // avoid copy-to-clipboard for highlight shortcode in table lineno mode + var isLineCell = inPre && + code.parentNode.parentNode.tagName.toLowerCase() == 'td' && + code.parentNode.parentNode.parentNode.querySelector( 'td:nth-child(1) > pre > code' ) == code; if( !isLineCell && ( inPre || text.length > 5 ) ){ var clip = new ClipboardJS( '.copy-to-clipboard-button', { @@ -513,7 +516,7 @@ function initCodeClipboard(){ } // 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 ){ + Array.from( code.querySelectorAll( '*:scope > span > span:nth-child(1):not(:last-child)' ) ).forEach( function( lineno ){ lineno.remove(); }); var text = code.textContent;