Skip to content

Commit

Permalink
feat(book): fix checkboxes
Browse files Browse the repository at this point in the history
The book uses custom checkboxes in the quickstart chapter. When we
moved the book to this repo (see
#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.
  • Loading branch information
W95Psp committed Jul 16, 2024
1 parent 7eb5391 commit e436991
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions book/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ stdenv.mkDerivation {
buildPhase = ''
mdbook build
mdbook build archive -d ../book/archive
bash ./postprocess.sh
'';
installPhase = "mv book $out";
}
29 changes: 29 additions & 0 deletions book/postprocess.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env sh

# This file replaces `<strong>user-checkable</strong>` with actual
# checkboxes and adds CSS to the generated HTML.

for file in $(find . -name '*.html'); do
sed -i 's|<strong>user-checkable</strong>|<input type="checkbox" class="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

0 comments on commit e436991

Please sign in to comment.