diff options
author | John MacFarlane <jgm@berkeley.edu> | 2019-11-06 15:41:30 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-11-06 15:42:41 -0800 |
commit | e299212bf766cdbeec43be90f634038ab4a727c1 (patch) | |
tree | ddf01436166c6bd313719a8009eb2639108e360f /src/Text | |
parent | adad3c70b6d68563f2dad5136705fcaa33d719ea (diff) | |
download | pandoc-e299212bf766cdbeec43be90f634038ab4a727c1.tar.gz |
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.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/App.hs | 3 | ||||
-rw-r--r-- | src/Text/Pandoc/App/CommandLineOptions.hs | 6 | ||||
-rw-r--r-- | src/Text/Pandoc/Filter.hs | 8 |
3 files changed, 7 insertions, 10 deletions
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs index db9d029ac..79346855f 100644 --- a/src/Text/Pandoc/App.hs +++ b/src/Text/Pandoc/App.hs @@ -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 [] -> ["-"] diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs index 848f9fba5..7692cfac9 100644 --- a/src/Text/Pandoc/App/CommandLineOptions.hs +++ b/src/Text/Pandoc/App/CommandLineOptions.hs @@ -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" diff --git a/src/Text/Pandoc/Filter.hs b/src/Text/Pandoc/Filter.hs index 5670d028e..adea0d5e2 100644 --- a/src/Text/Pandoc/Filter.hs +++ b/src/Text/Pandoc/Filter.hs @@ -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 |