1module DotPlugin (transform) where
3import Text.Pandoc.Shared
4import System.Process (readProcess)
6-- from the utf8-string package on HackageDB:
7import Data.ByteString.Lazy.UTF8 (fromString)
8-- from the SHA package on HackageDB:
9import Data.Digest.Pure.SHA
11-- This plugin allows you to include a graphviz "dot" diagram
12-- in a document like this:
14-- ~~~ {.dot name="diagram1"}
15-- digraph G {Hello->World}
18transform :: Block -> IO Block
19transform (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, "")]
28-- | Generate a unique filename given the file's contents.
29uniqueName :: String -> String
30uniqueName = showDigest . sha1 . fromString
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list