forked from sdiehl/wiwinwlh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
includes.hs
29 lines (24 loc) · 897 Bytes
/
includes.hs
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
{-# LANGUAGE OverloadedStrings #-}
-- includes.hs
import Text.Pandoc
import Text.Pandoc.Error
doInclude :: Block -> IO Block
doInclude cb@(CodeBlock (id, classes, namevals) contents) =
case lookup "include" namevals of
Just f -> return . CodeBlock (id, classes, namevals) =<< readFile f
Nothing -> return cb
doInclude x = return x
doHtml :: Block -> IO Block
doHtml cb@(CodeBlock (id, classes, namevals) contents) =
case lookup "literal" namevals of
Just f -> return . RawBlock "html" =<< readFile f
Nothing -> return cb
doHtml x = return x
main :: IO ()
main = getContents >>= bottomUpM doInclude . readMd def
>>= bottomUpM doHtml
>>= putStrLn . writeMarkdown def
readMd :: ReaderOptions -> String -> Pandoc
readMd ropt str = case readMarkdown ropt str of
Right doc -> doc
Left err -> error $ show err