summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Milligan <tom.milligan@uipath.com>2023-12-30 21:20:35 +0100
committerGitHub <noreply@github.com>2023-12-30 21:20:35 +0100
commitc4a05dae9dbb472d03cdd0e316e984939f10b9d3 (patch)
treea8ee4d6e52149a975d4094421aaf5eb55d614126
parent26c344a1e648d1c17e4b8847087420b49784b907 (diff)
parent1bb14684c4be5e2930579868c19a57e85febf5c3 (diff)
Merge pull request #165 from tommilligan/99-custom-admonitions
feat: custom directives
-rw-r--r--.github/workflows/check.yml6
-rw-r--r--Cargo.lock18
-rw-r--r--Cargo.toml5
-rw-r--r--book/book.toml7
-rw-r--r--book/mdbook-admonish-custom.css20
-rw-r--r--book/money-bag.svg6
-rw-r--r--book/src/overview.md45
-rw-r--r--book/src/reference.md27
-rw-r--r--compile_assets/package.json4
-rw-r--r--compile_assets/scss/admonition.scss55
-rw-r--r--compile_assets/scss/lib.scss52
-rw-r--r--compile_assets/scss/mdbook-admonish-custom-expected.scss16
-rw-r--r--integration/book.toml9
-rw-r--r--integration/expected/book.toml9
-rw-r--r--integration/expected/chapter_1_main.html9
-rw-r--r--integration/expected/mdbook-admonish-custom.css20
-rw-r--r--integration/frog.svg29
-rw-r--r--integration/mdbook-admonish-custom.css20
-rwxr-xr-xintegration/scripts/check21
-rw-r--r--integration/src/chapter_1.md4
-rwxr-xr-xscripts/check13
-rw-r--r--src/bin/assets/VERSION2
-rw-r--r--src/bin/assets/mdbook-admonish.css35
-rw-r--r--src/bin/mdbook-admonish.rs71
-rw-r--r--src/book_config.rs30
-rw-r--r--src/custom.rs110
-rw-r--r--src/lib.rs1
-rw-r--r--src/markdown.rs13
-rw-r--r--src/parse.rs9
-rw-r--r--src/preprocessor.rs5
-rw-r--r--src/render.rs36
-rw-r--r--src/resolve.rs180
-rw-r--r--src/test_data/mdbook-admonish-custom-expected.css20
-rw-r--r--src/types.rs92
34 files changed, 857 insertions, 142 deletions
diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml
index abcd2ac..a757db3 100644
--- a/.github/workflows/check.yml
+++ b/.github/workflows/check.yml
@@ -96,6 +96,12 @@ jobs:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
steps:
+ # This is required, otherwise we get files with CRLF on Windows
+ # Which causes tests relying on data loaded from files to fail
+ - name: Set git to use LF everywhere
+ run: |
+ git config --global core.autocrlf false
+ git config --global core.eol lf
- name: Checkout sources
uses: actions/checkout@v4
- name: Cache build files
diff --git a/Cargo.lock b/Cargo.lock
index b2c8445..de3bc22 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -110,6 +110,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
+name = "arrayvec"
+version = "0.7.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
+
+[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -626,6 +632,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b"
[[package]]
+name = "hex_color"
+version = "3.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d37f101bf4c633f7ca2e4b5e136050314503dd198e78e325ea602c327c484ef0"
+dependencies = [
+ "arrayvec",
+ "rand",
+ "serde",
+]
+
+[[package]]
name = "html5ever"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -957,6 +974,7 @@ dependencies = [
"anyhow",
"clap",
"env_logger",
+ "hex_color",
"log",
"mdbook",
"once_cell",
diff --git a/Cargo.toml b/Cargo.toml
index cd0b371..6b2be5a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -30,8 +30,8 @@ anyhow = "1.0.75"
# Note: clap 4.4 increases MSRV to 1.70.0 (2023-06-01)
# To use MSRV supported dependencies, install using the lockfile with
# `cargo install mdbook-admonish --locked`
-clap = { version = "4.3", default_features = false, features = ["std", "derive"], optional = true }
-env_logger = { version = "0.10", default_features = false, optional = true }
+clap = { version = "4.3", default-features = false, features = ["std", "derive"], optional = true }
+env_logger = { version = "0.10", default-features = false, optional = true }
log = "0.4.20"
mdbook = "0.4.35"
once_cell = "1.18.0"
@@ -46,6 +46,7 @@ serde_json = "1.0.107"
toml_mdbook = { package = "toml", version = "0.5.11" }
toml = "0.8.1"
toml_edit = { version = "0.20.1", optional = true }
+hex_color = { version = "3.0.0", features = ["serde"] }
[dev-dependencies]
pretty_assertions = "1.4.0"
diff --git a/book/book.toml b/book/book.toml
index 77673ec..9a14078 100644
--- a/book/book.toml
+++ b/book/book.toml
@@ -11,6 +11,11 @@ title = "The mdbook-admonish book"
command = "mdbook-admonish"
assets_version = "3.0.1" # do not edit: managed by `mdbook-admonish install`
+[[preprocessor.admonish.custom]]
+directive = "expensive"
+icon = "./money-bag.svg"
+color = "#24ab38"
+
[preprocessor.toc]
command = "mdbook-toc"
renderer = ["html"]
@@ -18,4 +23,4 @@ renderer = ["html"]
[output]
[output.html]
-additional-css = ["./mdbook-admonish.css"]
+additional-css = ["./mdbook-admonish.css", "./mdbook-admonish-custom.css"]
diff --git a/book/mdbook-admonish-custom.css b/book/mdbook-admonish-custom.css
new file mode 100644
index 0000000..5b8bb11
--- /dev/null
+++ b/book/mdbook-admonish-custom.css
@@ -0,0 +1,20 @@
+:root {
+ --md-admonition-icon--admonish-expensive: url("data:image/svg+xml;charset=utf-8,<svg width='800px' height='800px' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --><!-- ref: https://www.svgrepo.com/svg/526038/money-bag --><!-- Used under CC Attribution License; Author: Solar Icons --><path fill-rule='evenodd' clip-rule='evenodd' d='M12.052 1.25H11.948C11.0495 1.24997 10.3003 1.24995 9.70552 1.32991C9.07773 1.41432 8.51093 1.59999 8.05546 2.05546C7.59999 2.51093 7.41432 3.07773 7.32991 3.70552C7.27259 4.13189 7.25637 5.15147 7.25179 6.02566C5.22954 6.09171 4.01536 6.32778 3.17157 7.17157C2 8.34315 2 10.2288 2 14C2 17.7712 2 19.6569 3.17157 20.8284C4.34314 22 6.22876 22 9.99998 22H14C17.7712 22 19.6569 22 20.8284 20.8284C22 19.6569 22 17.7712 22 14C22 10.2288 22 8.34315 20.8284 7.17157C19.9846 6.32778 18.7705 6.09171 16.7482 6.02566C16.7436 5.15147 16.7274 4.13189 16.6701 3.70552C16.5857 3.07773 16.4 2.51093 15.9445 2.05546C15.4891 1.59999 14.9223 1.41432 14.2945 1.32991C13.6997 1.24995 12.9505 1.24997 12.052 1.25ZM15.2479 6.00188C15.2434 5.15523 15.229 4.24407 15.1835 3.9054C15.1214 3.44393 15.0142 3.24644 14.8839 3.11612C14.7536 2.9858 14.5561 2.87858 14.0946 2.81654C13.6116 2.7516 12.964 2.75 12 2.75C11.036 2.75 10.3884 2.7516 9.90539 2.81654C9.44393 2.87858 9.24644 2.9858 9.11612 3.11612C8.9858 3.24644 8.87858 3.44393 8.81654 3.9054C8.771 4.24407 8.75661 5.15523 8.75208 6.00188C9.1435 6 9.55885 6 10 6H14C14.4412 6 14.8565 6 15.2479 6.00188ZM12 9.25C12.4142 9.25 12.75 9.58579 12.75 10V10.0102C13.8388 10.2845 14.75 11.143 14.75 12.3333C14.75 12.7475 14.4142 13.0833 14 13.0833C13.5858 13.0833 13.25 12.7475 13.25 12.3333C13.25 11.9493 12.8242 11.4167 12 11.4167C11.1758 11.4167 10.75 11.9493 10.75 12.3333C10.75 12.7174 11.1758 13.25 12 13.25C13.3849 13.25 14.75 14.2098 14.75 15.6667C14.75 16.857 13.8388 17.7155 12.75 17.9898V18C12.75 18.4142 12.4142 18.75 12 18.75C11.5858 18.75 11.25 18.4142 11.25 18V17.9898C10.1612 17.7155 9.25 16.857 9.25 15.6667C9.25 15.2525 9.58579 14.9167 10 14.9167C10.4142 14.9167 10.75 15.2525 10.75 15.6667C10.75 16.0507 11.1758 16.5833 12 16.5833C12.8242 16.5833 13.25 16.0507 13.25 15.6667C13.25 15.2826 12.8242 14.75 12 14.75C10.6151 14.75 9.25 13.7903 9.25 12.3333C9.25 11.143 10.1612 10.2845 11.25 10.0102V10C11.25 9.58579 11.5858 9.25 12 9.25Z' fill='%231C274C'/></svg>");
+}
+
+:is(.admonition):is(.admonish-expensive) {
+ border-color: #24ab38;
+}
+
+:is(.admonish-expensive) > :is(.admonition-title, summary.admonition-title) {
+ background-color: rgba(36, 171, 56, 0.1);
+}
+:is(.admonish-expensive) > :is(.admonition-title, summary.admonition-title)::before {
+ background-color: #24ab38;
+ mask-image: var(--md-admonition-icon--admonish-expensive);
+ -webkit-mask-image: var(--md-admonition-icon--admonish-expensive);
+ mask-repeat: no-repeat;
+ -webkit-mask-repeat: no-repeat;
+ mask-size: contain;
+ -webkit-mask-repeat: no-repeat;
+}
diff --git a/book/money-bag.svg b/book/money-bag.svg
new file mode 100644
index 0000000..b388862
--- /dev/null
+++ b/book/money-bag.svg
@@ -0,0 +1,6 @@
+<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
+<!-- ref: https://www.svgrepo.com/svg/526038/money-bag -->
+<!-- Used under CC Attribution License; Author: Solar Icons -->
+<path fill-rule="evenodd" clip-rule="evenodd" d="M12.052 1.25H11.948C11.0495 1.24997 10.3003 1.24995 9.70552 1.32991C9.07773 1.41432 8.51093 1.59999 8.05546 2.05546C7.59999 2.51093 7.41432 3.07773 7.32991 3.70552C7.27259 4.13189 7.25637 5.15147 7.25179 6.02566C5.22954 6.09171 4.01536 6.32778 3.17157 7.17157C2 8.34315 2 10.2288 2 14C2 17.7712 2 19.6569 3.17157 20.8284C4.34314 22 6.22876 22 9.99998 22H14C17.7712 22 19.6569 22 20.8284 20.8284C22 19.6569 22 17.7712 22 14C22 10.2288 22 8.34315 20.8284 7.17157C19.9846 6.32778 18.7705 6.09171 16.7482 6.02566C16.7436 5.15147 16.7274 4.13189 16.6701 3.70552C16.5857 3.07773 16.4 2.51093 15.9445 2.05546C15.4891 1.59999 14.9223 1.41432 14.2945 1.32991C13.6997 1.24995 12.9505 1.24997 12.052 1.25ZM15.2479 6.00188C15.2434 5.15523 15.229 4.24407 15.1835 3.9054C15.1214 3.44393 15.0142 3.24644 14.8839 3.11612C14.7536 2.9858 14.5561 2.87858 14.0946 2.81654C13.6116 2.7516 12.964 2.75 12 2.75C11.036 2.75 10.3884 2.7516 9.90539 2.81654C9.44393 2.87858 9.24644 2.9858 9.11612 3.11612C8.9858 3.24644 8.87858 3.44393 8.81654 3.9054C8.771 4.24407 8.75661 5.15523 8.75208 6.00188C9.1435 6 9.55885 6 10 6H14C14.4412 6 14.8565 6 15.2479 6.00188ZM12 9.25C12.4142 9.25 12.75 9.58579 12.75 10V10.0102C13.8388 10.2845 14.75 11.143 14.75 12.3333C14.75 12.7475 14.4142 13.0833 14 13.0833C13.5858 13.0833 13.25 12.7475 13.25 12.3333C13.25 11.9493 12.8242 11.4167 12 11.4167C11.1758 11.4167 10.75 11.9493 10.75 12.3333C10.75 12.7174 11.1758 13.25 12 13.25C13.3849 13.25 14.75 14.2098 14.75 15.6667C14.75 16.857 13.8388 17.7155 12.75 17.9898V18C12.75 18.4142 12.4142 18.75 12 18.75C11.5858 18.75 11.25 18.4142 11.25 18V17.9898C10.1612 17.7155 9.25 16.857 9.25 15.6667C9.25 15.2525 9.58579 14.9167 10 14.9167C10.4142 14.9167 10.75 15.2525 10.75 15.6667C10.75 16.0507 11.1758 16.5833 12 16.5833C12.8242 16.5833 13.25 16.0507 13.25 15.6667C13.25 15.2826 12.8242 14.75 12 14.75C10.6151 14.75 9.25 13.7903 9.25 12.3333C9.25 11.143 10.1612 10.2845 11.25 10.0102V10C11.25 9.58579 11.5858 9.25 12 9.25Z" fill="#1C274C"/>
+</svg>
diff --git a/book/src/overview.md b/book/src/overview.md
index dee4fc0..823ab00 100644
--- a/book/src/overview.md
+++ b/book/src/overview.md
@@ -170,7 +170,7 @@ The default id is a normalized version of the admonishment's title,
prefixed with the `default.css_id_prefix`,
with an appended number if multiple blocks would have the same id.
-Setting the `id` field will *ignore* all other ids and the duplicate counter.
+Setting the `id` field will _ignore_ all other ids and the duplicate counter.
````
```admonish info title="My Info" id="my-special-info"
@@ -194,3 +194,46 @@ Will yield something like the following HTML, which you can then apply styles to
Content will be hidden initially.
```
+### Custom blocks
+
+You can add new block types via the `book.toml` config:
+
+```toml
+# book.toml
+
+[[preprocessor.admonish.custom]]
+directive = "expensive"
+icon = "./money-bag.svg"
+color = "#24ab38"
+aliases = ["money", "cash", "budget"]
+```
+
+You must then generate the relevant CSS file, and reference it in the `output.html` section.
+`mdbook-admonish` has a helper to quickly do this for you:
+
+```bash
+# Generates a file at ./mdbook-admonish-custom.css with your styles in
+$ mdbook-admonish generate-custom ./mdbook-admonish-custom.css
+```
+
+```toml
+# book.toml
+
+[output.html]
+# Reference the new file, so it's bundled in with book styles
+additional-css = ["./mdbook-admonish.css", "./mdbook-admonish-custom.css"]
+```
+
+You can then reference the new directive (or alias) like usual in your blocks.
+
+````
+```admonish expensive
+Remember, this operation costs money!
+```
+````
+
+```admonish expensive
+Remember, this operation costs money!
+```
+
+You can also set a default `title`. See the [Reference](./reference.md) page for more details.
diff --git a/book/src/reference.md b/book/src/reference.md
index e8d12c0..758a25e 100644
--- a/book/src/reference.md
+++ b/book/src/reference.md
@@ -75,6 +75,31 @@ Subfields:
- For the `html` renderer, the default value is `html`.
- For all other renderers, the default value is `preserve`.
+### `custom`
+
+Optional.
+
+Additional type of block to support.
+You must run `mdbook-admonish generate-custom` after updating these values, to generate the correct styles.
+
+Add blocks using TOML's [Array of Tables](https://toml.io/en/v1.0.0#array-of-tables) notation:
+
+```toml
+[[preprocessor.admonish.custom]]
+directive = "expensive"
+icon = "./money-bag.svg"
+color = "#24ab38"
+aliases = ["money", "cash", "budget"]
+```
+
+Subfields:
+
+- `directive`: The keyword to use this type of block.
+- `icon`: A filepath relative to the book root to load an SVG icon from.
+- `color`: An RGB hex encoded color to use for the icon.
+- `aliases` (optional): One or more alternative directives to use this block.
+- `title` (optional): The default title for this type of block. If not specified, defaults to the directive in title case. To give each alias a custom title, add multiple custom blocks.
+
### `command`
Required.
@@ -93,6 +118,8 @@ This is automatically updated by `mdbook-admonish install` and should not be edi
All supported directives are listed below.
+Custom directives can be added via the `custom` config option above.
+
`note`
```admonish note
diff --git a/compile_assets/package.json b/compile_assets/package.json
index dee59ef..ccf11d3 100644
--- a/compile_assets/package.json
+++ b/compile_assets/package.json
@@ -4,7 +4,9 @@
"main": "index.js",
"license": "MIT",
"scripts": {
- "build": "sass --no-source-map scss/mdbook-admonish.scss ../src/bin/assets/mdbook-admonish.css",
+ "build": "yarn run build-prod && yarn run build-custom-expected",
+ "build-prod": "sass --no-source-map scss/mdbook-admonish.scss ../src/bin/assets/mdbook-admonish.css",
+ "build-custom-expected": "sass --no-source-map scss/mdbook-admonish-custom-expected.scss ../src/test_data/mdbook-admonish-custom-expected.css",
"lint": "prettier --check .",
"fix": "prettier --write ."
},
diff --git a/compile_assets/scss/admonition.scss b/compile_assets/scss/admonition.scss
index d9b88d2..4d4075f 100644
--- a/compile_assets/scss/admonition.scss
+++ b/compile_assets/scss/admonition.scss
@@ -22,6 +22,7 @@
@use "sass:color";
@use "sass:list";
+@use "./lib";
// ----------------------------------------------------------------------------
// Variables
@@ -68,18 +69,10 @@ $admonitions: (
) !default;
// ----------------------------------------------------------------------------
-// Rules: layout
-// ----------------------------------------------------------------------------
-
-// Admonition variables
-:root {
- @each $names, $props in $admonitions {
- --md-admonition-icon--#{nth($names, 1)}: url("data:image/svg+xml;charset=utf-8,#{nth($props, 2)}");
- }
- --md-details-icon: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M8.59 16.58 13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.42Z'/></svg>");
-}
// ----------------------------------------------------------------------------
+// Static content - base for all admonitions
+// ----------------------------------------------------------------------------
// Admonition
:is(.admonition) {
@@ -231,48 +224,20 @@ summary.admonition-title {
}
}
-// ----------------------------------------------------------------------------
-// Rules: flavours
-// ----------------------------------------------------------------------------
-
-@each $names, $props in $admonitions {
- $name: list.nth($names, 1);
- $tint: list.nth($props, 1);
-
- // Admonition flavour selectors
- $flavours: ();
-
- @each $name in $names {
- $flavours: list.join($flavours, ".#{$name}", $separator: comma);
- }
-
- // Admonition flavour
- :is(.admonition):is(#{$flavours}) {
- border-color: $tint;
- }
-
- // Admonition flavour title
- :is(#{$flavours}) > :is(.admonition-title, summary.admonition-title) {
- background-color: color.adjust($tint, $alpha: -0.9);
-
- // Admonition icon
- &::before {
- background-color: $tint;
- mask-image: var(--md-admonition-icon--#{$name});
- -webkit-mask-image: var(--md-admonition-icon--#{$name});
- mask-repeat: no-repeat;
- -webkit-mask-repeat: no-repeat;
- mask-size: contain;
- -webkit-mask-repeat: no-repeat;
- }
- }
+:root {
+ --md-details-icon: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M8.59 16.58 13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.42Z'/></svg>");
}
+// Generate rules for each specified admonition variant
+@include lib.from-admonitions($admonitions);
+
// ----------------------------------------------------------------------------
// Rules: themes
// ----------------------------------------------------------------------------
//
// One rule per builtin theme in mdbook, overriding the default fg/bg if matched
+//
+// This must be after the variant CSS, so it can override they styles set there
.navy {
& :is(.admonition) {
diff --git a/compile_assets/scss/lib.scss b/compile_assets/scss/lib.scss
new file mode 100644
index 0000000..61e7c71
--- /dev/null
+++ b/compile_assets/scss/lib.scss
@@ -0,0 +1,52 @@
+@use "sass:color";
+@use "sass:list";
+
+@mixin from-admonitions($admonitions) {
+ // ----------------------------------------------------------------------------
+ // Rules: layout
+ // ----------------------------------------------------------------------------
+
+ // Admonition variables
+ :root {
+ @each $names, $props in $admonitions {
+ --md-admonition-icon--#{nth($names, 1)}: url("data:image/svg+xml;charset=utf-8,#{nth($props, 2)}");
+ }
+ }
+
+ // ----------------------------------------------------------------------------
+ // Rules: flavours
+ // ----------------------------------------------------------------------------
+
+ @each $names, $props in $admonitions {
+ $name: list.nth($names, 1);
+ $tint: list.nth($props, 1);
+
+ // Admonition flavour selectors
+ $flavours: ();
+
+ @each $name in $names {
+ $flavours: list.join($flavours, ".#{$name}", $separator: comma);
+ }
+
+ // Admonition flavour
+ :is(.admonition):is(#{$flavours}) {
+ border-color: $tint;
+ }
+
+ // Admonition flavour title
+ :is(#{$flavours}) > :is(.admonition-title, summary.admonition-title) {
+ background-color: color.adjust($tint, $alpha: -0.9);
+
+ // Admonition icon
+ &::before {
+ background-color: $tint;
+ mask-image: var(--md-admonition-icon--#{$name});
+ -webkit-mask-image: var(--md-admonition-icon--#{$name});
+ mask-repeat: no-repeat;
+ -webkit-mask-repeat: no-repeat;
+ mask-size: contain;
+ -webkit-mask-repeat: no-repeat;
+ }
+ }
+ }
+}
diff --git a/compile_assets/scss/mdbook-admonish-custom-expected.scss b/compile_assets/scss/mdbook-admonish-custom-expected.scss
new file mode 100644
index 0000000..54f2150
--- /dev/null
+++ b/compile_assets/scss/mdbook-admonish-custom-expected.scss
@@ -0,0 +1,16 @@
+// This file aims to generate the subset of CSS specific to a single admonition directive.
+//
+// This is used for unit test data in the rust css generation module.
+
+@use "sass:color";
+@use "sass:list";
+@use "./lib";
+@import "./material-color";
+
+$admonitions: (
+ admonish-note: $clr-blue-a200
+ "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83 3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75L3 17.25z'/></svg>",
+) !default;
+
+// Generate rules for each specified admonition variant
+@include lib.from-admonitions($admonitions);
diff --git a/integration/book.toml b/integration/book.toml
index 3e4ea48..1aae74e 100644
--- a/integration/book.toml
+++ b/integration/book.toml
@@ -9,13 +9,18 @@ title = "mdbook-admonish-integration"
[preprocessor.admonish]
command = "mdbook-admonish"
-assets_version = "3.0.1" # do not edit: managed by `mdbook-admonish install`
+assets_version = "3.0.2" # do not edit: managed by `mdbook-admonish install`
after = ["links"]
+[[preprocessor.admonish.custom]]
+directive = "frog"
+icon = "./frog.svg"
+color = "#9004CC"
+
[preprocessor.admonish.renderer.test]
render_mode = "strip"
[output]
[output.html]
-additional-css = ["./mdbook-admonish.css"]
+additional-css = ["./mdbook-admonish.css", "./mdbook-admonish-custom.css"]
diff --git a/integration/expected/book.toml b/integration/expected/book.toml
index 3e4ea48..1aae74e 100644
--- a/integration/expected/book.toml
+++ b/integration/expected/book.toml
@@ -9,13 +9,18 @@ title = "mdbook-admonish-integration"
[preprocessor.admonish]
command = "mdbook-admonish"
-assets_version = "3.0.1" # do not edit: managed by `mdbook-admonish install`
+assets_version = "3.0.2" # do not edit: managed by `mdbook-admonish install`
after = ["links"]
+[[preprocessor.admonish.custom]]
+directive = "frog"
+icon = "./frog.svg"
+color = "#9004CC"
+
[preprocessor.admonish.renderer.test]
render_mode = "strip"
[output]
[output.html]
-additional-css = ["./mdbook-admonish.css"]
+additional-css = ["./mdbook-admonish.css", "./mdbook-admonish-custom.css"]
diff --git a/integration/expected/chapter_1_main.html b/integration/expected/chapter_1_main.html
index df03a98..ac02d50 100644
--- a/integration/expected/chapter_1_main.html
+++ b/integration/expected/chapter_1_main.html
@@ -18,6 +18,15 @@
<p>Simples</p>
</div>
</div>
+<div id="admonition-frog" class="admonition admonish-frog">
+<div class="admonition-title">
+<p>Frog</p>
+<p><a class="admonition-anchor-link" href="#admonition-frog"></a></p>
+</div>
+<div>
+<p>Custom frog directive</p>
+</div>
+</div>
<div id="admonition-default" class="admonition admonish-warning">
<div>
<p>No title, only body</p>
diff --git a/integration/expected/mdbook-admonish-custom.css b/integration/expected/mdbook-admonish-custom.css
new file mode 100644
index 0000000..40ae678
--- /dev/null
+++ b/integration/expected/mdbook-admonish-custom.css
@@ -0,0 +1,20 @@
+:root {
+ --md-admonition-icon--admonish-frog: url("data:image/svg+xml;charset=utf-8,<svg height='800px' width='800px' version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 512 512' xml:space='preserve'><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --><!-- ref: https://www.svgrepo.com/svg/232692/frog --><!-- Used under CC0 Licence --><path d='M472,268.109H40c-4.418,0-8,3.582-8,8s3.582,8,8,8h432c4.418,0,8-3.582,8-8S476.418,268.109,472,268.109z'/><path d='M320,300.109H192c-4.418,0-8,3.582-8,8s3.582,8,8,8h128c4.418,0,8-3.582,8-8S324.418,300.109,320,300.109z'/><path d='M483.105,224.949c-9.717-8.094-13.741-11.93-11.921-21.398c5.588-10.328,8.816-22.464,8.816-35.441c0-21.712-9.036-41.065-23.058-53.523c-8.67-14.834-24.283-25.463-43.124-29.246c-20.05-4.027-40.644,0.458-55.09,11.994C321.682,126.917,290,140.109,256,140.109s-65.682-13.192-102.728-42.776c-14.446-11.535-35.04-16.02-55.09-11.994c-18.841,3.783-34.454,14.412-43.124,29.246C41.036,127.044,32,146.397,32,168.109c0,12.977,3.228,25.113,8.816,35.441c1.82,9.468-2.204,13.305-11.921,21.398C16.701,235.106,0,249.018,0,284.109c0,30.939,44.4,68.017,85.951,92.4c55.883,32.792,117.864,51.6,170.049,51.6s114.166-18.808,170.049-51.6C467.6,352.126,512,315.049,512,284.109C512,249.018,495.299,235.106,483.105,224.949z M464,168.109c0,10.585-2.696,20.437-7.312,28.661c-0.078,0.131-0.148,0.266-0.219,0.402c-7.916,13.829-21.31,22.937-36.47,22.937c-24.262,0-44-23.327-44-52s19.738-52,44-52c9.282,0,17.896,3.423,25.002,9.245c0.351,0.356,0.731,0.674,1.135,0.955C456.965,135.79,464,150.995,464,168.109z M65.857,126.314c0.407-0.282,0.791-0.603,1.144-0.962c7.105-5.82,15.718-9.242,24.999-9.242c24.262,0,44,23.327,44,52s-19.738,52-44,52c-15.159,0-28.552-9.107-36.468-22.935c-0.072-0.138-0.143-0.275-0.222-0.407C50.696,188.545,48,178.694,48,168.11C48,150.999,55.032,135.795,65.857,126.314z M417.951,362.709c-52.713,30.933-113.256,49.4-161.951,49.4s-109.238-18.467-161.951-49.4C48.095,335.744,16,303.422,16,284.109c0-27.596,11.761-37.393,23.135-46.867c5.547-4.621,11.494-9.583,15.006-16.426c10.334,9.552,23.514,15.293,37.858,15.293c33.084,0,60-30.505,60-68c0-33.803-21.879-61.914-50.429-67.125c15.396-3.025,30.975,0.273,41.717,8.852c40.075,32.002,74.837,46.273,112.712,46.273s72.637-14.271,112.712-46.273c10.743-8.579,26.321-11.878,41.717-8.852C381.879,106.195,360,134.307,360,168.109c0,37.495,26.916,68,60,68c14.344,0,27.524-5.741,37.858-15.293c3.512,6.842,9.459,11.805,15.006,16.426C484.239,246.717,496,256.513,496,284.109C496,303.422,463.905,335.744,417.951,362.709z'/><path d='M92,180.109c8.445,0,36-1.154,36-16s-27.555-16-36-16s-36,1.154-36,16S83.555,180.109,92,180.109z'/><path d='M384,164.109c0,14.846,27.555,16,36,16s36-1.154,36-16s-27.555-16-36-16S384,149.263,384,164.109z'/><path d='M232,228.109c4.418,0,8-3.582,8-8v-8c0-4.418-3.582-8-8-8s-8,3.582-8,8v8C224,224.528,227.582,228.109,232,228.109z'/><path d='M280,228.109c4.418,0,8-3.582,8-8v-8c0-4.418-3.582-8-8-8s-8,3.582-8,8v8C272,224.528,275.582,228.109,280,228.109z'/></svg>");
+}
+
+:is(.admonition):is(.admonish-frog) {
+ border-color: #9004cc;
+}
+
+:is(.admonish-frog) > :is(.admonition-title, summary.admonition-title) {
+ background-color: rgba(144, 4, 204, 0.1);
+}
+:is(.admonish-frog) > :is(.admonition-title, summary.admonition-title)::before {
+ background-color: #9004cc;
+ mask-image: var(--md-admonition-icon--admonish-frog);
+ -webkit-mask-image: var(--md-admonition-icon--admonish-frog);
+ mask-repeat: no-repeat;
+ -webkit-mask-repeat: no-repeat;
+ mask-size: contain;
+ -webkit-mask-repeat: no-repeat;
+}
diff --git a/integration/frog.svg b/integration/frog.svg
new file mode 100644
index 0000000..259a4f3
--- /dev/null
+++ b/integration/frog.svg
@@ -0,0 +1,29 @@
+<svg height="800px" width="800px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 512 512" xml:space="preserve">
+ <!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
+ <!-- ref: https://www.svgrepo.com/svg/232692/frog -->
+ <!-- Used under CC0 Licence -->
+ <path d="M472,268.109H40c-4.418,0-8,3.582-8,8s3.582,8,8,8h432c4.418,0,8-3.582,8-8S476.418,268.109,472,268.109z"/>
+ <path d="M320,300.109H192c-4.418,0-8,3.582-8,8s3.582,8,8,8h128c4.418,0,8-3.582,8-8S324.418,300.109,320,300.109z"/>
+ <path d="M483.105,224.949c-9.717-8.094-13.741-11.93-11.921-21.398c5.588-10.328,8.816-22.464,8.816-35.441
+ c0-21.712-9.036-41.065-23.058-53.523c-8.67-14.834-24.283-25.463-43.124-29.246c-20.05-4.027-40.644,0.458-55.09,11.994
+ C321.682,126.917,290,140.109,256,140.109s-65.682-13.192-102.728-42.776c-14.446-11.535-35.04-16.02-55.09-11.994
+ c-18.841,3.783-34.454,14.412-43.124,29.246C41.036,127.044,32,146.397,32,168.109c0,12.977,3.228,25.113,8.816,35.441
+ c1.82,9.468-2.204,13.305-11.921,21.398C16.701,235.106,0,249.018,0,284.109c0,30.939,44.4,68.017,85.951,92.4
+ c55.883,32.792,117.864,51.6,170.049,51.6s114.166-18.808,170.049-51.6C467.6,352.126,512,315.049,512,284.109
+ C512,249.018,495.299,235.106,483.105,224.949z M464,168.109c0,10.585-2.696,20.437-7.312,28.661
+ c-0.078,0.131-0.148,0.266-0.219,0.402c-7.916,13.829-21.31,22.937-36.47,22.937c-24.262,0-44-23.327-44-52s19.738-52,44-52
+ c9.282,0,17.896,3.423,25.002,9.245c0.351,0.356,0.731,0.674,1.135,0.955C456.965,135.79,464,150.995,464,168.109z M65.857,126.314
+ c0.407-0.282,0.791-0.603,1.144-0.962c7.105-5.82,15.718-9.242,24.999-9.242c24.262,0,44,23.327,44,52s-19.738,52-44,52
+ c-15.159,0-28.552-9.107-36.468-22.935c-0.072-0.138-0.143-0.275-0.222-0.407C50.696,188.545,48,178.694,48,168.11
+ C48,150.999,55.032,135.795,65.857,126.314z M417.951,362.709c-52.713,30.933-113.256,49.4-161.951,49.4
+ s-109.238-18.467-161.951-49.4C48.095,335.744,16,303.422,16,284.109c0-27.596,11.761-37.393,23.135-46.867
+ c5.547-4.621,11.494-9.583,15.006-16.426c10.334,9.552,23.514,15.293,37.858,15.293c33.084,0,60-30.505,60-68
+ c0-33.803-21.879-61.914-50.429-67.125c15.396-3.025,30.975,0.273,41.717,8.852c40.075,32.002,74.837,46.273,112.712,46.273
+ s72.637-14.271,112.712-46.273c10.743-8.579,26.321-11.878,41.717-8.852C381.879,106.195,360,134.307,360,168.109
+ c0,37.495,26.916,68,60,68c14.344,0,27.524-5.741,37.858-15.293c3.512,6.842,9.459,11.805,15.006,16.426
+ C484.239,246.717,496,256.513,496,284.109C496,303.422,463.905,335.744,417.951,362.709z"/>
+ <path d="M92,180.109c8.445,0,36-1.154,36-16s-27.555-16-36-16s-36,1.154-36,16S83.555,180.109,92,180.109z"/>
+ <path d="M384,164.109c0,14.846,27.555,16,36,16s36-1.154,36-16s-27.555-16-36-16S384,149.263,384,164.109z"/>
+ <path d="M232,228.109c4.418,0,8-3.582,8-8v-8c0-4.418-3.582-8-8-8s-8,3.582-8,8v8C224,224.528,227.582,228.109,232,228.109z"/>
+ <path d="M280,228.109c4.418,0,8-3.582,8-8v-8c0-4.418-3.582-8-8-8s-8,3.582-8,8v8C272,224.528,275.582,228.109,280,228.109z"/>
+</svg>
diff --git a/integration/mdbook-admonish-custom.css b/integration/mdboo