diff --git a/theme/book.js b/theme/book.js index ec2f0679a2..a422ca6ba4 100644 --- a/theme/book.js +++ b/theme/book.js @@ -17,6 +17,33 @@ function playground_text(playground, hidden = true) { } } +(function openContentLinksInNewTabs() { + var content = document.querySelector("#content main"); + if (!content) { + return; + } + + Array.from(content.querySelectorAll("a[href]")).forEach(function (link) { + var href = link.getAttribute("href"); + + // Heading permalinks are page controls, not links to other content. + if (!href || link.classList.contains("header") || /^(?:javascript|data):/i.test(href)) { + return; + } + + link.setAttribute("target", "_blank"); + + var rel = (link.getAttribute("rel") || "").split(/\s+/).filter(Boolean); + if (rel.indexOf("noopener") === -1) { + rel.push("noopener"); + } + if (rel.indexOf("noreferrer") === -1) { + rel.push("noreferrer"); + } + link.setAttribute("rel", rel.join(" ")); + }); +})(); + (function codeSnippets() { function fetch_with_timeout(url, options, timeout = 6000) { return Promise.race([ diff --git a/theme/css/chrome.css b/theme/css/chrome.css index 403c6779a3..15c677663c 100644 --- a/theme/css/chrome.css +++ b/theme/css/chrome.css @@ -1456,21 +1456,25 @@ details[open] > summary::before { } details { + --details-content-padding: clamp(1.5rem, 4vw, 4rem); border-radius: 8px; background-color: var(--bg); border: 1px solid var(--table-border-color); - font-size: 18px; - font-weight: 100; } details p { - padding-right: 4rem; - padding-left: 4rem; + padding-right: var(--details-content-padding); + padding-left: var(--details-content-padding); +} + +details > pre { + margin-right: var(--details-content-padding); + margin-left: var(--details-content-padding); } details ul, details ol { - padding-right: 6rem; - padding-left: 6rem; + padding-right: calc(var(--details-content-padding) + 2rem); + padding-left: calc(var(--details-content-padding) + 2rem); padding-bottom: 2rem; margin-top: 0; } diff --git a/theme/pagetoc.css b/theme/pagetoc.css index dc6124023c..c33d8fe372 100644 --- a/theme/pagetoc.css +++ b/theme/pagetoc.css @@ -95,17 +95,22 @@ } .sidetoc-wrapper { position: fixed; + top: calc(var(--menu-bar-height) + 25px); + bottom: 25px; width: 250px; - height: calc(100vh - var(--menu-bar-height) - 50px * 2); - overflow: auto; + height: auto; + overflow: hidden; display: flex; flex-direction: column; gap:14px; background-color: transparent; } .pagetoc { - max-height: 48%; - overflow: auto; + flex: 1 1 auto; + min-height: 0; + max-height: none; + overflow-x: hidden; + overflow-y: auto; border-left: 1px solid color-mix(in srgb, var(--table-border-color) 70%, transparent); border-radius: 12px; background: transparent; @@ -113,8 +118,10 @@ padding: 4px 4px; } .sidesponsor { - max-height: 52%; - height: 52%; + flex: 0 1 auto; + max-height: min(420px, 52vh); + height: auto; + margin-top: auto; background-color: transparent; border: 1px solid color-mix(in srgb, var(--table-border-color) 70%, transparent); border-radius: 8px; @@ -192,8 +199,10 @@ font-weight: 800; } .sidesponsor-bsa { - max-height: 52%; - height: 52%; + flex: 0 1 auto; + max-height: min(420px, 52vh); + height: auto; + margin-top: auto; background-color: transparent; border: 1px solid color-mix(in srgb, var(--table-border-color) 70%, transparent); border-radius: 8px; @@ -781,8 +790,8 @@ .sidesponsor { width: 100% !important; min-height: min(360px, 52vh); - max-height: 52% !important; - height: 52% !important; + max-height: min(420px, 52vh) !important; + height: auto !important; grid-template-columns: minmax(0, 1fr); grid-template-areas: "kicker" @@ -911,8 +920,8 @@ } .sidesponsor-bsa { - max-height: 52%; - height: 52%; + max-height: min(420px, 52vh); + height: auto; } } diff --git a/theme/toc.js.hbs b/theme/toc.js.hbs index b6b5566e52..1e99281481 100644 --- a/theme/toc.js.hbs +++ b/theme/toc.js.hbs @@ -11,35 +11,24 @@ class MDBookSidebarScrollbox extends HTMLElement { // Modify TOC to support external links var toc = '{{#toc}}{{/toc}}'; // Handle both old mdbook (
) and new mdbook 0.5 () formats - // External links open in new tab with external link icon - toc = toc.replace(/<(div|span)>([^$<>]*)\$\$external:([^$<>]*)\$\$<\/(div|span)>/g, '$2 ↗') + // External links open in a new tab. CSS adds the single external-link icon. + toc = toc.replace(/<(div|span)>([^$<>]*)\$\$external:([^$<>]*)\$\$<\/(div|span)>/g, '$2') this.innerHTML = toc // Set the current, active page, and reveal it if it's hidden - let current_page = document.location.href.toString(); - if (current_page.endsWith("/")) { - current_page += "index.html"; - } + var currentPage = normalizeChapterUrl(document.location.href); var links = Array.prototype.slice.call(this.querySelectorAll("a")); var l = links.length; for (var i = 0; i < l; ++i) { var link = links[i]; var href = link.getAttribute("href"); - if (href && !href.startsWith("#") && !/^(?:[a-z+]+:)?\/\//.test(href)) { + var isChapterLink = href && !href.startsWith("#") && !link.classList.contains("chapter-fold-toggle") && !link.classList.contains("external-link"); + if (isChapterLink && !/^(?:[a-z+]+:)?\/\//.test(href)) { link.href = path_to_root + href; } // The "index" page is supposed to alias the first chapter in the book. - if (link.href === current_page || (i === 0 && path_to_root === "" && current_page.endsWith("/index.html"))) { + if (isChapterLink && (normalizeChapterUrl(link.href) === currentPage || (i === 0 && path_to_root === "" && currentPage.endsWith("/index.html")))) { link.classList.add("active"); - var parent = link.parentElement; - if (parent && parent.classList.contains("chapter-item")) { - parent.classList.add("expanded"); - } - while (parent) { - if (parent.tagName === "LI" && parent.classList.contains("chapter-item")) { - parent.classList.add("expanded"); - } - parent = parent.parentElement; - } + expandChapterPath(link); } } updateChapterNavigation(links); @@ -99,6 +88,14 @@ function normalizeChapterUrl(url) { } } +function expandChapterPath(link) { + var chapter = link.closest("li.chapter-item"); + while (chapter) { + chapter.classList.add("expanded"); + chapter = chapter.parentElement && chapter.parentElement.closest("li.chapter-item"); + } +} + function setChapterNavigationLink(selector, chapter) { var link = document.querySelector(selector); if (!link) {