From ca1d4d3d4371c8175ea6addb1ca1b09c3b56a7bb Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Sat, 25 Jan 2025 14:33:21 -0600 Subject: Adding templates and cleaning up --- src/Hakyll/TeX/TikZ.hs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/Hakyll/TeX/TikZ.hs') diff --git a/src/Hakyll/TeX/TikZ.hs b/src/Hakyll/TeX/TikZ.hs index 9df98fd..c9087e7 100644 --- a/src/Hakyll/TeX/TikZ.hs +++ b/src/Hakyll/TeX/TikZ.hs @@ -1,7 +1,12 @@ +{-# LANGUAGE TemplateHaskell #-} module Hakyll.TeX.TikZ ( TikzTemplate - , tikzfilter + , tikzFilter , tikzBlockFilter + -- * Using the default TikZ template + , tikzTemplate + , tikzFilter_ + , tikzBlockFilter_ ) where import Network.URI.Encode qualified as URI @@ -14,16 +19,26 @@ import Prolog import Hakyll.TeX.LaTeX (rubberPipe) -type TikzTemplate = Identifier +type TikzTemplate = Template tikzFilter :: TikzTemplate -> Pandoc -> Compiler Pandoc -tikzFilter = walkM tikzBlockFilter +tikzFilter = walkM . tikzBlockFilter -- | Requires `rubber` and `poppler_utils` tikzBlockFilter :: TikzTemplate -> Block -> Compiler Block tikzBlockFilter tmpl (CodeBlock info@(_, "tikzpicture":_, _) contents) = do let imageBlock fname = Para [ Image info [] (toSL fname, "") ] - makeItem (toSL contents) >>= loadAndApplyTemplate tmpl (bodyField "body") >>= + makeItem (toSL contents) >>= applyTemplate tmpl (bodyField "body") >>= traverse (convSL $ rubberPipe [ "--pdf" ] >=> unixFilterLBS "pdftocairo" [ "-svg", "-", "-" ]) >>= - \(Item _ b) -> imageBlock $ ("data:image/svg+sml;utf8," <>) $ URI.encode $ filter (/= '\n') b + \(Item _ b) -> pure $ imageBlock $ ("data:image/svg+sml;utf8," <>) $ URI.encode $ filter (/= '\n') b tikzBlockFilter _ x = pure x + + +tikzTemplate :: TikzTemplate +tikzTemplate = $(embedTemplate "templates/tikz.tex") + +tikzBlockFilter_ :: Block -> Compiler Block +tikzBlockFilter_ = tikzBlockFilter tikzTemplate + +tikzFilter_ :: Pandoc -> Compiler Pandoc +tikzFilter_ = tikzFilter tikzTemplate -- cgit v1.2.3