diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2019-09-28 14:47:41 -0700 | 
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2019-09-29 11:43:17 -0700 | 
| commit | 746c92a41a4f1df5ac97246fe69555cef5419d00 (patch) | |
| tree | 4a300c58e87d1cf65cc5a55a5ef440b0bd71f1af /src/Text/Pandoc/App | |
| parent | 03d4e6b9ef87d4e6ed018c93b358f8557f8f7388 (diff) | |
| download | pandoc-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/App')
| -rw-r--r-- | src/Text/Pandoc/App/CommandLineOptions.hs | 23 | ||||
| -rw-r--r-- | src/Text/Pandoc/App/OutputSettings.hs | 21 | 
2 files changed, 23 insertions, 21 deletions
| diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs index cffe69eca..abb73ec92 100644 --- a/src/Text/Pandoc/App/CommandLineOptions.hs +++ b/src/Text/Pandoc/App/CommandLineOptions.hs @@ -768,12 +768,25 @@ options =      , Option "" ["list-extensions"]                   (OptArg                    (\arg _ -> do -                     let exts = getDefaultExtensions (fromMaybe "markdown" arg) -                     let showExt x = (if extensionEnabled x exts -                                         then '+' -                                         else '-') : drop 4 (show x) +                     let extList :: [Extension] +                         extList = [minBound..maxBound] +                     let allExts = +                           case arg of +                             Nothing  -> extensionsFromList extList +                             Just fmt -> getAllExtensions fmt +                     let defExts = +                           case arg of +                             Nothing   -> getDefaultExtensions +                                           "markdown" +                             Just fmt  -> getDefaultExtensions fmt +                     let showExt x = +                           (if extensionEnabled x defExts +                               then '+' +                               else if extensionEnabled x allExts +                                       then '-' +                                       else ' ') : drop 4 (show x)                       mapM_ (UTF8.hPutStrLn stdout . showExt) -                               ([minBound..maxBound] :: [Extension]) +                       [ex | ex <- extList, extensionEnabled ex allExts]                       exitSuccess )                    "FORMAT")                   "" 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 $ | 
