@@ -81,6 +81,7 @@ module Text.Pandoc.Class ( PandocMonad(..)
81 , FileTree(..)
81 , FileTree(..)
82 , FileInfo(..)
82 , FileInfo(..)
83 , addToFileTree
83 , addToFileTree
85 , runIOorExplode
86 , runIOorExplode
@@ -141,7 +142,7 @@ import qualified System.Environment as IO (lookupEnv)
141import System.FilePath.Glob (match, compile)
142import System.FilePath.Glob (match, compile)
142import System.Directory (createDirectoryIfMissing, getDirectoryContents,
143import System.Directory (createDirectoryIfMissing, getDirectoryContents,
143 doesDirectoryExist)
144 doesDirectoryExist)
144−import System.FilePath ((</>), (<.>), takeDirectory,
145+import System.FilePath ((</>), (<.>), takeDirectory, makeRelative,
145 takeExtension, dropExtension, isRelative, normalise)
146 takeExtension, dropExtension, isRelative, normalise)
146import qualified System.FilePath.Glob as IO (glob)
147import qualified System.FilePath.Glob as IO (glob)
147import qualified System.Directory as IO (getModificationTime)
148import qualified System.Directory as IO (getModificationTime)
@@ -912,12 +913,13 @@ newtype FileTree = FileTree {unFileTree :: M.Map FilePath FileInfo}
912 deriving (Monoid)
913 deriving (Monoid)
914getFileInfo :: FilePath -> FileTree -> Maybe FileInfo
915getFileInfo :: FilePath -> FileTree -> Maybe FileInfo
915−getFileInfo fp tree = M.lookup fp $ unFileTree tree
916+getFileInfo fp tree =
917+ M.lookup (makeRelative "." fp) (unFileTree tree)
917-- | Add the specified file to the FileTree. If file
919-- | Add the specified file to the FileTree. If file
918-- is a directory, add its contents recursively.
920-- is a directory, add its contents recursively.
919addToFileTree :: FileTree -> FilePath -> IO FileTree
921addToFileTree :: FileTree -> FilePath -> IO FileTree
920−addToFileTree (FileTree treemap) fp = do
922+addToFileTree tree fp = do
921 isdir <- doesDirectoryExist fp
923 isdir <- doesDirectoryExist fp
923 then do -- recursively add contents of directories
925 then do -- recursively add contents of directories
@@ -925,13 +927,17 @@ addToFileTree (FileTree treemap) fp = do
925 isSpecial "." = True
927 isSpecial "." = True
926 isSpecial _ = False
928 isSpecial _ = False
927 fs <- (map (fp </>) . filter (not . isSpecial)) <$> getDirectoryContents fp
929 fs <- (map (fp </>) . filter (not . isSpecial)) <$> getDirectoryContents fp
928− foldM addToFileTree (FileTree treemap) fs
930+ foldM addToFileTree tree fs
930 contents <- B.readFile fp
932 contents <- B.readFile fp
931 mtime <- IO.getModificationTime fp
933 mtime <- IO.getModificationTime fp
933− M.insert fp FileInfo{ infoFileMTime = mtime
934+ return $ insertInFileTree fp FileInfo{ infoFileMTime = mtime
934− , infoFileContents = contents } treemap
935+ , infoFileContents = contents } tree
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
936newtype PandocPure a = PandocPure {
942newtype PandocPure a = PandocPure {
937 unPandocPure :: ExceptT PandocError
943 unPandocPure :: ExceptT PandocError