@@ -81,6 +81,7 @@ module Text.Pandoc.Class ( PandocMonad(..)
8181 , FileTree(..)
8282 , FileInfo(..)
8383 , addToFileTree
84+ , insertInFileTree
8485 , runIO
8586 , runIOorExplode
8687 , runPure
@@ -141,7 +142,7 @@ import qualified System.Environment as IO (lookupEnv)
141142import System.FilePath.Glob (match, compile)
142143import System.Directory (createDirectoryIfMissing, getDirectoryContents,
143144 doesDirectoryExist)
144−import System.FilePath ((</>), (<.>), takeDirectory,
145+import System.FilePath ((</>), (<.>), takeDirectory, makeRelative,
145146 takeExtension, dropExtension, isRelative, normalise)
146147import qualified System.FilePath.Glob as IO (glob)
147148import qualified System.Directory as IO (getModificationTime)
@@ -912,12 +913,13 @@ newtype FileTree = FileTree {unFileTree :: M.Map FilePath FileInfo}
912913 deriving (Monoid)
913914
914915getFileInfo :: FilePath -> FileTree -> Maybe FileInfo
915−getFileInfo fp tree = M.lookup fp $ unFileTree tree
916+getFileInfo fp tree =
917+ M.lookup (makeRelative "." fp) (unFileTree tree)
916918
917919-- | Add the specified file to the FileTree. If file
918920-- is a directory, add its contents recursively.
919921addToFileTree :: FileTree -> FilePath -> IO FileTree
920−addToFileTree (FileTree treemap) fp = do
922+addToFileTree tree fp = do
921923 isdir <- doesDirectoryExist fp
922924 if isdir
923925 then do -- recursively add contents of directories
@@ -925,13 +927,17 @@ addToFileTree (FileTree treemap) fp = do
925927 isSpecial "." = True
926928 isSpecial _ = False
927929 fs <- (map (fp </>) . filter (not . isSpecial)) <$> getDirectoryContents fp
928− foldM addToFileTree (FileTree treemap) fs
930+ foldM addToFileTree tree fs
929931 else do
930932 contents <- B.readFile fp
931933 mtime <- IO.getModificationTime fp
932− return $ FileTree $
933− M.insert fp FileInfo{ infoFileMTime = mtime
934− , infoFileContents = contents } treemap
934+ return $ insertInFileTree fp FileInfo{ infoFileMTime = mtime
935+ , infoFileContents = contents } tree
936+
937+-- | Insert an ersatz file into the 'FileTree'.
938+insertInFileTree :: FilePath -> FileInfo -> FileTree -> FileTree
939+insertInFileTree fp info (FileTree treemap) =
940+ FileTree $ M.insert (makeRelative "." fp) info treemap
935941
936942newtype PandocPure a = PandocPure {
937943 unPandocPure :: ExceptT PandocError