mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-21 05:43:39 +08:00
The new type CustomComponents is exported from T.P.Scripting, and the ScriptEngine fields are changed. Instead of separate fields for custom readers and writers, we now have a single function that loads any number of "components" from a script: these may be custom readers, custom writers, templates for writers, or extension configs. (Note: it's possible to have a custom reader and a custom writer for a format together in the same file.) Pandoc now checks the folder `custom` in the user's data directory for a matching script if it can't find one in the local directory. Previously, the `readers` and `writers` data directories were search for custom readers and writers, respectively. Scripts in those directories must be moved to the `custom` folder. Custom readers used to implement a fallback behavior that allowed to consume just a string value as input to the `Reader` function. This has been removed, the first argument is now always a list of sources. Use `tostring` on that argument to get a string. Closes #8417. Signed-off-by: Albert Krewinkel <albert@zeitkraut.de>
37 lines
1.1 KiB
Haskell
37 lines
1.1 KiB
Haskell
{-# LANGUAGE LambdaCase #-}
|
|
{- |
|
|
Module : Tests.Lua.Reader
|
|
Copyright : © 2022 Albert Krewinkel
|
|
License : GPL-2.0-or-later
|
|
Maintainer : Albert Krewinkel <pandoc@tarleb.com>
|
|
|
|
Tests for custom Lua readers.
|
|
-}
|
|
module Tests.Lua.Reader (tests) where
|
|
|
|
import Control.Arrow ((>>>))
|
|
import Data.Char (chr)
|
|
import Data.Default (Default (def))
|
|
import Text.Pandoc.Class (runIOorExplode)
|
|
import Text.Pandoc.Lua (loadCustom)
|
|
import Text.Pandoc.Readers (Reader (ByteStringReader))
|
|
import Text.Pandoc.Scripting (customReader)
|
|
import Test.Tasty (TestTree)
|
|
import Test.Tasty.HUnit ((@?=), testCase)
|
|
|
|
import qualified Data.ByteString.Lazy as BL
|
|
import qualified Data.Text as T
|
|
import qualified Text.Pandoc.Builder as B
|
|
|
|
tests :: [TestTree]
|
|
tests =
|
|
[ testCase "read binary to code block" $ do
|
|
input <- BL.readFile "bytestring.bin"
|
|
doc <- runIOorExplode $
|
|
loadCustom "bytestring-reader.lua" >>= (customReader >>> \case
|
|
Just (ByteStringReader f) -> f def input
|
|
_ -> error "Expected a bytestring reader")
|
|
let bytes = mconcat $ map (B.str . T.singleton . chr) [0..255]
|
|
doc @?= B.doc (B.plain bytes)
|
|
]
|