Introduction
mdBook Plugins is a collection of plugins for mdBook.
License
This project is available under the MIT license.
Rust For Web
The mdBook Plugins project is part of the Rust For Web.
Rust For Web creates and ports web UI libraries for Rust. All projects are free and open source.
Tabs
Plugin for rendering content in tabs.
Example
All examples are part of the book source code.
Basic
Tab content 1
Global
Other tab content 1
#![allow(unused)] fn main() { let a = 1 + 2; }
Nested Tabs
Level 1 - Item 1
Level 2 - Item 1.1
Installation
cargo install mdbook-tabs
Configuration
Add the preprocessor to book.toml
.
[preprocessor.tabs]
Add the additional CSS and JS files to the book with the following command.
mdbook-tabs install
Add the additional CSS and JS files to the HTML renderer in book.toml
.
[output.html]
additional-css = ["theme/tabs.css"]
additional-js = ["theme/tabs.js"]
Usage
Define tabs as follows:
{{#tabs }}
{{#tab name="Tab 1" }}
**Tab content 1**
{{#endtab }}
{{#tab name="Tab 2" }}
_Tab content 2_
{{#endtab }}
{{#tab name="Tab 3" }}
~~Tab content 3~~
{{#endtab }}
{{#endtabs }}
The tabs can share a global state by adding a global
string to the opening tag:
{{#tabs global="example" }}
{{#tab name="Tab 1" }}
Some content.
{{#endtab }}
{{#endtabs }}
Trunk
Plugin which bundles packages using Trunk and includes them as iframes.
Example
All examples are part of the book source code.
Installation
cargo install mdbook-trunk
Configuration
Add the preprocessor and renderer to book.toml
. Note that the HTML renderer is also required.
[preprocessor.trunk]
[output.html]
[output.trunk]
Add the additional CSS and JS files to the book with the following command.
mdbook-trunk install
Add the additional CSS and JS files to the HTML renderer in book.toml
.
[output.html]
additional-css = ["theme/trunk.css"]
additional-js = ["theme/trunk.js"]
Usage
Define a Trunk include as follows:
```toml,trunk
# Package to build, must be in the current workspace.
package = "book-example"
# Features to enable for the package.
features = ["button"]
```
The following options are available:
# Package to build, must be in the current workspace.
package = "book-example"
# Features to enable for the package.
features = ["button"]
# Sources files to render (optional).
# Relative to the package root.
files = ["src/button.rs"]
# Whether to show files by default (optional).
show_files = true
# URL query for the iframe URL (optional).
# The leading question mark is optional.
url_query = "?key=value"
# URL fragment for the iframe URL (optional).
# The leading hash is optional.
url_fragment = "#header"
# HTML attributes for the iframe (optional).
[attributes]
allow = "fullscreen"
# Replacements to apply on files (optional).
[[file_replacements]]
find = "Some sentence"
replace = "Another sentence"
Building
- Build the book using
mdbook build
. This will output multiple directories inbook/build
. - Combine the build outputs using
mdbook-trunk combine
. This will combine the output directories inbook/dist
. - Serve the
book/dist
directory.