blob: 9df98fddbdece59149346a7568d8f5820f41f6f2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
module Hakyll.TeX.TikZ
( TikzTemplate
, tikzfilter
, tikzBlockFilter
) where
import Network.URI.Encode qualified as URI
import Text.Pandoc.Definition
import Text.Pandoc.Walk (walkM)
import Hakyll
import Prolog
import Hakyll.TeX.LaTeX (rubberPipe)
type TikzTemplate = Identifier
tikzFilter :: TikzTemplate -> Pandoc -> Compiler Pandoc
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") >>=
traverse (convSL $ rubberPipe [ "--pdf" ] >=> unixFilterLBS "pdftocairo" [ "-svg", "-", "-" ]) >>=
\(Item _ b) -> imageBlock $ ("data:image/svg+sml;utf8," <>) $ URI.encode $ filter (/= '\n') b
tikzBlockFilter _ x = pure x
|