git.iko.soy/typeable/pandoc
on 2.2.2 help sign in
typeable/pandoc/benchmark/weigh-pandoc.hs
40 lines 1.3 kB history raw
1{-# LANGUAGE NoImplicitPrelude #-}
2import Prelude
3import Weigh
4import Text.Pandoc
5import Data.Text (Text)
7main :: IO ()
8main = do
9 doc <- read <$> readFile "test/testsuite.native"
10 mainWith $ do
11 func "Pandoc document" id doc
12 mapM_
13 (\(n,r) -> weighReader doc n (either (error . show) id . runPure . r def{readerExtensions = pandocExtensions}))
14 [("markdown", readMarkdown)
15 ,("html", readHtml)
16 ,("docbook", readDocBook)
17 ,("latex", readLaTeX)
18 ,("commonmark", readCommonMark)
19 ]
20 mapM_
21 (\(n,w) -> weighWriter doc n (either (error . show) id . runPure . w def))
22 [("markdown", writeMarkdown)
23 ,("html", writeHtml5String)
24 ,("docbook", writeDocbook5)
25 ,("latex", writeLaTeX)
26 ,("commonmark", writeCommonMark)
27 ]
29weighWriter :: Pandoc -> String -> (Pandoc -> Text) -> Weigh ()
30weighWriter doc name writer = func (name ++ " writer") writer doc
32weighReader :: Pandoc -> String -> (Text -> Pandoc) -> Weigh ()
33weighReader doc name reader = do
34 case lookup name writers of
35 Just (TextWriter writer) ->
36 let inp = either (error . show) id $ runPure $ writer def{ writerWrapText = WrapAuto} doc
37 in func (name ++ " reader") reader inp
38 _ -> return () -- no writer for reader