Add and apply filters in order (not reversed).
This changes `applyFilters` from Text.Pandoc.Filter so that it does a left fold rather than a right fold, applying the filters in the order listed. [behavior change] The command-line arguments are accumulated in order instead of reverse order. A first step twoards #5881.
This commit is contained in:
parent
adad3c70b6
commit
e299212bf7
3 changed files with 7 additions and 10 deletions
|
@ -85,8 +85,7 @@ convertWithOpts opts = do
|
|||
(optMetadata opts)) &&
|
||||
optCiteMethod opts `notElem` [Natbib, Biblatex] &&
|
||||
all (not . isPandocCiteproc) filters
|
||||
let filters' = if needsCiteproc then JSONFilter "pandoc-citeproc" : filters
|
||||
else filters
|
||||
let filters' = filters ++ [ JSONFilter "pandoc-citeproc" | needsCiteproc ]
|
||||
|
||||
let sources = case optInputFiles opts of
|
||||
[] -> ["-"]
|
||||
|
|
|
@ -436,16 +436,14 @@ options =
|
|||
, Option "F" ["filter"]
|
||||
(ReqArg
|
||||
(\arg opt -> return opt { optFilters =
|
||||
JSONFilter (normalizePath arg) :
|
||||
optFilters opt })
|
||||
optFilters opt ++ [JSONFilter (normalizePath arg)] })
|
||||
"PROGRAM")
|
||||
"" -- "External JSON filter"
|
||||
|
||||
, Option "L" ["lua-filter"]
|
||||
(ReqArg
|
||||
(\arg opt -> return opt { optFilters =
|
||||
LuaFilter (normalizePath arg) :
|
||||
optFilters opt })
|
||||
optFilters opt ++ [LuaFilter (normalizePath arg)] })
|
||||
"SCRIPTPATH")
|
||||
"" -- "Lua filter"
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ module Text.Pandoc.Filter
|
|||
|
||||
import Prelude
|
||||
import Data.Aeson.TH (deriveJSON, defaultOptions)
|
||||
import Data.Foldable (foldrM)
|
||||
import GHC.Generics (Generic)
|
||||
import Text.Pandoc.Class (PandocIO)
|
||||
import Text.Pandoc.Definition (Pandoc)
|
||||
|
@ -33,6 +32,7 @@ import Data.YAML
|
|||
import qualified Data.Text as T
|
||||
import System.FilePath (takeExtension)
|
||||
import Control.Applicative ((<|>))
|
||||
import Control.Monad (foldM)
|
||||
|
||||
-- | Type of filter and path to filter file.
|
||||
data Filter = LuaFilter FilePath
|
||||
|
@ -63,10 +63,10 @@ applyFilters :: ReaderOptions
|
|||
-> PandocIO Pandoc
|
||||
applyFilters ropts filters args d = do
|
||||
expandedFilters <- mapM expandFilterPath filters
|
||||
foldrM ($) d $ map applyFilter expandedFilters
|
||||
foldM applyFilter d expandedFilters
|
||||
where
|
||||
applyFilter (JSONFilter f) = JSONFilter.apply ropts args f
|
||||
applyFilter (LuaFilter f) = LuaFilter.apply ropts args f
|
||||
applyFilter doc (JSONFilter f) = JSONFilter.apply ropts args f doc
|
||||
applyFilter doc (LuaFilter f) = LuaFilter.apply ropts args f doc
|
||||
|
||||
-- | Expand paths of filters, searching the data directory.
|
||||
expandFilterPath :: Filter -> PandocIO Filter
|
||||
|
|
Loading…
Add table
Reference in a new issue