tommilligan / mdbook-admonish

A preprocessor for mdbook to add Material Design admonishments.
MIT License
171 stars 18 forks source link

feat: custom directives #165

Closed tommilligan closed 8 months ago

tommilligan commented 8 months ago

Closes #99 Replaces #157 cc: @Sky9x as you've already thought a lot about this - I used a bunch of code and ideas from your branch, it was really helpful!

As I already wrote the doc page, I think this summarises the changes quite nicely:

image


The approach I took here was to write some slightly hacky Rust code to produce the small subset of CSS we need for each new variant. There's a unit test that will fail if either the Rust or SCSS code get out of step.

I think this is a good compromise between still doing the majority of complex CSS with SCSS, having runtime directive safety in Rust, and ensuring that there are some checks in place. An alternative would just have been to work out how to run an SCSS compiler inside a Rust binary, but I really did not want to do that.

This approach is also back compatible, and opt in for new users, which is great.

image


Internals wise, this changes slightly how the Directive type works internally. Basically, we standardise to a String earlier in the pipeline, at the point we resolve the title.

Uses hex_color for that concern as it's simple and looks to do the job well.

Sky9x commented 8 months ago

this looks cool! and better than what i threw together at 5am :sleepy: