diff --git a/templates/modern/src/markdown.scss b/templates/modern/src/markdown.scss index 23c801606f4..abe1ed4a057 100644 --- a/templates/modern/src/markdown.scss +++ b/templates/modern/src/markdown.scss @@ -111,3 +111,10 @@ pre { border-top-right-radius: 0; } } + +@media print { + div.tabGroup > section { + display: flex !important; + margin-bottom: 1rem; + } +} diff --git a/templates/modern/src/markdown.ts b/templates/modern/src/markdown.ts index c8d6c4dde32..4ab0db2a71a 100644 --- a/templates/modern/src/markdown.ts +++ b/templates/modern/src/markdown.ts @@ -451,10 +451,35 @@ function renderTabs() { } function updateTabStyle() { - document.querySelectorAll('div.tabGroup>ul').forEach(e => e.classList.add('nav', 'nav-tabs')) + document.querySelectorAll('div.tabGroup>ul').forEach(e => e.classList.add('nav', 'nav-tabs', 'd-print-none')) document.querySelectorAll('div.tabGroup>ul>li').forEach(e => e.classList.add('nav-item')) document.querySelectorAll('div.tabGroup>ul>li>a').forEach(e => e.classList.add('nav-link')) document.querySelectorAll('div.tabGroup>section').forEach(e => e.classList.add('card')) + // Create hidden tab nav that show up when printing + const parser = new DOMParser() + document.querySelectorAll('div.tabGroup').forEach(e => { + const navigation = e.querySelector('ul') + const sections = [] + const children = Array.from(e.children) + Array.from(children).forEach(c => { + if (c.tagName === 'SECTION') { + sections.push(c) + } + }) + for (let i = 0; i < sections.length; i++) { + const newNav = e.insertBefore(parser.parseFromString(navigation.outerHTML, 'text/html').body.firstElementChild, sections[i]) + newNav.classList.remove('d-print-none') + newNav.classList.add('d-none', 'd-print-flex') + for (let j = 0; j < newNav.children.length; j++) { + newNav.children[j].classList.remove('active') + newNav.children[j].removeAttribute('hidden') + newNav.children[j].firstElementChild.classList.remove('active') + if (j === i) { + newNav.children[j].firstElementChild.classList.add('active') + } + } + } + }) } function notifyContentUpdated() {