From fa643ba6d78fd97f0a779840dca32bfea3b296f8 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Mon, 6 Dec 2021 16:55:19 +0100 Subject: Lua: update to latest pandoc-lua-marshal (0.1.1) - `walk` methods are added to `Block` and `Inline` values; the methods are similar to `pandoc.utils.walk_block` and `pandoc.utils.walk_inline`, but apply to filter also to the element itself, and therefore return a list of element instead of a single element. - Functions of name `Doc` are no longer accepted as alternatives for `Pandoc` filter functions. This functionality was undocumented. --- src/Text/Pandoc/Lua/Module/Pandoc.hs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'src/Text/Pandoc/Lua/Module') diff --git a/src/Text/Pandoc/Lua/Module/Pandoc.hs b/src/Text/Pandoc/Lua/Module/Pandoc.hs index e932ca59a..529a28cf8 100644 --- a/src/Text/Pandoc/Lua/Module/Pandoc.hs +++ b/src/Text/Pandoc/Lua/Module/Pandoc.hs @@ -31,20 +31,16 @@ import HsLua.Class.Peekable (PeekError) import System.Exit (ExitCode (..)) import Text.Pandoc.Class.PandocIO (runIO) import Text.Pandoc.Definition -import Text.Pandoc.Lua.Filter (List (..), SingletonsList (..), LuaFilter, - peekLuaFilter, - walkInlines, walkInlineLists, - walkBlocks, walkBlockLists) import Text.Pandoc.Lua.Orphans () import Text.Pandoc.Lua.Marshal.AST +import Text.Pandoc.Lua.Marshal.Filter (peekFilter) import Text.Pandoc.Lua.Marshal.ReaderOptions ( peekReaderOptions - , pushReaderOptions) + , pushReaderOptions) import Text.Pandoc.Lua.Module.Utils (sha1) import Text.Pandoc.Lua.PandocLua (PandocLua, liftPandocLua) import Text.Pandoc.Options (ReaderOptions (readerExtensions)) import Text.Pandoc.Process (pipeProcess) import Text.Pandoc.Readers (Reader (..), getReader) -import Text.Pandoc.Walk (Walkable) import qualified HsLua as Lua import qualified Data.ByteString.Lazy as BL @@ -149,16 +145,6 @@ stringConstants = } in map toField nullaryConstructors -walkElement :: (Walkable (SingletonsList Inline) a, - Walkable (SingletonsList Block) a, - Walkable (List Inline) a, - Walkable (List Block) a) - => a -> LuaFilter -> LuaE PandocError a -walkElement x f = walkInlines f x - >>= walkInlineLists f - >>= walkBlocks f - >>= walkBlockLists f - functions :: [DocumentedFunction PandocError] functions = [ defun "pipe" @@ -206,15 +192,21 @@ functions = , defun "walk_block" ### walkElement <#> parameter peekBlockFuzzy "Block" "block" "element to traverse" - <#> parameter peekLuaFilter "LuaFilter" "filter" "filter functions" + <#> parameter peekFilter "Filter" "lua_filter" "filter functions" =#> functionResult pushBlock "Block" "modified Block" , defun "walk_inline" ### walkElement <#> parameter peekInlineFuzzy "Inline" "inline" "element to traverse" - <#> parameter peekLuaFilter "LuaFilter" "filter" "filter functions" + <#> parameter peekFilter "Filter" "lua_filter" "filter functions" =#> functionResult pushInline "Inline" "modified Inline" ] + where + walkElement x f = + walkInlineSplicing f x + >>= walkInlinesStraight f + >>= walkBlockSplicing f + >>= walkBlocksStraight f data PipeError = PipeError { pipeErrorCommand :: T.Text -- cgit v1.2.3