From 631cd5845e8de329d0e227aaa707d7ea228b8f8f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:20:29 +0200 Subject: Merging upstream version 1.70.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/mdbook/src/book/init.rs | 14 ++++++++ vendor/mdbook/src/book/mod.rs | 37 ++++++++++++++++------ .../src/renderer/html_handlebars/hbs_renderer.rs | 28 +++++++++++++++- vendor/mdbook/src/theme/css/chrome.css | 19 +++++++---- vendor/mdbook/src/theme/index.hbs | 6 +++- vendor/mdbook/src/theme/mod.rs | 36 +++++++++++++++++++-- vendor/mdbook/src/utils/fs.rs | 1 - 7 files changed, 119 insertions(+), 22 deletions(-) (limited to 'vendor/mdbook/src') 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 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}} +