A preprocessor for mdbook to add Material Design admonishments.

Overview

mdbook-admonish

Latest version docs.rs

A preprocessor for mdbook to add Material Design admonishments, based on the mkdocs-material implementation.

It turns this:

```admonish info
A beautifully styled message.
```

into this:

Simple Message

Examples

Read the documentation here, to see the actual examples in action. You can see the source in the ./book subdirectory.

Other projects using mdbook-admonish:

Usage

Use any fenced code-block as you normally would, but annotate it with admonish <admonition type>:

```admonish example
My example is the best!
```

Best Example

See the reference page for a list of supported admonitions. You'll find:

  • info
  • warning
  • danger
  • example

and quite a few more!

You can also leave out the admonition type altogether, in which case it will default to note:

```admonish
A plain note.
```

Plain Note

Additional Options

See the mdbook-admonish book for additional options, such as:

  • Custom titles
  • Custom styling
  • Collapsible blocks

Installation

Install the tool:

cargo install mdbook-admonish

Then let mdbook-admonish add the required files and configuration:

# Note: this may need to be rerun for new minor versions of mdbook-admonish
# see the 'Semantic Versioning' section below for details.
mdbook-admonish install path/to/your/book

# optionally, specify a directory where CSS files live, relative to the book root
mdbook-admonish install --css-dir ./assets/css .

This will add the following configuration to your book.toml:

[preprocessor.admonish]
command = "mdbook-admonish"

[output.html]
additional-css = ["./mdbook-admonish.css"]

and copy the file mdbook-admonish.css into your book's directory.

Then, build your book as usual:

mdbook path/to/book

Updates

Please note, when updating your version of mdbook-admonish, updated styles will not be applied unless you rerun mdbook-admonish install to update the additional CSS files in your book.

mdbook will fail the build if you require newer assets than you have installed:

2022-04-26 12:27:52 [INFO] (mdbook::book): Book building has started
ERROR:
  Incompatible assets installed: required mdbook-admonish assets version '^2.0.0', but found '1.0.0'.
  Please run `mdbook-admonish install` to update installed assets.
2022-04-26 12:27:52 [ERROR] (mdbook::utils): Error: The "admonish" preprocessor exited unsuccessfully with exit status: 1 status

If you want to update across minor versions without breakage, you should always run mdbook-admonish install.

Alternatively, pin to a specific version for a reproducible installation:

cargo install mdbook-admonish --vers "1.5.0" --locked

Bail on error

By default, if an adomnition is incorrectly configured, an error will be shown in the book.

You can force it to break the build instead, with the following configuration:

[preprocessor.admonish]
on_failure = "bail"

This may be useful for non-interative workflows.

Semantic Versioning

Guarantees provided are as follows:

  • Major versions: Contain breaking changes to the user facing markdown API, or the public API of the crate itself.
  • Minor versions: Feature release. May contain changes to generated CSS/HTML requiring mdbook-admonish install to be rerun.
  • Patch versions: Bug fixes only.

Development

Project design

  • Compiled CSS styles are built and committed from SCSS sources. See the compile_assets folder for details.
  • mdbook-admonish install is responsible for delivering additional assets and configuration to a client book.
  • mdbook-admonish is responsible for preprocessing book data, adding HTML that references compiled classnames.

Scripts to get started

  • ./scripts/install installs other toolchains required for development
  • ./scripts/check runs a full CI check
  • ./scripts/rebuild-book rebuilds the reference book under ./book. This is useful for integration testing locally.

Making breaking changes in CSS

To make a breaking change in CSS, you should:

  • Update the assets version in ./src/bin/assets/VERSION
  • Update the required assets version specifier in ./src/REQUIRED_ASSETS_VERSION

You must make the next mdbook-admonish crate version at least a minor version bump.

Releasing

Github workflows are setup such that pushing a vX.Y.Z tag will trigger a release to be cut.

Once the release is created, copy and paste the relevant section of CHANGELOG.md manually to update the description.

Thanks

This utility is heavily drawn from and inspired by other projects, namely:

The licences for these projects are included in the licences folder.

