diff options
author | John MacFarlane <jgm@berkeley.edu> | 2016-11-21 15:32:27 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2016-11-21 15:32:27 +0100 |
commit | ac6dfe0b4efb601f24e444ac8a4059c4103881ef (patch) | |
tree | 6eb0a12af38f845bb85acaf7793276544ec53e71 /pandoc.hs | |
parent | 8d7ecc27a19facf6c4b50a65ee1029c105aacdb2 (diff) |
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`.
Diffstat (limited to 'pandoc.hs')
-rw-r--r-- | pandoc.hs | 27 |
1 files changed, 15 insertions, 12 deletions
@@ -1111,19 +1111,22 @@ adjustMetadata metadata d = return $ M.foldWithKey setMeta d metadata applyTransforms :: [Transform] -> Pandoc -> IO Pandoc applyTransforms transforms d = return $ foldr ($) d transforms - -- First we check to see if a filter is a path. If it isn't, we - -- check to see whether it's in `userdir/filters`. If not, we leave - -- it unchanged. + -- First we check to see if a filter is found. If not, and if it's + -- not an absolute path, we check to see whether it's in `userdir/filters`. + -- If not, we leave it unchanged. expandFilterPath :: Maybe FilePath -> FilePath -> IO FilePath -expandFilterPath mbDatadir fp - | '/' `elem` fp = return fp - | Just datadir <- mbDatadir = do - let filterPath = (datadir </> "filters" </> fp) - filterPathExists <- doesFileExist filterPath - if filterPathExists - then return filterPath - else return fp - | otherwise = return fp +expandFilterPath mbDatadir fp = do + fpExists <- doesFileExist fp + if fpExists + then return fp + else case mbDatadir of + Just datadir | isRelative fp -> do + let filterPath = (datadir </> "filters" </> fp) + filterPathExists <- doesFileExist filterPath + if filterPathExists + then return filterPath + else return fp + _ -> return fp applyFilters :: Maybe FilePath -> [FilePath] -> [String] -> Pandoc -> IO Pandoc applyFilters mbDatadir filters args d = do |