diff options
Diffstat (limited to 'vendor/mdbook/src')
-rw-r--r-- | vendor/mdbook/src/book/init.rs | 14 | ||||
-rw-r--r-- | vendor/mdbook/src/book/mod.rs | 37 | ||||
-rw-r--r-- | vendor/mdbook/src/renderer/html_handlebars/hbs_renderer.rs | 28 | ||||
-rw-r--r-- | vendor/mdbook/src/theme/css/chrome.css | 19 | ||||
-rw-r--r-- | vendor/mdbook/src/theme/index.hbs | 6 | ||||
-rw-r--r-- | vendor/mdbook/src/theme/mod.rs | 36 | ||||
-rw-r--r-- | vendor/mdbook/src/utils/fs.rs | 1 |
7 files changed, 119 insertions, 22 deletions
diff --git a/vendor/mdbook/src/book/init.rs b/vendor/mdbook/src/book/init.rs index dd3fa8b0d..ebcdd9349 100644 --- a/vendor/mdbook/src/book/init.rs +++ b/vendor/mdbook/src/book/init.rs @@ -6,6 +6,7 @@ use super::MDBook; use crate::config::Config; use crate::errors::*; use crate::theme; +use crate::utils::fs::write_file; use log::{debug, error, info, trace}; /// A helper for setting up a new book and its directory structure. @@ -158,6 +159,19 @@ impl BookBuilder { let mut highlight_js = File::create(themedir.join("highlight.js"))?; highlight_js.write_all(theme::HIGHLIGHT_JS)?; + write_file(&themedir.join("fonts"), "fonts.css", theme::fonts::CSS)?; + for (file_name, contents) in theme::fonts::LICENSES { + write_file(&themedir, file_name, contents)?; + } + for (file_name, contents) in theme::fonts::OPEN_SANS.iter() { + write_file(&themedir, file_name, contents)?; + } + write_file( + &themedir, + theme::fonts::SOURCE_CODE_PRO.0, + theme::fonts::SOURCE_CODE_PRO.1, + )?; + Ok(()) } diff --git a/vendor/mdbook/src/book/mod.rs b/vendor/mdbook/src/book/mod.rs index 75bbcc714..33fe93f7f 100644 --- a/vendor/mdbook/src/book/mod.rs +++ b/vendor/mdbook/src/book/mod.rs @@ -196,21 +196,26 @@ impl MDBook { Ok(()) } - /// Run the entire build process for a particular [`Renderer`]. - pub fn execute_build_process(&self, renderer: &dyn Renderer) -> Result<()> { - let mut preprocessed_book = self.book.clone(); + /// Run preprocessors and return the final book. + pub fn preprocess_book(&self, renderer: &dyn Renderer) -> Result<(Book, PreprocessorContext)> { let preprocess_ctx = PreprocessorContext::new( self.root.clone(), self.config.clone(), renderer.name().to_string(), ); - + let mut preprocessed_book = self.book.clone(); for preprocessor in &self.preprocessors { if preprocessor_should_run(&**preprocessor, renderer, &self.config) { debug!("Running the {} preprocessor.", preprocessor.name()); preprocessed_book = preprocessor.run(&preprocess_ctx, preprocessed_book)?; } } + Ok((preprocessed_book, preprocess_ctx)) + } + + /// Run the entire build process for a particular [`Renderer`]. + pub fn execute_build_process(&self, renderer: &dyn Renderer) -> Result<()> { + let (preprocessed_book, preprocess_ctx) = self.preprocess_book(renderer)?; let name = renderer.name(); let build_dir = self.build_dir_for(name); @@ -264,13 +269,25 @@ impl MDBook { let mut chapter_found = false; - // FIXME: Is "test" the proper renderer name to use here? - let preprocess_context = - PreprocessorContext::new(self.root.clone(), self.config.clone(), "test".to_string()); + struct TestRenderer; + impl Renderer for TestRenderer { + // FIXME: Is "test" the proper renderer name to use here? + fn name(&self) -> &str { + "test" + } - let book = LinkPreprocessor::new().run(&preprocess_context, self.book.clone())?; - // Index Preprocessor is disabled so that chapter paths continue to point to the - // actual markdown files. + fn render(&self, _: &RenderContext) -> Result<()> { + Ok(()) + } + } + + // Index Preprocessor is disabled so that chapter paths + // continue to point to the actual markdown files. + self.preprocessors = determine_preprocessors(&self.config)? + .into_iter() + .filter(|pre| pre.name() != IndexPreprocessor::NAME) + .collect(); + let (book, _) = self.preprocess_book(&TestRenderer)?; let mut failed = false; for item in book.iter() { diff --git a/vendor/mdbook/src/renderer/html_handlebars/hbs_renderer.rs b/vendor/mdbook/src/renderer/html_handlebars/hbs_renderer.rs index 1b648dac1..e170e2fcd 100644 --- a/vendor/mdbook/src/renderer/html_handlebars/hbs_renderer.rs +++ b/vendor/mdbook/src/renderer/html_handlebars/hbs_renderer.rs @@ -289,6 +289,31 @@ impl HtmlHandlebars { theme::fonts::SOURCE_CODE_PRO.1, )?; } + if let Some(fonts_css) = &theme.fonts_css { + if !fonts_css.is_empty() { + if html_config.copy_fonts { + warn!( + "output.html.copy_fonts is deprecated.\n\ + Set copy_fonts=false and ensure the fonts you want are in \ + the `theme/fonts/` directory." + ); + } + write_file(destination, "fonts/fonts.css", &fonts_css)?; + } + } + if !html_config.copy_fonts && theme.fonts_css.is_none() { + warn!( + "output.html.copy_fonts is deprecated.\n\ + This book appears to have copy_fonts=false without a fonts.css file.\n\ + Add an empty `theme/fonts/fonts.css` file to squelch this warning." + ); + } + for font_file in &theme.font_files { + let contents = fs::read(font_file)?; + let filename = font_file.file_name().unwrap(); + let filename = Path::new("fonts").join(filename); + write_file(destination, filename, &contents)?; + } let playground_config = &html_config.playground; @@ -656,7 +681,8 @@ fn make_data( data.insert("mathjax_support".to_owned(), json!(true)); } - if html_config.copy_fonts { + // This `matches!` checks for a non-empty file. + if html_config.copy_fonts || matches!(theme.fonts_css.as_deref(), Some([_, ..])) { data.insert("copy_fonts".to_owned(), json!(true)); } diff --git a/vendor/mdbook/src/theme/css/chrome.css b/vendor/mdbook/src/theme/css/chrome.css index 59eae11fd..29992f7b6 100644 --- a/vendor/mdbook/src/theme/css/chrome.css +++ b/vendor/mdbook/src/theme/css/chrome.css @@ -2,12 +2,6 @@ @import 'variables.css'; -::-webkit-scrollbar { - background: var(--bg); -} -::-webkit-scrollbar-thumb { - background: var(--scrollbar); -} html { scrollbar-color: var(--scrollbar) var(--bg); } @@ -18,6 +12,19 @@ a > .hljs { color: var(--links); } +/* + body-container is necessary because mobile browsers don't seem to like + overflow-x on the body tag when there is a <meta name="viewport"> tag. +*/ +#body-container { + /* + This is used when the sidebar pushes the body content off the side of + the screen on small screens. Without it, dragging on mobile Safari + will want to reposition the viewport in a weird way. + */ + overflow-x: clip; +} + /* Menu Bar */ #menu-bar, diff --git a/vendor/mdbook/src/theme/index.hbs b/vendor/mdbook/src/theme/index.hbs index 147eb9af2..6f3948c65 100644 --- a/vendor/mdbook/src/theme/index.hbs +++ b/vendor/mdbook/src/theme/index.hbs @@ -54,6 +54,7 @@ {{/if}} </head> <body> + <div id="body-container"> <!-- Provide site root to javascript --> <script> var path_to_root = "{{ path_to_root }}"; @@ -91,10 +92,12 @@ <!-- Hide / unhide sidebar before it is displayed --> <script> var html = document.querySelector('html'); - var sidebar = 'hidden'; + var sidebar = null; if (document.body.clientWidth >= 1080) { try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { } sidebar = sidebar || 'visible'; + } else { + sidebar = 'hidden'; } html.classList.remove('sidebar-visible'); html.classList.add("sidebar-" + sidebar); @@ -309,5 +312,6 @@ {{/if}} {{/if}} + </div> </body> </html> diff --git a/vendor/mdbook/src/theme/mod.rs b/vendor/mdbook/src/theme/mod.rs index 7af5e2b70..6e6b509d1 100644 --- a/vendor/mdbook/src/theme/mod.rs +++ b/vendor/mdbook/src/theme/mod.rs @@ -9,7 +9,7 @@ pub mod searcher; use std::fs::File; use std::io::Read; -use std::path::Path; +use std::path::{Path, PathBuf}; use crate::errors::*; use log::warn; @@ -54,6 +54,8 @@ pub struct Theme { pub general_css: Vec<u8>, pub print_css: Vec<u8>, pub variables_css: Vec<u8>, + pub fonts_css: Option<Vec<u8>>, + pub font_files: Vec<PathBuf>, pub favicon_png: Option<Vec<u8>>, pub favicon_svg: Option<Vec<u8>>, pub js: Vec<u8>, @@ -104,7 +106,7 @@ impl Theme { ), ]; - let load_with_warn = |filename: &Path, dest| { + let load_with_warn = |filename: &Path, dest: &mut Vec<u8>| { if !filename.exists() { // Don't warn if the file doesn't exist. return false; @@ -121,6 +123,29 @@ impl Theme { load_with_warn(&filename, dest); } + let fonts_dir = theme_dir.join("fonts"); + if fonts_dir.exists() { + let mut fonts_css = Vec::new(); + if load_with_warn(&fonts_dir.join("fonts.css"), &mut fonts_css) { + theme.fonts_css.replace(fonts_css); + } + if let Ok(entries) = fonts_dir.read_dir() { + theme.font_files = entries + .filter_map(|entry| { + let entry = entry.ok()?; + if entry.file_name() == "fonts.css" { + None + } else if entry.file_type().ok()?.is_dir() { + log::info!("skipping font directory {:?}", entry.path()); + None + } else { + Some(entry.path()) + } + }) + .collect(); + } + } + // If the user overrides one favicon, but not the other, do not // copy the default for the other. let favicon_png = &mut theme.favicon_png.as_mut().unwrap(); @@ -153,6 +178,8 @@ impl Default for Theme { general_css: GENERAL_CSS.to_owned(), print_css: PRINT_CSS.to_owned(), variables_css: VARIABLES_CSS.to_owned(), + fonts_css: None, + font_files: Vec::new(), favicon_png: Some(FAVICON_PNG.to_owned()), favicon_svg: Some(FAVICON_SVG.to_owned()), js: JS.to_owned(), @@ -209,10 +236,10 @@ mod tests { "favicon.png", "favicon.svg", "css/chrome.css", - "css/fonts.css", "css/general.css", "css/print.css", "css/variables.css", + "fonts/fonts.css", "book.js", "highlight.js", "tomorrow-night.css", @@ -223,6 +250,7 @@ mod tests { let temp = TempFileBuilder::new().prefix("mdbook-").tempdir().unwrap(); fs::create_dir(temp.path().join("css")).unwrap(); + fs::create_dir(temp.path().join("fonts")).unwrap(); // "touch" all of the special files so we have empty copies for file in &files { @@ -240,6 +268,8 @@ mod tests { general_css: Vec::new(), print_css: Vec::new(), variables_css: Vec::new(), + fonts_css: Some(Vec::new()), + font_files: Vec::new(), favicon_png: Some(Vec::new()), favicon_svg: Some(Vec::new()), js: Vec::new(), diff --git a/vendor/mdbook/src/utils/fs.rs b/vendor/mdbook/src/utils/fs.rs index 0d6f38374..67f7062db 100644 --- a/vendor/mdbook/src/utils/fs.rs +++ b/vendor/mdbook/src/utils/fs.rs @@ -38,7 +38,6 @@ pub fn write_file<P: AsRef<Path>>(build_dir: &Path, filename: P, content: &[u8]) /// Consider [submitting a new issue](https://github.com/rust-lang/mdBook/issues) /// or a [pull-request](https://github.com/rust-lang/mdBook/pulls) to improve it. pub fn path_to_root<P: Into<PathBuf>>(path: P) -> String { - debug!("path_to_root"); // Remove filename and add "../" for every directory path.into() |