toolkit for mdBook [mirror of my GitHub repo] docs.tonywu.dev/mdbookkit/
permalinks rust-analyzer mdbook
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[link-forever] fix: images in links

+544 -255
+3
.prettierignore
··· 1 1 **/*.snap 2 2 **/*.snap.new 3 + 4 + docs/app/dist.css 5 + docs/src/app/**/*
+5 -1
README.md
··· 1 + ![mdbookkit hero image](docs/src/media/banner.webp) 2 + 1 3 # mdbookkit 2 4 3 - ![mdbookkit hero image](docs/src/media/banner.webp) 5 + [![crates.io](https://img.shields.io/crates/v/mdbookkit?style=flat-square)](https://crates.io/crates/mdbookkit) 6 + [![documentation](https://img.shields.io/docsrs/mdbookkit?style=flat-square&label=docs.rs)](https://docs.rs/mdbookkit) 7 + [![MIT/Apache-2.0 licensed](https://img.shields.io/crates/l/mdbookkit?style=flat-square)](/LICENSE-APACHE.md) 4 8 5 9 ## [Read the book](https://tonywu6.github.io/mdbookkit)
+3 -7
crates/mdbookkit/README.md
··· 4 4 5 5 Quality-of-life plugins for your [mdBook] project. 6 6 7 - Right now, there are two mdBook [preprocessors], both for generating **correct and 8 - versioned** external links from **easy-to-write** markup. 9 - 10 7 - [**`mdbook-rustdoc-link`**](https://tonywu6.github.io/mdbookkit/rustdoc-link) 11 8 12 9 _rustdoc_-style linking for Rust APIs: write types and function names, get links to ··· 16 13 17 14 _Permalinks_ for your source tree: write relative paths, get links to GitHub. 18 15 19 - > [!TIP] 20 - > 21 - > Preprocessors are standalone programs that mdBook invokes to transform your Markdown 22 - > sources before rendering them. 16 + [![crates.io](https://img.shields.io/crates/v/mdbookkit?style=flat-square)](https://crates.io/crates/mdbookkit) 17 + [![documentation](https://img.shields.io/docsrs/mdbookkit?style=flat-square&label=docs.rs)](https://docs.rs/mdbookkit) 18 + [![MIT/Apache-2.0 licensed](https://img.shields.io/crates/l/mdbookkit?style=flat-square)](/LICENSE-APACHE.md) 23 19 24 20 ## Installation 25 21
+16 -5
crates/mdbookkit/src/markdown.rs
··· 44 44 return Some(Ok(Cow::Borrowed(&self.source[start..]))); 45 45 }; 46 46 47 + if start > span.start { 48 + panic!("span {span:?} is backwards from already yielded span ending at {start}") 49 + } 50 + 47 51 let patch = match String::new().pipe(|mut out| cmark(events, &mut out).and(Ok(out))) { 48 52 Err(error) => return Some(Err(error)), 49 53 Ok(patch) => patch, ··· 59 63 impl<'a, S> PatchStream<'a, S> { 60 64 /// Create a new patch stream. 61 65 /// 62 - /// `stream` should be an [`Iterator`] yielding (`E`, [`Range<usize>`]), where `E` is an 63 - /// [`Iterator`] yielding [`Event`]s. 66 + /// `stream` should be an [`Iterator`] yielding tuples of (`events`, `range`): 67 + /// 68 + /// - `events` is an [`Iterator`] yielding [`Event`]s which is the replacement 69 + /// Markdown to be rendered into `source` using [`pulldown_cmark_to_cmark`]. 70 + /// 71 + /// - `range` is a [`Range<usize>`] representing the byte span in `source` that 72 + /// should be patched. 64 73 /// 65 - /// [`Range<usize>`] is the byte span in `source` that should be patched. 74 + /// **The yielded ranges must not overlap or decrease**, that is, for `span1` and 75 + /// `span2`, where `span1` is yielded before `span2`, `span1.end <= span2.start`. 66 76 /// 67 - /// `E` is the replacement event stream to be rendered into `source` 68 - /// using [`pulldown_cmark_to_cmark`]. 77 + /// ## Panics 78 + /// 79 + /// Panic if ranges in `stream` are not monotonically increasing. 69 80 pub fn new(source: &'a str, stream: S) -> Self { 70 81 Self { 71 82 source,
docs/app/socials.pxd

This is a binary file and will not be displayed.

+1 -1
docs/book.toml
··· 56 56 command = "cargo bin mdbook-alerts" 57 57 58 58 [preprocessor.app] 59 - command = "deno run -A app/build/preprocessor.ts" 59 + command = "deno run --allow-all app/build/preprocessor.ts" 60 60 61 61 [_metadata] 62 62 base-url = "https://tonywu6.github.io/mdbookkit/"
docs/src/media/banner.webp

This is a binary file and will not be displayed.

+10 -2
utils/mdbook-socials/src/main.rs
··· 1 - //! Postprocess mdBook HTML output to add OpenGraph metadata, for social images, etc. 1 + //! Postprocess mdBook HTML output. 2 + //! 3 + //! Currently does the following: 4 + //! 5 + //! - Add OpenGraph metadata and link to images for social. 6 + //! - Add explicit widths and heights to images: <https://web.dev/articles/optimize-cls#images-without-dimensions> 2 7 //! 3 8 //! mdBook doesn't support frontmatters yet, so this cannot be a preprocessor. 4 9 ··· 165 170 element!(r#"img[src]"#, |elem| { 166 171 let src = elem.get_attribute("src").unwrap(); 167 172 let src = url.join(&src)?; 168 - let img = image::open(src.to_file_path().unwrap())?; 173 + let img = image::open(match src.to_file_path() { 174 + Ok(path) => path, 175 + Err(()) => return Ok(()), 176 + })?; 169 177 elem.set_attribute("width", &img.width().to_string())?; 170 178 elem.set_attribute("height", &img.height().to_string())?; 171 179 Ok(())