-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpandoc-filter-manager.hs
45 lines (39 loc) · 1.28 KB
/
pandoc-filter-manager.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
38
39
40
41
42
43
44
45
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
--------------------------------------------------------------------------------
import Text.Pandoc.JSON
import Text.Pandoc.Walk
import Control.Arrow
( (&&&) )
import Control.Monad
( foldM )
import Data.Aeson
import Data.ByteString.Lazy
( ByteString )
import qualified Data.ByteString.Lazy as BL
import qualified HSH
import System.Environment
( getArgs )
--------------------------------------------------------------------------------
main :: IO ()
main
= BL.getContents
>>= runFilters
. ( ( getFilters . either error id . eitherDecode' ) &&& id )
>>= BL.putStr
runFilters :: ([String], ByteString) -> IO ByteString
runFilters (filters, doc)
= foldM run doc filters
where
run :: ByteString -> String -> IO ByteString
run doc' f = do
args <- getArgs
HSH.run $ (const doc' :: () -> ByteString) HSH.-|- (f, args)
getFilters :: Pandoc -> [String]
getFilters (Pandoc m _)
= maybe [] (query getStr)
$ lookupMeta "filters" m
where
getStr (Str x) = [x]
getStr _ = []
--------------------------------------------------------------------------------