tabs: fix false codify detection if only contained in subtabs #550

This commit is contained in:
Sören Weber 2023-06-08 16:45:30 +02:00
parent efce383939
commit 5a2ffac7fc
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
2 changed files with 11 additions and 11 deletions

View file

@ -1952,7 +1952,7 @@ html[dir="rtl"] #sidebar ul.collapsible-menu > li > label > i.fa-chevron-right {
} }
/* remove margin if only a single code block is contained in the tab (FF without :has using .codify style) */ /* remove margin if only a single code block is contained in the tab (FF without :has using .codify style) */
#body .tab-content.tab-panel-style.codify > .tab-content-text{ #body .tab-content.codify > .tab-content-text{
padding: 0; padding: 0;
} }
#body .tab-content-text:has(> div.highlight:only-child){ #body .tab-content-text:has(> div.highlight:only-child){

View file

@ -67,22 +67,22 @@ function adjustContentWidth(){
function fixCodeTabs(){ function fixCodeTabs(){
/* if only a single code block is contained in the tab and no style was selected, treat it like style=code */ /* if only a single code block is contained in the tab and no style was selected, treat it like style=code */
var codeTabPanels = Array.from( document.querySelectorAll( '.tab-content.tab-panel-style' ) ).filter( function( tabPanel ){ var codeTabContents = Array.from( document.querySelectorAll( '.tab-content.tab-panel-style' ) ).filter( function( tabContent ){
return tabPanel.querySelector( '.tab-content-text > div.highlight:only-child, .tab-content-text > pre.pre-code:only-child'); return tabContent.querySelector( '*:scope > .tab-content-text > div.highlight:only-child, *:scope > .tab-content-text > pre.pre-code:only-child');
}); });
codeTabPanels.forEach( function( tabPanel ){ codeTabContents.forEach( function( tabContent ){
var p = tabPanel.parentNode.parentNode; var tabId = tabContent.dataset.tabItem;
var tabId = tabPanel.dataset.tabItem; var tabPanel = tabContent.parentNode.parentNode;
var tabButton = p.querySelector( '.tab-nav-button.tab-panel-style[data-tab-item="'+tabId+'"]' ); var tabButton = tabPanel.querySelector( '.tab-nav-button.tab-panel-style[data-tab-item="'+tabId+'"]' );
if( tabPanel.classList.contains( 'initial' ) ){ if( tabContent.classList.contains( 'initial' ) ){
tabButton.classList.remove( 'initial' ); tabButton.classList.remove( 'initial' );
tabButton.classList.add( 'code' ); tabButton.classList.add( 'code' );
tabPanel.classList.remove( 'initial' ); tabContent.classList.remove( 'initial' );
tabPanel.classList.add( 'code' ); tabContent.classList.add( 'code' );
} }
// mark code blocks for FF without :has() // mark code blocks for FF without :has()
tabPanel.classList.add( 'codify' ); tabContent.classList.add( 'codify' );
}); });
} }