diff options
| author | Albert Krewinkel <albert@zeitkraut.de> | 2021-12-30 16:53:34 +0100 |
|---|---|---|
| committer | Albert Krewinkel <albert+github@zeitkraut.de> | 2021-12-30 22:41:15 +0100 |
| commit | 2dd1cde7158a032e58618c96543ce7db2fa1aa47 (patch) | |
| tree | 933fe94fea987fb6ff9941c50e9406ed5df13b29 /src/Text/Pandoc/Lua/Module | |
| parent | ce7e1f516957c62124fcbcc83523786b0f36ed5d (diff) | |
Lua: allow binary (byte string) readers to be used with `pandoc.read`
Diffstat (limited to 'src/Text/Pandoc/Lua/Module')
| -rw-r--r-- | src/Text/Pandoc/Lua/Module/Pandoc.hs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Lua/Module/Pandoc.hs b/src/Text/Pandoc/Lua/Module/Pandoc.hs index 20c2f5af5..d2d74aaa8 100644 --- a/src/Text/Pandoc/Lua/Module/Pandoc.hs +++ b/src/Text/Pandoc/Lua/Module/Pandoc.hs @@ -21,7 +21,6 @@ module Text.Pandoc.Lua.Module.Pandoc import Prelude hiding (read) import Control.Monad (forM_, when) import Control.Monad.Catch (catch, throwM) -import Control.Monad.Except (throwError) import Data.Data (Data, dataTypeConstrs, dataTypeOf, showConstr) import Data.Default (Default (..)) import Data.Maybe (fromMaybe) @@ -47,6 +46,7 @@ import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Lazy.Char8 as BSL import qualified Data.Text as T import qualified Text.Pandoc.Lua.Util as LuaUtil +import qualified Text.Pandoc.UTF8 as UTF8 import Text.Pandoc.Error -- | Push the "pandoc" package to the Lua stack. Requires the `List` @@ -170,12 +170,12 @@ functions = , defun "read" ### (\content mformatspec mreaderOptions -> do let formatSpec = fromMaybe "markdown" mformatspec - readerOptions = fromMaybe def mreaderOptions + readerOpts = fromMaybe def mreaderOptions res <- Lua.liftIO . runIO $ getReader formatSpec >>= \case - (TextReader r, es) -> r readerOptions{ readerExtensions = es } - content - _ -> throwError $ PandocSomeError - "Only textual formats are supported" + (TextReader r, es) -> + r readerOpts{ readerExtensions = es } (UTF8.toText content) + (ByteStringReader r, es) -> + r readerOpts{ readerExtensions = es } (BSL.fromStrict content) case res of Right pd -> return pd -- success, got a Pandoc document Left (PandocUnknownReaderError f) -> @@ -185,7 +185,7 @@ functions = "Extension " <> e <> " not supported for " <> f Left e -> throwM e) - <#> parameter peekText "string" "content" "text to parse" + <#> parameter peekByteString "string" "content" "text to parse" <#> optionalParameter peekText "string" "formatspec" "format and extensions" <#> optionalParameter peekReaderOptions "ReaderOptions" "reader_options" "reader options" |
