[API Change] Change argument type of getReader, getWriter.

The functions now take a `FlavoredFormat` instead of a text argument.
This commit is contained in:
Albert Krewinkel
2022-10-08 23:01:27 +02:00
committed by John MacFarlane
parent a4218b9719
commit 5589b1f8f9
6 changed files with 21 additions and 21 deletions
@@ -30,6 +30,7 @@ import HsLua hiding (pushModule)
import System.Exit (ExitCode (..))
import Text.Pandoc.Definition
import Text.Pandoc.Error (PandocError (..))
import Text.Pandoc.Format (parseFlavoredFormat)
import Text.Pandoc.Lua.Orphans ()
import Text.Pandoc.Lua.Marshal.AST
import Text.Pandoc.Lua.Marshal.Filter (peekFilter)
@@ -208,7 +209,7 @@ functions =
, defun "read"
### (\content mformatspec mreaderOptions -> unPandocLua $ do
let readerOpts = fromMaybe def mreaderOptions
let formatSpec = fromMaybe "markdown" mformatspec
formatSpec <- parseFlavoredFormat $ fromMaybe "markdown" mformatspec
getReader formatSpec >>= \case
(TextReader r, es) ->
r readerOpts{readerExtensions = es}
@@ -246,7 +247,7 @@ functions =
, defun "write"
### (\doc mformatspec mwriterOpts -> unPandocLua $ do
let writerOpts = fromMaybe def mwriterOpts
let formatSpec = fromMaybe "html" mformatspec
formatSpec <- parseFlavoredFormat $ fromMaybe "html" mformatspec
getWriter formatSpec >>= \case
(TextWriter w, es) -> Right <$>
w writerOpts{ writerExtensions = es } doc
+3 -3
View File
@@ -264,13 +264,13 @@ server = convertBytes
modifyPureState $ \st -> st{ stFiles = filetree }
let opts = options params
let readerFormat = fromMaybe "markdown" $ optFrom opts
let writerFormat = fromMaybe "html" $ optTo opts
readerFormat <- parseFlavoredFormat <$> fromMaybe "markdown" $ optFrom opts
writerFormat <- parseFlavoredFormat <$> fromMaybe "html" $ optTo opts
(readerSpec, readerExts) <- getReader readerFormat
(writerSpec, writerExts) <- getWriter writerFormat
let isStandalone = optStandalone opts
toformat <- formatName <$> parseFlavoredFormat writerFormat
let toformat = formatName writerFormat
hlStyle <- traverse (lookupHighlightingStyle . T.unpack)
$ optHighlightStyle opts
+3 -3
View File
@@ -149,7 +149,7 @@ convertWithOpts' scriptingEngine istty datadir opts = do
(map (T.pack . takeExtension) sources) "markdown"
return "markdown"
Format.FlavoredFormat readerNameBase _extsDiff <-
flvrd@(Format.FlavoredFormat readerNameBase _extsDiff) <-
Format.parseFlavoredFormat readerName
let makeSandboxed pureReader =
let files = maybe id (:) (optReferenceDoc opts) .
@@ -174,10 +174,10 @@ convertWithOpts' scriptingEngine istty datadir opts = do
, mempty
)
else if optSandbox opts
then case runPure (getReader readerName) of
then case runPure (getReader flvrd) of
Left e -> throwError e
Right (r, rexts) -> return (makeSandboxed r, rexts)
else getReader readerName
else getReader flvrd
outputSettings <- optToOutputSettings scriptingEngine opts
let format = outputFormat outputSettings
+4 -3
View File
@@ -102,17 +102,18 @@ optToOutputSettings scriptingEngine opts = do
ByteStringWriter w ->
ByteStringWriter $ \o d -> sandbox files (w o d)
Format.FlavoredFormat format _extsDiff <- Format.parseFlavoredFormat writerName
flvrd@(Format.FlavoredFormat format _extsDiff) <-
Format.parseFlavoredFormat writerName
(writer, writerExts) <-
if "lua" `T.isSuffixOf` format
then do
(, mempty) <$> engineWriteCustom scriptingEngine (T.unpack format)
else do
if optSandbox opts
then case runPure (getWriter writerName) of
then case runPure (getWriter flvrd) of
Right (w, wexts) -> return (makeSandboxed w, wexts)
Left e -> throwError e
else getWriter writerName
else getWriter flvrd
let standalone = optStandalone opts || not (isTextFormat format) || pdfOutput
+4 -5
View File
@@ -163,14 +163,13 @@ readers = [("native" , TextReader readNative)
]
-- | Retrieve reader, extensions based on format spec (format+extensions).
getReader :: PandocMonad m => Text -> m (Reader m, Extensions)
getReader s = do
spec <- Format.parseFlavoredFormat s
let readerName = Format.formatName spec
getReader :: PandocMonad m => Format.FlavoredFormat -> m (Reader m, Extensions)
getReader flvrd = do
let readerName = Format.formatName flvrd
case lookup readerName readers of
Nothing -> throwError $ PandocUnknownReaderError readerName
Just r -> (r,) <$>
Format.applyExtensionsDiff (Format.getExtensionsConfig readerName) spec
Format.applyExtensionsDiff (Format.getExtensionsConfig readerName) flvrd
-- | Read pandoc document from JSON format.
readJSON :: (PandocMonad m, ToSources a)
+4 -5
View File
@@ -192,14 +192,13 @@ writers = [
]
-- | Retrieve writer, extensions based on formatSpec (format+extensions).
getWriter :: PandocMonad m => Text -> m (Writer m, Extensions)
getWriter s = do
spec <- Format.parseFlavoredFormat s
let writerName = Format.formatName spec
getWriter :: PandocMonad m => Format.FlavoredFormat -> m (Writer m, Extensions)
getWriter flvrd = do
let writerName = Format.formatName flvrd
case lookup writerName writers of
Nothing -> throwError $ PandocUnknownWriterError writerName
Just w -> (w,) <$>
Format.applyExtensionsDiff (Format.getExtensionsConfig writerName) spec
Format.applyExtensionsDiff (Format.getExtensionsConfig writerName) flvrd
writeJSON :: PandocMonad m => WriterOptions -> Pandoc -> m Text
writeJSON _ = return . UTF8.toText . BL.toStrict . encode