diff options
| author | Albert Krewinkel <[email protected]> | 2021-12-31 10:23:32 +0100 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2021-12-31 17:35:52 -0800 |
| commit | 03054a33e895cacc9b2c74fd6dd5b698c58c3877 (patch) | |
| tree | 0bb4ee9a9a8fa3e9404b28951d7feaa6cb7cf336 /src | |
| parent | d6e66b1f1d79ddb0a4b402461da5e1f42ed6b658 (diff) | |
Lua: use global state when parsing documents in `pandoc.read`
The function `pandoc.read` is updated to use the same state that was
used while parsing the main input files. This ensures that log messages
are preserved and that images embedded in the input are added to the
mediabag.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Lua/Module/Pandoc.hs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Lua/Module/Pandoc.hs b/src/Text/Pandoc/Lua/Module/Pandoc.hs index d2d74aaa8..c2f1f68fd 100644 --- a/src/Text/Pandoc/Lua/Module/Pandoc.hs +++ b/src/Text/Pandoc/Lua/Module/Pandoc.hs @@ -28,7 +28,6 @@ import Data.Proxy (Proxy (Proxy)) import HsLua hiding (pushModule) import HsLua.Class.Peekable (PeekError) import System.Exit (ExitCode (..)) -import Text.Pandoc.Class.PandocIO (runIO) import Text.Pandoc.Definition import Text.Pandoc.Lua.Orphans () import Text.Pandoc.Lua.Marshal.AST @@ -36,7 +35,7 @@ import Text.Pandoc.Lua.Marshal.Filter (peekFilter) import Text.Pandoc.Lua.Marshal.ReaderOptions ( peekReaderOptions , pushReaderOptions) import Text.Pandoc.Lua.Module.Utils (sha1) -import Text.Pandoc.Lua.PandocLua (PandocLua, liftPandocLua) +import Text.Pandoc.Lua.PandocLua (PandocLua (unPandocLua), liftPandocLua) import Text.Pandoc.Options (ReaderOptions (readerExtensions)) import Text.Pandoc.Process (pipeProcess) import Text.Pandoc.Readers (Reader (..), getReader) @@ -171,13 +170,15 @@ functions = ### (\content mformatspec mreaderOptions -> do let formatSpec = fromMaybe "markdown" mformatspec readerOpts = fromMaybe def mreaderOptions - res <- Lua.liftIO . runIO $ getReader formatSpec >>= \case - (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 + readAction = getReader formatSpec >>= \case + (TextReader r, es) -> + r readerOpts{readerExtensions = es} (UTF8.toText content) + (ByteStringReader r, es) -> + r readerOpts{readerExtensions = es} (BSL.fromStrict content) + try (unPandocLua readAction) >>= \case + Right pd -> + -- success, got a Pandoc document + return pd Left (PandocUnknownReaderError f) -> Lua.failLua . T.unpack $ "Unknown reader: " <> f Left (PandocUnsupportedExtensionError e f) -> |
