From 746c92a41a4f1df5ac97246fe69555cef5419d00 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 28 Sep 2019 14:47:41 -0700 Subject: 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. --- src/Text/Pandoc/App/OutputSettings.hs | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'src/Text/Pandoc/App/OutputSettings.hs') diff --git a/src/Text/Pandoc/App/OutputSettings.hs b/src/Text/Pandoc/App/OutputSettings.hs index 744f4591f..cfb6f7ec2 100644 --- a/src/Text/Pandoc/App/OutputSettings.hs +++ b/src/Text/Pandoc/App/OutputSettings.hs @@ -85,18 +85,12 @@ optToOutputSettings opts = do then writerName else map toLower $ baseWriterName writerName - (writer, writerExts) <- + (writer :: Writer PandocIO, writerExts) <- if ".lua" `isSuffixOf` format then return (TextWriter (\o d -> writeCustom writerName o d) :: Writer PandocIO, mempty) - else case getWriter (map toLower writerName) of - Left e -> throwError $ PandocAppError $ - if format == "pdf" - then e ++ "\n" ++ pdfIsNoWriterErrorMsg - else e - Right (w, es) -> return (w :: Writer PandocIO, es) - + else getWriter (map toLower writerName) let standalone = optStandalone opts || not (isTextFormat format) || pdfOutput @@ -249,13 +243,6 @@ optToOutputSettings opts = do baseWriterName :: String -> String baseWriterName = takeWhile (\c -> c /= '+' && c /= '-') -pdfIsNoWriterErrorMsg :: String -pdfIsNoWriterErrorMsg = - "To create a pdf using pandoc, use " ++ - "-t latex|beamer|context|ms|html5" ++ - "\nand specify an output file with " ++ - ".pdf extension (-o filename.pdf)." - pdfWriterAndProg :: Maybe String -- ^ user-specified writer name -> Maybe String -- ^ user-specified pdf-engine -> IO (String, Maybe String) -- ^ IO (writerName, maybePdfEngineProg) @@ -263,6 +250,8 @@ pdfWriterAndProg mWriter mEngine = do let panErr msg = liftIO $ E.throwIO $ PandocAppError msg case go mWriter mEngine of Right (writ, prog) -> return (writ, Just prog) + Left "pdf writer" -> liftIO $ E.throwIO $ + PandocUnknownWriterError "pdf" Left err -> panErr err where go Nothing Nothing = Right ("latex", "pdflatex") @@ -279,7 +268,7 @@ pdfWriterAndProg mWriter mEngine = do [] -> Left $ "pdf-engine " ++ eng ++ " not known" - engineForWriter "pdf" = Left pdfIsNoWriterErrorMsg + engineForWriter "pdf" = Left "pdf writer" engineForWriter w = case [e | (f,e) <- engines, f == baseWriterName w] of eng : _ -> Right eng [] -> Left $ -- cgit v1.2.3