#!/usr/bin/env nix #! nix shell --impure --expr `` #! nix with (builtins.getFlake "git+file://${toString ./../..}/..").packages.${builtins.currentSystem}; #! nix [ #! nix (haskellPackages.ghcWithPackages ( #! nix haskellPackages: [ #! nix haskellPackages.pandoc-types #! nix ] #! nix )) #! nix ] #! nix `` #! nix --command runhaskell {-#LANGUAGE OverloadedStrings#-} {-#LANGUAGE ViewPatterns #-} import Text.Pandoc.JSON import Data.List qualified as List import Data.Text qualified as Text main :: IO () main = toJSONFilter filt filt :: Block -> Block -- Put chapter images into the chapter filt (Div as@(_, ["Section1"], _) es) = Div as (fixChapterImage es) -- Remove useless images filt (Para (Image _ _ ("Images/philos0.jpg", _):_)) = Para [] filt x = x fixChapterImage (p@(Para [ Span ( _ , _ , _ ) (Image ( _ , _ , _ ) _ ( Text.isPrefixOf "Images/Chapter" -> True , _ ) :_) ]) :h@Header{} :xs ) = h:p:xs fixChapterImage (x:xs) = x:fixChapterImage xs fixChapterImage [] = [] -- vim: syntax=haskell