From e4369913bbad62bb129ca7dea5ad812e60345790 Mon Sep 17 00:00:00 2001 From: Lucas Franceschino Date: Tue, 16 Jul 2024 13:35:39 +0200 Subject: [PATCH] feat(book): fix checkboxes The book uses custom checkboxes in the quickstart chapter. When we moved the book to this repo (see https://github.com/hacspec/hax/pull/729), we dropped the theme. mdbook documentation suggest (see https://rust-lang.github.io/mdBook/format/theme/index.html) copying and patching the default theme. Since here it's such a small change, I added a small script that post-process the HTML instead. --- book/default.nix | 1 + book/postprocess.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100755 book/postprocess.sh diff --git a/book/default.nix b/book/default.nix index a7358b93f..98580862c 100644 --- a/book/default.nix +++ b/book/default.nix @@ -9,6 +9,7 @@ stdenv.mkDerivation { buildPhase = '' mdbook build mdbook build archive -d ../book/archive + bash ./postprocess.sh ''; installPhase = "mv book $out"; } diff --git a/book/postprocess.sh b/book/postprocess.sh new file mode 100755 index 000000000..79d4a55ae --- /dev/null +++ b/book/postprocess.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env sh + +# This file replaces `user-checkable` with actual +# checkboxes and adds CSS to the generated HTML. + +for file in $(find . -name '*.html'); do + sed -i 's|user-checkable||g' "$file" +done + +for css in $(find . -name 'general.css'); do + cat >> "$css" <<-EOF +input.user-checkable { + transform: scale(1.5); + margin-right: 8px; + margin-left: 8px; +} + +ul:has(> li > .user-checkable) { + list-style-type: none; + padding: 0; + margin: 0; +} +li:has(> .user-checkable) { + list-style-type: none; + padding: 0; + margin: 0; +} +EOF +done