diff options
| author | Albert Krewinkel <[email protected]> | 2022-10-05 12:37:30 +0200 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2022-12-16 10:43:01 -0800 |
| commit | a36f12119fe1a0b70a1a3ff65264e94373a490ce (patch) | |
| tree | 224f9932bf6e1c120db568a6a111f69a9146317a /pandoc-lua-engine/src/Text/Pandoc/Lua/Module | |
| parent | db0232fc545913a9ea6e81d84fc5ee4d9cc8a185 (diff) | |
Lua: allow table structure as format spec.
This allows to pass structured values as format specifiers to
`pandoc.write` and `pandoc.read`.
Diffstat (limited to 'pandoc-lua-engine/src/Text/Pandoc/Lua/Module')
| -rw-r--r-- | pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs index aaca86b02..9d74f363c 100644 --- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs +++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs @@ -32,6 +32,7 @@ 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.Format (peekFlavoredFormat) import Text.Pandoc.Lua.Marshal.Filter (peekFilter) import Text.Pandoc.Lua.Marshal.ReaderOptions ( peekReaderOptions , pushReaderOptions) @@ -200,9 +201,9 @@ functions = , defun "read" ### (\content mformatspec mreaderOptions -> unPandocLua $ do + flvrd <- maybe (parseFlavoredFormat "markdown") pure mformatspec let readerOpts = fromMaybe def mreaderOptions - formatSpec <- parseFlavoredFormat $ fromMaybe "markdown" mformatspec - getReader formatSpec >>= \case + getReader flvrd >>= \case (TextReader r, es) -> r readerOpts{readerExtensions = es} (case content of @@ -217,7 +218,8 @@ functions = <#> parameter (\idx -> (Left <$> peekByteString idx) <|> (Right <$> peekSources idx)) "string|Sources" "content" "text to parse" - <#> opt (textParam "formatspec" "format and extensions") + <#> opt (parameter peekFlavoredFormat "string|table" + "formatspec" "format and extensions") <#> opt (parameter peekReaderOptions "ReaderOptions" "reader_options" "reader options") =#> functionResult pushPandoc "Pandoc" "result document" @@ -238,15 +240,16 @@ functions = , defun "write" ### (\doc mformatspec mwriterOpts -> unPandocLua $ do + flvrd <- maybe (parseFlavoredFormat "markdown") pure mformatspec let writerOpts = fromMaybe def mwriterOpts - formatSpec <- parseFlavoredFormat $ fromMaybe "html" mformatspec - getWriter formatSpec >>= \case + getWriter flvrd >>= \case (TextWriter w, es) -> Right <$> w writerOpts{ writerExtensions = es } doc (ByteStringWriter w, es) -> Left <$> w writerOpts{ writerExtensions = es } doc) <#> parameter peekPandoc "Pandoc" "doc" "document to convert" - <#> opt (textParam "formatspec" "format and extensions") + <#> opt (parameter peekFlavoredFormat "string|table" + "formatspec" "format and extensions") <#> opt (parameter peekWriterOptions "WriterOptions" "writer_options" "writer options") =#> functionResult (either pushLazyByteString pushText) "string" |
