git.iko.soy/typeable/pandoc
on master help sign in
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.

commite299212bf766cdbeec43be90f634038ab4a727c1 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 6 Nov 2019, 15:41 (7 years ago) parentadad3c7
3 files changed+7−10
src/Text/Pandoc/App.hs+1−2 src/Text/Pandoc/App/CommandLineOptions.hs+2−4 src/Text/Pandoc/Filter.hs+4−4
src/Text/Pandoc/App.hs+1−2
@@ -85,8 +85,7 @@ convertWithOpts opts = do
8585 (optMetadata opts)) &&
8686 optCiteMethod opts `notElem` [Natbib, Biblatex] &&
8787 all (not . isPandocCiteproc) filters
88− let filters' = if needsCiteproc then JSONFilter "pandoc-citeproc" : filters
89− else filters
88+ let filters' = filters ++ [ JSONFilter "pandoc-citeproc" | needsCiteproc ]
9089
9190 let sources = case optInputFiles opts of
9291 [] -> ["-"]
src/Text/Pandoc/App/CommandLineOptions.hs+2−4
@@ -436,16 +436,14 @@ options =
436436 , Option "F" ["filter"]
437437 (ReqArg
438438 (\arg opt -> return opt { optFilters =
439− JSONFilter (normalizePath arg) :
440− optFilters opt })
439+ optFilters opt ++ [JSONFilter (normalizePath arg)] })
441440 "PROGRAM")
442441 "" -- "External JSON filter"
443442
444443 , Option "L" ["lua-filter"]
445444 (ReqArg
446445 (\arg opt -> return opt { optFilters =
447− LuaFilter (normalizePath arg) :
448− optFilters opt })
446+ optFilters opt ++ [LuaFilter (normalizePath arg)] })
449447 "SCRIPTPATH")
450448 "" -- "Lua filter"
451449
src/Text/Pandoc/Filter.hs+4−4
@@ -21,7 +21,6 @@ module Text.Pandoc.Filter
2121
2222import Prelude
2323import Data.Aeson.TH (deriveJSON, defaultOptions)
24−import Data.Foldable (foldrM)
2524import GHC.Generics (Generic)
2625import Text.Pandoc.Class (PandocIO)
2726import Text.Pandoc.Definition (Pandoc)
@@ -33,6 +32,7 @@ import Data.YAML
3332import qualified Data.Text as T
3433import System.FilePath (takeExtension)
3534import Control.Applicative ((<|>))
35+import Control.Monad (foldM)
3636
3737-- | Type of filter and path to filter file.
3838data Filter = LuaFilter FilePath
@@ -63,10 +63,10 @@ applyFilters :: ReaderOptions
6363 -> PandocIO Pandoc
6464applyFilters ropts filters args d = do
6565 expandedFilters <- mapM expandFilterPath filters
66− foldrM ($) d $ map applyFilter expandedFilters
66+ foldM applyFilter d expandedFilters
6767 where
68− applyFilter (JSONFilter f) = JSONFilter.apply ropts args f
69− applyFilter (LuaFilter f) = LuaFilter.apply ropts args f
68+ applyFilter doc (JSONFilter f) = JSONFilter.apply ropts args f doc
69+ applyFilter doc (LuaFilter f) = LuaFilter.apply ropts args f doc
7070
7171-- | Expand paths of filters, searching the data directory.
7272expandFilterPath :: Filter -> PandocIO Filter