From 08305f7d578135084b65c161cda51f3f36f732ec Mon Sep 17 00:00:00 2001 From: Pyrox Date: Sat, 20 Jul 2024 21:58:12 -0400 Subject: [PATCH] fix admonitions --- overlays/lix-docs/default.nix | 10 +--- packages/md-manual/TODO.md | 6 +-- packages/nixpkgs-manual/default.nix | 84 +++++++++++++++++++++-------- 3 files changed, 66 insertions(+), 34 deletions(-) diff --git a/overlays/lix-docs/default.nix b/overlays/lix-docs/default.nix index 19267b7..9d75a8b 100644 --- a/overlays/lix-docs/default.nix +++ b/overlays/lix-docs/default.nix @@ -1,12 +1,6 @@ { channels, ... }: final: prev: { - lix-docs = channels.nixpkgs.lix.overrideAttrs (old: { - patches = (old.patches or [ ]) ++ [ - (prev.fetchpatch { - url = "https://git.lix.systems/lix-project/lix/commit/c7af89c79771a6d4eb84baa6cd9b7551b3a84a4b.patch"; - hash = "sha256-u5c9GsPb1K2yjK6lhg7x0ui0lRHZA5r7Iqg0IMCD/CI="; - }) - ]; + lix-docs = channels.nixpkgs.lix.overrideAttrs { postBuild = '' TERM=dumb ninja doc/manual/markdown ''; @@ -20,5 +14,5 @@ final: prev: { installCheckPhase = '' true ''; - }); + }; } diff --git a/packages/md-manual/TODO.md b/packages/md-manual/TODO.md index 7e316ae..c8c07ef 100644 --- a/packages/md-manual/TODO.md +++ b/packages/md-manual/TODO.md @@ -2,11 +2,9 @@ Ongoing or future fixups and projects for this documentation site -- [ ] Fix Nixpkgs documentation admonitions +- [x] Fix Nixpkgs documentation admonitions - - Currently all of them are broken and need to have their formatting adjusted to be not broken. - - See all the examples [here](https://aux-docs.pyrox.pages.gay/Nixpkgs/library-reference/asserts/), for instance. - The code block should be inside the admonition. + - We believe that all admonitions in the documentation should be automatically fixed up. If they aren't, please let us know where you see broken ones! - [ ] Replace Lix doc fixme's with admonitions diff --git a/packages/nixpkgs-manual/default.nix b/packages/nixpkgs-manual/default.nix index f609c2e..3498568 100644 --- a/packages/nixpkgs-manual/default.nix +++ b/packages/nixpkgs-manual/default.nix @@ -38,6 +38,9 @@ let }; }; optionsMD = optionsDoc.optionsCommonMark; + + p = "find . -type f -exec perl -pi -e"; + s = "find . -type f -exec sed -i"; in stdenvNoCC.mkDerivation { name = "nixpkgs-manual-md"; @@ -68,29 +71,66 @@ stdenvNoCC.mkDerivation { mkdir out cp ${optionsMD} out/options.md mv preface.chapter.md out/index.md - mv build-helpers out/build-helpers - mv build-helpers.md out/build-helpers/index.md - mv development out/development - mv development.md out/development/index.md - mv functions out/functions - mv functions.md out/functions/index.md - mv hooks out/hooks - mv languages-frameworks out/languages-and-frameworks - mkdir out/library-reference - cp ${pkgs.amg.nixpkgs-lib-docs}/*.md out/library-reference/ - mv module-system out/module-system - mv packages out/packages - mv stdenv out/stdenv - mv stdenv.md out/stdenv/index.md - mv using out/using-nixpkgs - mv using-nixpkgs.md out/using-nixpkgs/index.md + mv build-helpers out/Build-Helpers + mv build-helpers.md out/Build-Helpers/index.md + mv development out/Development + mv development.md out/Development/index.md + mv functions out/Functions + mv functions.md out/Functions/index.md + mv hooks out/Hooks + mv languages-frameworks out/Languages-And-Frameworks + mkdir out/Library-Reference + cp ${pkgs.amg.nixpkgs-lib-docs}/*.md out/Library-Reference/ + mv module-system out/Module-System + mv packages out/Packages + mv stdenv out/Standard-Environment + mv stdenv.md out/Standard-Environment/index.md + mv using out/Using-Nixpkgs + mv using-nixpkgs.md out/Using-Nixpkgs/index.md pushd out - find . -type f -exec perl -pi -e 's/\s*:::{.note}\n/!!! note\n\ \ /' {} \; - find . -type f -exec perl -pi -e 's/\s*:::{.warning}\n/!!! warning\n\ \ /' {} \; - find . -type f -exec perl -pi -e 's/\s*:::{.tip}\n/!!! tip\n\ \ \ \ /' {} \; - find . -type f -exec perl -pi -e 's/\s*:::{.example}\n/!!! example\n\ \ \ \ /' {} \; - find . -type f -exec sed -i 's/\s*::://g' {} \; - find . -type f -exec sed -i 's/\n```nix/\ \ \ \ ```nix/g' {} \; + + # Fix-up options page + sed -i 's!${inputs.nixpkgs.outPath}!https://github.com/NixOS/nixpkgs/blob/master!g' options.md + sed -i 's!file://!!g' options.md + sed -i 's/\\//g' options.md + + # Clean up all index pages + ${s} '/```{=include=}/,$d' {} \; + + # Remove all ::: sequences + ${s} 's/\s*::://g' {} \; + + # Indent all nix codeblocks + # ${p} 's/\n```nix/\ \ \ \ ```nix/g' -0 {} \; + + # Replace nix-style note admonitions + ${p} 's/\s*(\w?){.note}/!!! note/' {} \; + ${s} '/^\!\!\![[:space:]]note/,/^$/s/^/\ \ \ \ /' {} \; + ${s} 's/^\ \ \ \ !!! note/!!! note/' {} \; + + # Replace nix-style warning admonitions + ${p} 's/\s*(\w?){.warning}/!!! warning/' {} \; + ${s} '/^\!\!\![[:space:]]warning/,/^$/s/^/\ \ \ \ /' {} \; + ${s} 's/^\ \ \ \ !!! warning/!!! warning/' {} \; + + # Replace nix-style tip admonitions + ${p} 's/\s*(\w?){.tip}/!!! tip/' {} \; + ${s} '/^\!\!\![[:space:]]tip/,/^$/s/^/\ \ \ \ /' {} \; + ${s} 's/^\ \ \ \ !!! tip/!!! tip/' {} \; + + # Replace nix-style example admonitions + ${p} 's/\s*(\w?){.example.*}/!!! example/' {} \; + ${p} 's/\n\n# /\ \"/g' -0 {} \; + ${s} '/^!!! example/,/^$/s/^/\ \ \ \ /' {} \; + ${s} 's/^\ \ \ \ !!! example/!!! example/' {} \; + + # Have to special-case some example admonitions + ${p} 's/\n\n\n/placeholderstring123/g' -0 {} \; + ${s} '/^!!! example/,/placeholderstring123/s/^/\ \ \ \ /' {} \; + ${p} 's/placeholderstring123/\n\n\n/g' -0 {} \; + ${s} 's/^\ \ \ \ !!! example/!!! example/' {} \; + ${p} 's/example\n[ ]{8}#### /example "/g' -0 {} \; + ${s} '/^!!! example \"/s/$/\"/' {} \; popd '';