Comments
  • Add collapsible admonition blocks

    Add collapsible admonition blocks

    The mkdocs-material implementation allows for collapsible blocks, a pretty cool feature that allows for example to hide the answer to a question, which is invaluable for teaching material.

    Would it be possible to add it to mdbook-admonish?

    opened by gggto 13
  • Smart quotes doesn't work inside admonish blocks

    Smart quotes doesn't work inside admonish blocks

    1. Standard quotes are not turned into smart quotes inside the blocks even with the mdbook option turned on.

    2. Also, it would be nice to be able to style the title text... in other words, specify the title text also as MarkDown...

    3. Also, inlined HTML tags are not recognized:

    image

    1. Code blocks inside admonish blocks must be wrapped with ~~~ otherwise they conflict with the admonish closing tag

    2. Also, symbols inside fenced code blocks inside admonish blocks are not recognized:

    image

    opened by schungx 13
  • Add collapsible support

    Add collapsible support

    This Pull Request adds collapsible admonition support, as described in https://github.com/tommilligan/mdbook-admonish/issues/18.

    In its current state, this implementation has 2 shortcomings that I'm not sure how to overcome:

    1. The CSS could be modified to make the arrow look slightly better.
    2. The links to the admonition titles interfere with the open/close interaction. Clicking on the title doesn't open the box, which is counter-intuitive.
    opened by gggto 8
  • are there the tabs feature!

    are there the tabs feature!

    UPDATE

    the best feature for me in mkdocs-material is the way that uses the tabs to groups codes

    • is it supported by mdbook-admonish ?
    • if not, is there any way to use this feature?

    image

    opened by ayoubelmhamdi 6
  • [VISUAL BUG] - Header Bar Overflow

    [VISUAL BUG] - Header Bar Overflow

    Hi 👋, just wanted to say that I really like this library and thank you for making it!

    Issue

    However, I have noticed one thing though with the Header Bar in the given code blocks, they seem to overflow and not line up.

    Example

    	```admonish <admonition type>
    	[insert text]
    	```
    

    Results in:

    image image image

    It's like one or two pixels off so not entirely noticeable but definitely visible. I was wondering if this was an issue with the library or something potentially on the client-side? I've not changed any CSS within the generated CSS file.

    Diagnostic Info

    Operating System: Windows 11 Rust: v1.58.1 mdbook: v0.4.18 mdbook-admonish: 1.5.0

    opened by sgoudham 5
  • mdbook without installation possible?

    mdbook without installation possible?

    Hello Tom Milligan @tommilligan,

    thank you very much for your great work.

    Is there any way to use the exe file without mdbook-admonish install? I can`t / am not allowed to install anything on my computer.

    Thanks for your time and sorry for asking my question here, I didn`t find any forum or similar unfortunately.

    Many greetings rufus42

    opened by rufus42 4
  • feat: clickable anchor links, enforce asset updates

    feat: clickable anchor links, enforce asset updates

    Following discussion here: https://github.com/tommilligan/mdbook-admonish/pull/16#issuecomment-1109179755

    This PR:

    • adds clickable anchor links from admonition titles
    • adds a mechanism for forcing the user to upgrade their installed CSS files, to allow rollout of breaking changes
      • adds notes to README, that breaking CSS changes may be rolled out on minor version bumps
    opened by tommilligan 4
  • feat: add unique ids to generated html

    feat: add unique ids to generated html

    Closes #15

    I investigated whether there was an easy 'click to link to this admonition', but it's not clear to me what the UX of this should be, so that's open if anyone wants to work on it.

    opened by tommilligan 4
  • Feature Request: Provide prebuilt binaries for mdbook-admonish

    Feature Request: Provide prebuilt binaries for mdbook-admonish

    Many other mdbook preprocessors provide prebuilt binaries. This helps to enable the use of preprocessors in automation scenarios.

    For example I'm interested in using mdbook-admonish with the actions-mdbook github action. It currently requires prebuilt binaries, more details here: https://github.com/peaceiris/actions-mdbook/issues/426#issuecomment-1102752476

    Would you be willing to provide prebuilt binaries for mdbook-admonish?

    It looks like you could probably just modify the existing actions workflow that mdboom-mermaid uses: https://github.com/badboy/mdbook-mermaid/blob/main/.github/workflows/deploy.yml

    opened by bgianfo 4
  • The way to install it isn't specified.

    The way to install it isn't specified.

    Hi, I found it hard to install it (This is my first mdbook), maybe there should be a section talking about that?

    cargo install mdbook-admonish
    

    Then

    mdbook-admonish install
    

    Isn't something that a new user would know. I needed to check the source code of this repo to figure it out

    opened by blyxyas 3
  • `cargo install --locked mdbook-admonish` fails

    `cargo install --locked mdbook-admonish` fails

    I'm not sure how it could fail given that it used to succeed — I thought the role of --locked was to prevent this. But it generates this for me on a 1.64 compiler:

    error[E0597]: `local_ctx` does not live long enough
       --> /Users/maximilian/.cargo/registry/src/github.com-1ecc6299db9ec823/mdbook-0.4.18/src/renderer/html_handlebars/helpers/navigation.rs:154:25
        |
    154 |             t.render(r, &local_ctx, &mut local_rc, out)
        |                         ^^^^^^^^^^ borrowed value does not live long enough
    155 |         })?;
        |         -
        |         |
        |         `local_ctx` dropped here while still borrowed
        |         borrow might be used here, when `local_rc` is dropped and runs the destructor for type `handlebars::RenderContext<'_, '_>`
        |
        = note: values in a scope are dropped in the opposite order they are defined
    
    For more information about this error, try `rustc --explain E0597`.
    error: could not compile `mdbook` due to previous error
    warning: build failed, waiting for other jobs to finish...
        Building [=======================> ] 240/243: toml_edit
    error: failed to compile `mdbook-admonish v1.7.0`, intermediate artifacts can be found at `/var/folders/q2/jxfwc8mn3gvf0cs0mqk83thm0000gn/T/cargo-installm1zcJW`
    

    (There's a warning about using a yanked dependency, but again, I thought it could still use it)

    Running cargo install --path . --locked on main works — would it be possible if we could release a new version? And FYI the original command works without --locked.

    opened by max-sixty 3
Releases(v1.8.0)
Owner
Tom Milligan
Backend, systems and CI engineer. Working to automate all the things.
Tom Milligan
A GitHub Action to automatically build and deploy your mdbook project.

?? deploy-mdbook The deploy-mdbook action allows you to easily build and deploy your mdBook project to GitHub Pages. See action.yml for configuration

null 27 Oct 24, 2022
unFlow is a Design as Code implementation, a DSL for UX & backend modeling. DSL to Sketch file, Sketch to DSL, DSL to code.

unflow 是一个低代码、无代码设计语言。unFlow is a Design as Code implementation, a DSL for UX & backend modeling. DSL to Sketch file, Sketch to DSL, DSL to code.

Inherd OS Team (硬核开源小组) 70 Nov 27, 2022
Add toast support in your dioxus project

Add toast support in your dioxus project

YuKun Liu 8 Dec 16, 2022
GitHub Actions for mdBook (rust-lang/mdBook) ⚡️ Setup mdBook quickly and build your site fast. Linux (Ubuntu), macOS, and Windows are supported.

GitHub Actions for mdBook rust-lang/mdBook Setup Action. We can run mdBook on a virtual machine of GitHub Actions by this mdBook action. Linux, macOS,

Shohei Ueda 231 Jan 2, 2023
A mdbook preprocessor that allows the re-usability of template files with dynamic arguments

mdbook-template A mdbook preprocessor that allows the re-usability of template files with dynamic arguments Table of Contents Author Notes Installatio

Hamothy 7 Dec 22, 2022
yew-material is a material-ui framework for yew

About yew-material is a material-ui framework for yew create-yew-material-app Create Yew Material App is a way to create a single page Yew application

jie.wang 79 Dec 26, 2022
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
Design token framework — adopt a unified design language across platforms, codebases, and teams

Palette Design tokens framework with atomic classes for React and Master CSS. Deliver a consistent visual identity across your apps with design tokens

Foretag 4 Aug 23, 2022
Jest preprocessor/transformer for Rust

rs-jest tl;dr -- see examples This is a jest transformer that loads Rust code so it can be interop with Javascript base project. Currently, the Rust c

Fahmi Akbar Wildana 13 May 19, 2022
Another cursed Garry's Mod module. This time, it adds the C preprocessor to Lua scripts

gm_cpreprocessor Another cursed Garry's Mod module. This time, it adds the C preprocessor to Lua scripts. It works by detouring RunStringEx and overri

William 6 Aug 14, 2022
A pug-inspired HTML preprocessor

UNDER CONSTRUCTION Right now there is no usable version of hsml available. I'm just working on it. HSML - Hyper Short Markup Language hsml is a hyper

Shinigami 5 May 24, 2023
A general purpose Lisp🛸 intended for use as Sage's preprocessor language

sage-lisp This crate implements a standalone Lisp implementation, intended for use in the Sage preprocessor. (do (defun fact (n) (if (<=

adam mcdaniel 3 Apr 10, 2024
mdBook is a utility to create modern online books from Markdown files.

Create book from markdown files. Like Gitbook but implemented in Rust

The Rust Programming Language 11.6k Jan 4, 2023
mdzk is a plain text Zettelkasten system that is based on the mdBook API.

mdzk A lovingly designed system and static publishing tool for your plain text Zettelkasten mdzk is a plain text Zettelkasten system that is based on

mdzk 176 Jan 4, 2023
A GitHub Action to automatically build and deploy your mdbook project.

?? deploy-mdbook The deploy-mdbook action allows you to easily build and deploy your mdBook project to GitHub Pages. See action.yml for configuration

null 27 Oct 24, 2022
A backend for mdBook written in Rust for generating PDF based on headless chrome and Chrome DevTools Protocol.

A backend for mdBook written in Rust for generating PDF based on headless chrome and Chrome DevTools Protocol.

Hollow Man 52 Jan 7, 2023
An mdBook single PDF generator using pure Rust and some Node.js

mdbook-compress An mdBook backend renderer to generate a single PDF file for a full book. There are other similar projects, but most rely on chrome in

nxe 44 Jan 20, 2023
Translation support for mdbook. The plugins here give you a structured way to maintain a translated book.

Gettext Translation Support for mdbook The plugins here makes it easy to translate documentation written in mdbook into multiple languages. Support fo

Google 19 Apr 5, 2023
An mdBook backend to output Typst markup, pdf, png, or svg

mdbook-typst mdbook-typst is a backend for mdBook. The backend converts the book to Typst markup and can output any format Typst can (currently pdf, p

Christian Legnitto 18 Dec 16, 2023
Rust Language Learning material

RustMaterial Rust Language Learning material Rust Rust is blazingly fast systems programming language that prevents segfaults and guarantees thread sa

Udhay Prakash Pethakamsetty 1 Jan 6, 2022