aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Lua/Module/Pandoc.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-09-28 14:47:41 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-09-29 11:43:17 -0700
commit746c92a41a4f1df5ac97246fe69555cef5419d00 (patch)
tree4a300c58e87d1cf65cc5a55a5ef440b0bd71f1af /src/Text/Pandoc/Lua/Module/Pandoc.hs
parent03d4e6b9ef87d4e6ed018c93b358f8557f8f7388 (diff)
downloadpandoc-746c92a41a4f1df5ac97246fe69555cef5419d00.tar.gz
Raise error on unsupported extensions. Closes #4338.
+ An error is now raised if you try to specify (enable or disable) an extension that does not affect the given format, e.g. `docx+pipe_tables`. + The `--list-extensions[=FORMAT]` option now lists only extensions that affect the given FORMAT. + Text.Pandoc.Error: Add constructors `PandocUnknownReaderError`, `PandocUnknownWriterError`, `PandocUnsupportedExtensionError`. [API change] + Text.Pandoc.Extensions now exports `getAllExtensions`, which returns the extensions that affect a given format (whether enabled by default or not). [API change] + Text.Pandoc.Extensions: change type of `parseFormatSpec` from `Either ParseError (String, Extensions -> Extensions)` to `Either ParseError (String, [Extension], [Extension])` [API change]. + Text.Pandoc.Readers: change type of `getReader` so it returns a value in the PandocMonad instance rather than an Either [API change]. Exceptions for unknown formats and unsupported extensions are now raised by this function and need not be handled by the calling function. + Text.Pandoc.Writers: change type of `getWriter` so it returns a value in the PandocMonad instance rather than an Either [API change]. Exceptions for unknown formats and unsupported extensions are now raised by this function and need not be handled by the calling function.
Diffstat (limited to 'src/Text/Pandoc/Lua/Module/Pandoc.hs')
-rw-r--r--src/Text/Pandoc/Lua/Module/Pandoc.hs25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Lua/Module/Pandoc.hs b/src/Text/Pandoc/Lua/Module/Pandoc.hs
index 8950c4b7f..182008da7 100644
--- a/src/Text/Pandoc/Lua/Module/Pandoc.hs
+++ b/src/Text/Pandoc/Lua/Module/Pandoc.hs
@@ -16,6 +16,7 @@ module Text.Pandoc.Lua.Module.Pandoc
import Prelude
import Control.Monad (when)
+import Control.Monad.Except (throwError)
import Data.Default (Default (..))
import Data.Maybe (fromMaybe)
import Data.Text (pack)
@@ -34,6 +35,7 @@ import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Lazy.Char8 as BSL
import qualified Foreign.Lua as Lua
import qualified Text.Pandoc.Lua.Util as LuaUtil
+import Text.Pandoc.Error
-- | Push the "pandoc" on the lua stack. Requires the `list` module to be
-- loaded.
@@ -60,17 +62,20 @@ walkBlock = walkElement
readDoc :: String -> Optional String -> Lua NumResults
readDoc content formatSpecOrNil = do
let formatSpec = fromMaybe "markdown" (Lua.fromOptional formatSpecOrNil)
- case getReader formatSpec of
- Left s -> Lua.raiseError s -- Unknown reader
- Right (reader, es) ->
- case reader of
- TextReader r -> do
- res <- Lua.liftIO . runIO $
+ res <- Lua.liftIO . runIO $
+ getReader formatSpec >>= \(rdr,es) ->
+ case rdr of
+ TextReader r ->
r def{ readerExtensions = es } (pack content)
- case res of
- Right pd -> (1 :: NumResults) <$ Lua.push pd -- success, push Pandoc
- Left s -> Lua.raiseError (show s) -- error while reading
- _ -> Lua.raiseError "Only string formats are supported at the moment."
+ _ -> throwError $ PandocSomeError $
+ "Only textual formats are supported"
+ case res of
+ Right pd -> (1 :: NumResults) <$ Lua.push pd -- success, push Pandoc
+ Left (PandocUnknownReaderError f) -> Lua.raiseError $
+ "Unknown reader: " ++ f
+ Left (PandocUnsupportedExtensionError e f) -> Lua.raiseError $
+ "Extension " ++ e ++ " not supported for " ++ f
+ Left e -> Lua.raiseError $ show e
-- | Pipes input through a command.
pipeFn :: String