deploy: 75014632413b319cb87db5b3e54bba2d6a21ac05

This commit is contained in:
github-actions[bot] 2020-05-01 06:11:26 +00:00
parent 3fdd5c7e4b
commit 41c7e7265c
6 changed files with 34 additions and 22 deletions

37
book.js
View File

@ -143,6 +143,11 @@ function playpen_text(playpen) {
languages: [], // Languages used for auto-detection languages: [], // Languages used for auto-detection
}); });
let code_nodes = Array
.from(document.querySelectorAll('code'))
// Don't highlight `inline code` blocks in headers.
.filter(function (node) {return !node.parentElement.classList.contains("header"); });
if (window.ace) { if (window.ace) {
// language-rust class needs to be removed for editable // language-rust class needs to be removed for editable
// blocks or highlightjs will capture events // blocks or highlightjs will capture events
@ -154,16 +159,12 @@ function playpen_text(playpen) {
.from(document.querySelectorAll('code:not(.editable)')) .from(document.querySelectorAll('code:not(.editable)'))
.forEach(function (block) { hljs.highlightBlock(block); }); .forEach(function (block) { hljs.highlightBlock(block); });
} else { } else {
Array code_nodes.forEach(function (block) { hljs.highlightBlock(block); });
.from(document.querySelectorAll('code'))
.forEach(function (block) { hljs.highlightBlock(block); });
} }
// Adding the hljs class gives code blocks the color css // Adding the hljs class gives code blocks the color css
// even if highlighting doesn't apply // even if highlighting doesn't apply
Array code_nodes.forEach(function (block) { block.classList.add('hljs'); });
.from(document.querySelectorAll('code'))
.forEach(function (block) { block.classList.add('hljs'); });
Array.from(document.querySelectorAll("code.language-rust")).forEach(function (block) { Array.from(document.querySelectorAll("code.language-rust")).forEach(function (block) {
@ -284,7 +285,7 @@ function playpen_text(playpen) {
function showThemes() { function showThemes() {
themePopup.style.display = 'block'; themePopup.style.display = 'block';
themeToggleButton.setAttribute('aria-expanded', true); themeToggleButton.setAttribute('aria-expanded', true);
themePopup.querySelector("button#" + document.body.className).focus(); themePopup.querySelector("button#" + get_theme()).focus();
} }
function hideThemes() { function hideThemes() {
@ -293,6 +294,16 @@ function playpen_text(playpen) {
themeToggleButton.focus(); themeToggleButton.focus();
} }
function get_theme() {
var theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { }
if (theme === null || theme === undefined) {
return default_theme;
} else {
return theme;
}
}
function set_theme(theme, store = true) { function set_theme(theme, store = true) {
let ace_theme; let ace_theme;
@ -324,9 +335,7 @@ function playpen_text(playpen) {
}); });
} }
var previousTheme; var previousTheme = get_theme();
try { previousTheme = localStorage.getItem('mdbook-theme'); } catch (e) { }
if (previousTheme === null || previousTheme === undefined) { previousTheme = default_theme; }
if (store) { if (store) {
try { localStorage.setItem('mdbook-theme', theme); } catch (e) { } try { localStorage.setItem('mdbook-theme', theme); } catch (e) { }
@ -337,9 +346,7 @@ function playpen_text(playpen) {
} }
// Set theme // Set theme
var theme; var theme = get_theme();
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; }
set_theme(theme, false); set_theme(theme, false);
@ -408,7 +415,6 @@ function playpen_text(playpen) {
(function sidebar() { (function sidebar() {
var html = document.querySelector("html"); var html = document.querySelector("html");
var sidebar = document.getElementById("sidebar"); var sidebar = document.getElementById("sidebar");
var sidebarScrollBox = document.querySelector(".sidebar-scrollbox");
var sidebarLinks = document.querySelectorAll('#sidebar a'); var sidebarLinks = document.querySelectorAll('#sidebar a');
var sidebarToggleButton = document.getElementById("sidebar-toggle"); var sidebarToggleButton = document.getElementById("sidebar-toggle");
var sidebarResizeHandle = document.getElementById("sidebar-resize-handle"); var sidebarResizeHandle = document.getElementById("sidebar-resize-handle");
@ -507,7 +513,8 @@ function playpen_text(playpen) {
// Scroll sidebar to current active section // Scroll sidebar to current active section
var activeSection = document.getElementById("sidebar").querySelector(".active"); var activeSection = document.getElementById("sidebar").querySelector(".active");
if (activeSection) { if (activeSection) {
sidebarScrollBox.scrollTop = activeSection.offsetTop; // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
activeSection.scrollIntoView({ block: 'center' });
} }
})(); })();

View File

@ -80,8 +80,8 @@
</script> </script>
<nav id="sidebar" class="sidebar" aria-label="Table of contents"> <nav id="sidebar" class="sidebar" aria-label="Table of contents">
<div id="sidebar-scrollbox" class="sidebar-scrollbox"> <div class="sidebar-scrollbox">
<ol class="chapter"><li class="expanded "><a href="chapter_1.html" class="active"><strong aria-hidden="true">1.</strong> Chapter 1</a></li></ol> <ol class="chapter"><li class="chapter-item expanded "><a href="chapter_1.html" class="active"><strong aria-hidden="true">1.</strong> Chapter 1</a></li></ol>
</div> </div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div> <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
</nav> </nav>

View File

@ -423,7 +423,7 @@ ul#searchresults span.teaser em {
display: none; display: none;
} }
.chapter li.expanded { .chapter li.chapter-item {
line-height: 1.5em; line-height: 1.5em;
margin-top: 0.6em; margin-top: 0.6em;
} }

View File

@ -25,6 +25,11 @@ code {
font-size: 0.875em; /* please adjust the ace font size accordingly in editor.js */ font-size: 0.875em; /* please adjust the ace font size accordingly in editor.js */
} }
/* Don't change font size in headers. */
h1 code, h2 code, h3 code, h4 code, h5 code, h6 code {
font-size: unset;
}
.left { float: left; } .left { float: left; }
.right { float: right; } .right { float: right; }
.boring { opacity: 0.6; } .boring { opacity: 0.6; }

View File

@ -80,8 +80,8 @@
</script> </script>
<nav id="sidebar" class="sidebar" aria-label="Table of contents"> <nav id="sidebar" class="sidebar" aria-label="Table of contents">
<div id="sidebar-scrollbox" class="sidebar-scrollbox"> <div class="sidebar-scrollbox">
<ol class="chapter"><li class="expanded "><a href="chapter_1.html"><strong aria-hidden="true">1.</strong> Chapter 1</a></li></ol> <ol class="chapter"><li class="chapter-item expanded "><a href="chapter_1.html"><strong aria-hidden="true">1.</strong> Chapter 1</a></li></ol>
</div> </div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div> <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
</nav> </nav>

View File

@ -82,8 +82,8 @@
</script> </script>
<nav id="sidebar" class="sidebar" aria-label="Table of contents"> <nav id="sidebar" class="sidebar" aria-label="Table of contents">
<div id="sidebar-scrollbox" class="sidebar-scrollbox"> <div class="sidebar-scrollbox">
<ol class="chapter"><li class="expanded "><a href="chapter_1.html"><strong aria-hidden="true">1.</strong> Chapter 1</a></li></ol> <ol class="chapter"><li class="chapter-item expanded "><a href="chapter_1.html"><strong aria-hidden="true">1.</strong> Chapter 1</a></li></ol>
</div> </div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div> <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
</nav> </nav>