-
Notifications
You must be signed in to change notification settings - Fork 243
/
includes.hs
37 lines (31 loc) · 1.03 KB
/
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
30
31
32
33
34
35
36
37
{-# LANGUAGE OverloadedStrings #-}
import Control.Monad.IO.Class
import qualified Data.Text as T
import qualified Data.Text.IO as T
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) =<< T.readFile (T.unpack 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" =<< T.readFile (T.unpack f)
Nothing -> return cb
doHtml x = return x
ropts :: ReaderOptions
ropts = def {readerExtensions = pandocExtensions}
wopts :: WriterOptions
wopts = def {writerExtensions = pandocExtensions}
main :: IO ()
main =
runIOorExplode $
liftIO T.getContents
>>= readMarkdown ropts
>>= liftIO . bottomUpM doInclude
>>= liftIO . bottomUpM doHtml
>>= writeMarkdown wopts
>>= liftIO . T.putStrLn