git.iko.soy/typeable/pandoc
on master help sign in
Changed resolution of filter paths.

- We now first treat the argument of `--filter` as a full (absolute or relative) path, looking for a program there. If it's found, we run it. - If not, and if it is a simple program name or a relative path, we try resolving it relative to `$DATADIR/filters`. - If this fails, then we treat it as a program name and look in the user's PATH. Previously if you did `--filter foo` and you had `foo` in your path and also an executable `foo` in your working directory, the one in the path would be used. Now the one in the working directory is used. In addition, when you do `--filter foo/bar.hs`, pandoc will now find a filter `$DATADIR/filters/foo/bar.hs` -- assuming there isn't a `foo/bar.hs` relative to the working directory. @jkr note the slight revision of what we had before. This was motivated by the idea that one might clone filter repositories into the filters subdirectory; it is nice to be able to run them as `reponame/filtername`.

commitac6dfe0b4efb601f24e444ac8a4059c4103881ef authorJohn MacFarlane <jgm@berkeley.edu> dateMon 21 Nov 2016, 15:32 (10 years ago) parent8d7ecc2
2 files changed+16−19
MANUAL.txt+1−7 pandoc.hs+15−12
MANUAL.txt+1−7
@@ -426,7 +426,7 @@ Reader options
426426 footnotes and links will not work across files. Reading binary
427427 files (docx, odt, epub) implies `--file-scope`.
428428
429−`--filter=`*EXECUTABLE*
429+`--filter=`*PROGRAM*
430430
431431: Specify an executable to be used as a filter transforming the
432432 pandoc AST after the input is parsed and before the output is
@@ -450,12 +450,6 @@ Reader options
450450 pandoc filter libraries in [PHP], [perl], and
451451 [javascript/node.js].
452452
453− If no directory is provided pandoc will look for executable or
454− non-executable filters in the director `$DATADIR/filters`, and
455− then for executable filters in the user's `PATH`. If you want to
456− run a script in the working directory, preface the filename with
457− `./`.
458−
459453 In order of preference, pandoc will look for filters in
460454
461455 1. a specified full or relative path (executable or
pandoc.hs+15−12
@@ -1111,19 +1111,22 @@ adjustMetadata metadata d = return $ M.foldWithKey setMeta d metadata
11111111applyTransforms :: [Transform] -> Pandoc -> IO Pandoc
11121112applyTransforms transforms d = return $ foldr ($) d transforms
11131113
1114− -- First we check to see if a filter is a path. If it isn't, we
1115− -- check to see whether it's in `userdir/filters`. If not, we leave
1116− -- it unchanged.
1114+ -- First we check to see if a filter is found. If not, and if it's
1115+ -- not an absolute path, we check to see whether it's in `userdir/filters`.
1116+ -- If not, we leave it unchanged.
11171117expandFilterPath :: Maybe FilePath -> FilePath -> IO FilePath
1118−expandFilterPath mbDatadir fp
1119− | '/' `elem` fp = return fp
1120− | Just datadir <- mbDatadir = do
1121− let filterPath = (datadir </> "filters" </> fp)
1122− filterPathExists <- doesFileExist filterPath
1123− if filterPathExists
1124− then return filterPath
1125− else return fp
1126− | otherwise = return fp
1118+expandFilterPath mbDatadir fp = do
1119+ fpExists <- doesFileExist fp
1120+ if fpExists
1121+ then return fp
1122+ else case mbDatadir of
1123+ Just datadir | isRelative fp -> do
1124+ let filterPath = (datadir </> "filters" </> fp)
1125+ filterPathExists <- doesFileExist filterPath
1126+ if filterPathExists
1127+ then return filterPath
1128+ else return fp
1129+ _ -> return fp
11271130
11281131applyFilters :: Maybe FilePath -> [FilePath] -> [String] -> Pandoc -> IO Pandoc
11291132applyFilters mbDatadir filters args d = do