Skip to content

Commit 071e58e

Browse files
committed
PandocMonad: allow nested data files
Data file fallbacks are now also searched in the directory that has the same name as the file minus the extension. For example, a filter with name `frob.lua` will be searched in `$DATADIR/filters/frob.lua` as well as in `$DATADIR/filters/frob/frob.lua`. This allows to place full git repositories in the data directory. Closes: jgm#6635
1 parent f9bbbf6 commit 071e58e

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/Text/Pandoc/Class/PandocMonad.hs

+13-10
Original file line numberDiff line numberDiff line change
@@ -417,16 +417,19 @@ findFileWithDataFallback subdir fp = do
417417
existsInWorkingDir <- fileExists fp
418418
if existsInWorkingDir
419419
then return $ Just fp
420-
else do
421-
mbDataDir <- checkUserDataDir fp
422-
case mbDataDir of
423-
Nothing -> return Nothing
424-
Just datadir -> do
425-
let datafp = datadir </> subdir </> fp
426-
existsInDataDir <- fileExists datafp
427-
return $ if existsInDataDir
428-
then Just datafp
429-
else Nothing
420+
else checkUserDataDir fp >>= findInDataDir
421+
where
422+
findInDataDir Nothing = pure Nothing
423+
findInDataDir (Just datadir) = do
424+
let datafp = datadir </> subdir </> fp
425+
let nested = datadir </> subdir </> dropExtension fp </> fp
426+
existsInDataDir <- fileExists datafp
427+
nestedInDataDir <- fileExists nested
428+
return $
429+
case () of
430+
_ | existsInDataDir -> Just datafp
431+
_ | nestedInDataDir -> Just nested
432+
_ -> Nothing
430433

431434
-- | Traverse tree, filling media bag for any images that
432435
-- aren't already in the media bag.

0 commit comments

Comments
 (0)