diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-12-28 10:47:09 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-12-28 10:47:09 -0800 |
commit | 60ace79b03e133521f1bdea8bf69f5db22dc5e88 (patch) | |
tree | 1efab7cd180631647dd44b399e765d41d333939e /src/Text/Pandoc/Class.hs | |
parent | 51b7fe85a841272079fb59f23fd711643f18b96f (diff) |
Class: use makeCanonical for normalization in FileTree and data files.
Diffstat (limited to 'src/Text/Pandoc/Class.hs')
-rw-r--r-- | src/Text/Pandoc/Class.hs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs index 487f66793..5ea736539 100644 --- a/src/Text/Pandoc/Class.hs +++ b/src/Text/Pandoc/Class.hs @@ -142,7 +142,7 @@ import qualified System.Environment as IO (lookupEnv) import System.FilePath.Glob (match, compile) import System.Directory (createDirectoryIfMissing, getDirectoryContents, doesDirectoryExist) -import System.FilePath ((</>), (<.>), takeDirectory, makeRelative, +import System.FilePath ((</>), (<.>), takeDirectory, takeExtension, dropExtension, isRelative, normalise) import qualified System.FilePath.Glob as IO (glob) import qualified System.Directory as IO (getModificationTime) @@ -621,6 +621,7 @@ getDefaultReferenceDocx = do "word/document.xml", "word/fontTable.xml", "word/footnotes.xml", + "word/comments.xml", "word/numbering.xml", "word/settings.xml", "word/webSettings.xml", @@ -761,15 +762,17 @@ readDefaultDataFile fname = case lookup (makeCanonical fname) dataFiles of Nothing -> throwError $ PandocCouldNotFindDataFileError fname Just contents -> return contents - where makeCanonical = Posix.joinPath . transformPathParts . splitDirectories - transformPathParts = reverse . foldl go [] - go as "." = as - go (_:as) ".." = as - go as x = x : as #else getDataFileName fname' >>= checkExistence >>= readFileStrict where fname' = if fname == "MANUAL.txt" then fname else "data" </> fname +makeCanonical :: FilePath -> FilePath +makeCanonical = Posix.joinPath . transformPathParts . splitDirectories + where transformPathParts = reverse . foldl go [] + go as "." = as + go (_:as) ".." = as + go as x = x : as + checkExistence :: PandocMonad m => FilePath -> m FilePath checkExistence fn = do exists <- fileExists fn @@ -914,7 +917,7 @@ newtype FileTree = FileTree {unFileTree :: M.Map FilePath FileInfo} getFileInfo :: FilePath -> FileTree -> Maybe FileInfo getFileInfo fp tree = - M.lookup (makeRelative "." fp) (unFileTree tree) + M.lookup (makeCanonical fp) (unFileTree tree) -- | Add the specified file to the FileTree. If file -- is a directory, add its contents recursively. @@ -937,7 +940,7 @@ addToFileTree tree fp = do -- | Insert an ersatz file into the 'FileTree'. insertInFileTree :: FilePath -> FileInfo -> FileTree -> FileTree insertInFileTree fp info (FileTree treemap) = - FileTree $ M.insert (makeRelative "." fp) info treemap + FileTree $ M.insert (makeCanonical fp) info treemap newtype PandocPure a = PandocPure { unPandocPure :: ExceptT PandocError |