2014-06-17 07:21:30 +04:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2019-12-26 02:06:23 +03:00
|
|
|
import Control.Monad.IO.Class
|
|
|
|
import qualified Data.Text as T
|
|
|
|
import qualified Data.Text.IO as T
|
2014-04-04 03:13:17 +04:00
|
|
|
import Text.Pandoc
|
2015-12-02 04:12:06 +03:00
|
|
|
import Text.Pandoc.Error
|
2014-04-04 03:13:17 +04:00
|
|
|
|
|
|
|
doInclude :: Block -> IO Block
|
|
|
|
doInclude cb@(CodeBlock (id, classes, namevals) contents) =
|
|
|
|
case lookup "include" namevals of
|
2020-02-08 18:11:18 +03:00
|
|
|
Just f -> return . CodeBlock (id, classes, namevals) =<< T.readFile (T.unpack f)
|
2019-12-26 02:06:23 +03:00
|
|
|
Nothing -> return cb
|
2014-04-04 03:13:17 +04:00
|
|
|
doInclude x = return x
|
|
|
|
|
2014-06-17 07:21:30 +04:00
|
|
|
doHtml :: Block -> IO Block
|
|
|
|
doHtml cb@(CodeBlock (id, classes, namevals) contents) =
|
|
|
|
case lookup "literal" namevals of
|
2020-02-08 18:11:18 +03:00
|
|
|
Just f -> return . RawBlock "html" =<< T.readFile (T.unpack f)
|
2019-12-26 02:06:23 +03:00
|
|
|
Nothing -> return cb
|
2014-06-17 07:21:30 +04:00
|
|
|
doHtml x = return x
|
|
|
|
|
2019-12-26 02:06:23 +03:00
|
|
|
ropts :: ReaderOptions
|
|
|
|
ropts = def {readerExtensions = pandocExtensions}
|
|
|
|
|
|
|
|
wopts :: WriterOptions
|
|
|
|
wopts = def {writerExtensions = pandocExtensions}
|
2015-12-02 04:12:06 +03:00
|
|
|
|
2018-11-13 17:20:28 +03:00
|
|
|
main :: IO ()
|
2019-12-26 02:06:23 +03:00
|
|
|
main =
|
|
|
|
runIOorExplode $
|
|
|
|
liftIO T.getContents
|
|
|
|
>>= readMarkdown ropts
|
|
|
|
>>= liftIO . bottomUpM doInclude
|
|
|
|
>>= liftIO . bottomUpM doHtml
|
|
|
|
>>= writeMarkdown wopts
|
|
|
|
>>= liftIO . T.putStrLn
|