module Text.Pandoc.Filter.Path
( expandFilterPath
) where
import Text.Pandoc.Class.PandocMonad (PandocMonad, fileExists, getUserDataDir)
import System.FilePath ((</>), isRelative)
expandFilterPath :: PandocMonad m => FilePath -> m FilePath
expandFilterPath fp = do
mbDatadir <- getUserDataDir
fpExists <- fileExists fp
if fpExists
then return fp
else case mbDatadir of
Just datadir | isRelative fp -> do
let filterPath = datadir </> "filters" </> fp
filterPathExists <- fileExists filterPath
if filterPathExists
then return filterPath
else return fp
_ -> return fp