@@ -1,30 +0,0 @@
1−module DotPlugin (transform) where
2−import Text.Pandoc
3−import Text.Pandoc.Shared
4−import System.Process (readProcess)
5−import Data.Char (ord)
6−-- from the utf8-string package on HackageDB:
7−import Data.ByteString.Lazy.UTF8 (fromString)
8−-- from the SHA package on HackageDB:
9−import Data.Digest.Pure.SHA
10−
11−-- This plugin allows you to include a graphviz "dot" diagram
12−-- in a document like this:
13−--
14−-- ~~~ {.dot name="diagram1"}
15−-- digraph G {Hello->World}
16−-- ~~~
17−
18−transform :: Block -> IO Block
19−transform (CodeBlock (id, classes, namevals) contents) | "dot" `elem` classes = do
20− let (name, outfile) = case lookup "name" namevals of
21− Just fn -> ([Str fn], fn ++ ".png")
22− Nothing -> ([], uniqueName contents ++ ".png")
23− result <- readProcess "dot" ["-Tpng"] contents
24− writeFile outfile result
25− return $ Para [Image name (outfile, "")]
26−transform x = return x
27−
28−-- | Generate a unique filename given the file's contents.
29−uniqueName :: String -> String
30−uniqueName = showDigest . sha1 . fromString