Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions theme/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
16 changes: 10 additions & 6 deletions theme/css/chrome.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
33 changes: 21 additions & 12 deletions theme/pagetoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,33 @@
}
.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;
box-shadow: none;
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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -911,8 +920,8 @@
}

.sidesponsor-bsa {
max-height: 52%;
height: 52%;
max-height: min(420px, 52vh);
height: auto;
}
}

Expand Down
33 changes: 15 additions & 18 deletions theme/toc.js.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,24 @@ class MDBookSidebarScrollbox extends HTMLElement {
// Modify TOC to support external links
var toc = '{{#toc}}{{/toc}}';
// Handle both old mdbook (<div>) and new mdbook 0.5 (<span>) formats
// External links open in new tab with external link icon
toc = toc.replace(/<(div|span)>([^$<>]*)\$\$external:([^$<>]*)\$\$<\/(div|span)>/g, '<a class="external-link" href="$3" target="_blank" rel="noopener noreferrer">$2</a>')
// External links open in a new tab. CSS adds the single external-link icon.
toc = toc.replace(/<(div|span)>([^$<>]*)\$\$external:([^$<>]*)\$\$<\/(div|span)>/g, '<a class="external-link" href="$3" target="_blank" rel="noopener noreferrer">$2</a>')
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);
Expand Down Expand Up @@ -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) {
Expand Down