From 0c677070edf9978cb85a0b521f7e6e0ef6d6b491 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Mon, 10 Feb 2025 12:48:38 -0600 Subject: A lot of work on aliases and the like --- src/WWW/HW.hs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/WWW/HW.hs') diff --git a/src/WWW/HW.hs b/src/WWW/HW.hs index 1ce601f..9387961 100644 --- a/src/WWW/HW.hs +++ b/src/WWW/HW.hs @@ -1,6 +1,8 @@ module WWW.HW ( removeEnv , removeSolutions + , setDocLocation + , setDocLocation_ -- * LaTeX utils , LaTeX (..) , texmap @@ -9,13 +11,28 @@ module WWW.HW , module Hakyll.TeX.LaTeX ) where --- import Prolog +import Prolog +import Hakyll import Hakyll.TeX.HaTeX import Hakyll.TeX.LaTeX +import Network.URI import Text.LaTeX.Base.Syntax +import Text.LaTeX.Packages.Hyperref removeEnv :: (String -> Bool) -> LaTeX -> LaTeX removeEnv p = texmap (\case { TeXEnv s _ _ -> p s; _ -> False }) $ pure mempty removeSolutions :: LaTeX -> LaTeX removeSolutions = removeEnv (== "solution") + +setDocLocation :: URI -> (String -> [TeXArg] -> Bool) -> Item LaTeX -> Compiler (Item LaTeX) +setDocLocation u p (Item i l) = Item i <$> texmapM (\case { TeXComm _ _ -> True; _ -> False }) mapper l + where + mapper = \case + TeXComm s args | p s args -> do + relpath <- getRoute i >>= maybe (fail $ show i <> " has no route") pure >>= maybe (fail $ "Cannot parse " <> show i <> " as a relative URI") pure . parseRelativeReference + pure $ TeXComm s [ FixArg $ url $ toSL $ relpath `relativeTo` u ] + x -> pure x + +setDocLocation_ :: URI -> Item LaTeX -> Compiler (Item LaTeX) +setDocLocation_ u = setDocLocation u $ \s _ -> s == "doclink" -- cgit v1.2.3