summaryrefslogtreecommitdiff
path: root/src/Hakyll/TeX/TikZ.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Hakyll/TeX/TikZ.hs')
-rw-r--r--src/Hakyll/TeX/TikZ.hs25
1 files changed, 20 insertions, 5 deletions
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