-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpandoc_filter.hs
22 lines (19 loc) · 904 Bytes
/
pandoc_filter.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import Graphics.Svg( applyCSSRules
, xmlOfDocument
, Document( _styleRules ) )
import Text.Pandoc.JSON( Block( CodeBlock, RawBlock )
, Format( .. )
, toJSONFilter )
import Text.AsciiDiagram( parseAsciiDiagram, svgOfDiagram )
import Text.XML.Light.Output( ppcTopElement, prettyConfigPP )
import qualified Data.Text as T
main :: IO ()
main = toJSONFilter insertDiagrams
insertDiagrams :: Block -> IO [Block]
insertDiagrams (CodeBlock (_ident, classes, _attrs) code)
| "ditaa" `elem` classes || "asciidiagram" `elem` classes = do
let svg = applyCSSRules . svgOfDiagram . parseAsciiDiagram $ T.pack code
stripCss d = d { _styleRules = [] }
xmlStr = ppcTopElement prettyConfigPP . xmlOfDocument $ stripCss svg
return [RawBlock (Format "html") $ xmlStr]
insertDiagrams block = return [block]