Switch to new pandoc-types and use Text instead of String [API change].
PR #5884.
+ Use pandoc-types 1.20 and texmath 0.12.
+ Text is now used instead of String, with a few exceptions.
+ In the MediaBag module, some of the types using Strings
were switched to use FilePath instead (not Text).
+ In the Parsing module, new parsers `manyChar`, `many1Char`,
`manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`,
`mantyUntilChar` have been added: these are like their
unsuffixed counterparts but pack some or all of their output.
+ `glob` in Text.Pandoc.Class still takes String since it seems
to be intended as an interface to Glob, which uses strings.
It seems to be used only once in the package, in the EPUB writer,
so that is not hard to change.
2019-11-04 22:12:37 +01:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2014-05-08 21:50:20 +02:00
|
|
|
{-
|
2021-01-08 18:38:20 +01:00
|
|
|
Copyright (C) 2012-2021 John MacFarlane <jgm@berkeley.edu>
|
2014-05-08 21:50:20 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
-}
|
2010-12-11 08:35:31 +01:00
|
|
|
import Text.Pandoc
|
2019-08-25 22:58:29 +02:00
|
|
|
import Text.Pandoc.MIME
|
2021-03-16 06:50:18 +01:00
|
|
|
import Control.DeepSeq (force)
|
2021-02-13 09:14:49 +01:00
|
|
|
import Control.Monad.Except (throwError)
|
2017-06-10 20:57:38 +02:00
|
|
|
import qualified Text.Pandoc.UTF8 as UTF8
|
2017-01-27 11:15:45 +01:00
|
|
|
import qualified Data.ByteString as B
|
Switch to new pandoc-types and use Text instead of String [API change].
PR #5884.
+ Use pandoc-types 1.20 and texmath 0.12.
+ Text is now used instead of String, with a few exceptions.
+ In the MediaBag module, some of the types using Strings
were switched to use FilePath instead (not Text).
+ In the Parsing module, new parsers `manyChar`, `many1Char`,
`manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`,
`mantyUntilChar` have been added: these are like their
unsuffixed counterparts but pack some or all of their output.
+ `glob` in Text.Pandoc.Class still takes String since it seems
to be intended as an interface to Glob, which uses strings.
It seems to be used only once in the package, in the EPUB writer,
so that is not hard to change.
2019-11-04 22:12:37 +01:00
|
|
|
import qualified Data.Text as T
|
2021-03-17 21:34:17 +01:00
|
|
|
import Test.Tasty.Bench
|
|
|
|
-- import Gauge
|
2019-08-25 22:58:29 +02:00
|
|
|
import qualified Data.ByteString.Lazy as BL
|
2021-02-13 09:14:49 +01:00
|
|
|
import Data.Maybe (mapMaybe)
|
2021-02-20 09:28:10 +01:00
|
|
|
import Data.List (sortOn)
|
2020-07-07 05:10:45 +02:00
|
|
|
|
2010-12-11 08:35:31 +01:00
|
|
|
readerBench :: Pandoc
|
Switch to new pandoc-types and use Text instead of String [API change].
PR #5884.
+ Use pandoc-types 1.20 and texmath 0.12.
+ Text is now used instead of String, with a few exceptions.
+ In the MediaBag module, some of the types using Strings
were switched to use FilePath instead (not Text).
+ In the Parsing module, new parsers `manyChar`, `many1Char`,
`manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`,
`mantyUntilChar` have been added: these are like their
unsuffixed counterparts but pack some or all of their output.
+ `glob` in Text.Pandoc.Class still takes String since it seems
to be intended as an interface to Glob, which uses strings.
It seems to be used only once in the package, in the EPUB writer,
so that is not hard to change.
2019-11-04 22:12:37 +01:00
|
|
|
-> T.Text
|
2021-02-13 09:14:49 +01:00
|
|
|
-> Maybe Benchmark
|
2021-03-16 06:50:18 +01:00
|
|
|
readerBench _ name
|
|
|
|
| name `elem` ["bibtex", "biblatex", "csljson"] = Nothing
|
2021-02-13 09:14:49 +01:00
|
|
|
readerBench doc name = either (const Nothing) Just $
|
|
|
|
runPure $ do
|
|
|
|
(rdr, rexts) <- getReader name
|
|
|
|
(wtr, wexts) <- getWriter name
|
|
|
|
case (rdr, wtr) of
|
|
|
|
(TextReader r, TextWriter w) -> do
|
|
|
|
inp <- w def{ writerWrapText = WrapAuto
|
|
|
|
, writerExtensions = wexts } doc
|
|
|
|
return $ bench (T.unpack name) $
|
|
|
|
nf (either (error . show) id . runPure . r def) inp
|
|
|
|
(ByteStringReader r, ByteStringWriter w) -> do
|
|
|
|
tmpl <- Just <$> compileDefaultTemplate name
|
|
|
|
inp <- w def{ writerWrapText = WrapAuto
|
|
|
|
, writerExtensions = wexts
|
|
|
|
, writerTemplate = tmpl } doc
|
|
|
|
return $ bench (T.unpack name) $
|
|
|
|
nf (either (error . show) id .
|
|
|
|
runPure . r def{readerExtensions = rexts}) inp
|
|
|
|
_ -> throwError $ PandocSomeError $ "text/bytestring format mismatch: "
|
|
|
|
<> name
|
2010-12-11 08:35:31 +01:00
|
|
|
|
2019-08-25 22:58:29 +02:00
|
|
|
getImages :: IO [(FilePath, MimeType, BL.ByteString)]
|
|
|
|
getImages = do
|
2021-03-16 02:19:36 +01:00
|
|
|
ll <- B.readFile "test/lalune.jpg"
|
|
|
|
mv <- B.readFile "test/movie.jpg"
|
|
|
|
return [("lalune.jpg", "image/jpg", BL.fromStrict ll)
|
|
|
|
,("movie.jpg", "image/jpg", BL.fromStrict mv)]
|
2019-08-25 22:58:29 +02:00
|
|
|
|
2021-01-31 03:01:14 +01:00
|
|
|
writerBench :: [(FilePath, MimeType, BL.ByteString)]
|
|
|
|
-> Pandoc
|
Switch to new pandoc-types and use Text instead of String [API change].
PR #5884.
+ Use pandoc-types 1.20 and texmath 0.12.
+ Text is now used instead of String, with a few exceptions.
+ In the MediaBag module, some of the types using Strings
were switched to use FilePath instead (not Text).
+ In the Parsing module, new parsers `manyChar`, `many1Char`,
`manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`,
`mantyUntilChar` have been added: these are like their
unsuffixed counterparts but pack some or all of their output.
+ `glob` in Text.Pandoc.Class still takes String since it seems
to be intended as an interface to Glob, which uses strings.
It seems to be used only once in the package, in the EPUB writer,
so that is not hard to change.
2019-11-04 22:12:37 +01:00
|
|
|
-> T.Text
|
2017-12-30 23:25:38 +01:00
|
|
|
-> Maybe Benchmark
|
2021-03-16 06:50:18 +01:00
|
|
|
writerBench _ _ name
|
|
|
|
| name `elem` ["bibtex", "biblatex", "csljson"] = Nothing
|
2021-02-13 09:14:49 +01:00
|
|
|
writerBench imgs doc name = either (const Nothing) Just $
|
|
|
|
runPure $ do
|
|
|
|
(wtr, wexts) <- getWriter name
|
|
|
|
case wtr of
|
|
|
|
TextWriter writerFun ->
|
|
|
|
return $ bench (T.unpack name)
|
2017-12-30 23:25:38 +01:00
|
|
|
$ nf (\d -> either (error . show) id $
|
2021-02-13 09:14:49 +01:00
|
|
|
runPure $ do
|
|
|
|
mapM_ (\(fp,mt,bs) -> insertMedia fp (Just mt) bs) imgs
|
|
|
|
writerFun def{ writerExtensions = wexts} d)
|
|
|
|
doc
|
2021-02-20 09:28:10 +01:00
|
|
|
ByteStringWriter writerFun ->
|
|
|
|
return $ bench (T.unpack name)
|
|
|
|
$ nf (\d -> either (error . show) id $
|
|
|
|
runPure $ do
|
|
|
|
mapM_ (\(fp,mt,bs) -> insertMedia fp (Just mt) bs) imgs
|
|
|
|
writerFun def{ writerExtensions = wexts} d)
|
|
|
|
doc
|
2010-12-11 08:35:31 +01:00
|
|
|
|
2012-07-26 19:02:00 +02:00
|
|
|
main :: IO ()
|
2010-12-11 08:35:31 +01:00
|
|
|
main = do
|
2017-06-10 20:57:38 +02:00
|
|
|
inp <- UTF8.toText <$> B.readFile "test/testsuite.txt"
|
2017-01-27 11:15:45 +01:00
|
|
|
let opts = def
|
2021-03-16 06:50:18 +01:00
|
|
|
let doc = either (error . show) force $ runPure $ readMarkdown opts inp
|
2021-01-31 03:01:14 +01:00
|
|
|
defaultMain
|
2021-03-16 02:19:36 +01:00
|
|
|
[ env getImages $ \imgs ->
|
|
|
|
bgroup "writers" $ mapMaybe (writerBench imgs doc . fst)
|
2021-02-20 09:28:10 +01:00
|
|
|
(sortOn fst
|
|
|
|
writers :: [(T.Text, Writer PandocPure)])
|
2021-02-13 09:14:49 +01:00
|
|
|
, bgroup "readers" $ mapMaybe (readerBench doc . fst)
|
2021-02-20 09:28:10 +01:00
|
|
|
(sortOn fst
|
|
|
|
readers :: [(T.Text, Reader PandocPure)])
|
2021-01-31 03:01:14 +01:00
|
|
|
]
|