git.iko.soy/typeable/pandoc
on master help sign in
MediaBag: Fixes Windows specific path problems

Changes the internal representation to fix the problem. I haven't tested this on windows. Closes #1597

commit56e4ecab20613d86a6660547ed87e7ff4b80d632 authormpickering <matthewtpickering@gmail.com> dateThu 25 Sep 2014, 12:19 (12 years ago) parent0fbe7df
1 file changed+5−5
src/Text/Pandoc/MediaBag.hs+5−5
src/Text/Pandoc/MediaBag.hs+5−5
@@ -51,7 +51,7 @@ import System.IO (stderr)
5151-- mime types. Note that a 'MediaBag' is a Monoid, so 'mempty'
5252-- can be used for an empty 'MediaBag', and '<>' can be used to append
5353-- two 'MediaBag's.
54−newtype MediaBag = MediaBag (M.Map String (MimeType, BL.ByteString))
54+newtype MediaBag = MediaBag (M.Map [String] (MimeType, BL.ByteString))
5555 deriving (Monoid)
5656
5757instance Show MediaBag where
@@ -65,7 +65,7 @@ insertMedia :: FilePath -- ^ relative path and canonical name of resource
6565 -> MediaBag
6666 -> MediaBag
6767insertMedia fp mbMime contents (MediaBag mediamap) =
68− MediaBag (M.insert fp (mime, contents) mediamap)
68+ MediaBag (M.insert (splitPath fp) (mime, contents) mediamap)
6969 where mime = fromMaybe fallback mbMime
7070 fallback = case takeExtension fp of
7171 ".gz" -> getMimeTypeDef $ dropExtension fp
@@ -75,14 +75,14 @@ insertMedia fp mbMime contents (MediaBag mediamap) =
7575lookupMedia :: FilePath
7676 -> MediaBag
7777 -> Maybe (MimeType, BL.ByteString)
78−lookupMedia fp (MediaBag mediamap) = M.lookup fp mediamap
78+lookupMedia fp (MediaBag mediamap) = M.lookup (splitPath fp) mediamap
7979
8080-- | Get a list of the file paths stored in a 'MediaBag', with
8181-- their corresponding mime types and the lengths in bytes of the contents.
8282mediaDirectory :: MediaBag -> [(String, MimeType, Int)]
8383mediaDirectory (MediaBag mediamap) =
8484 M.foldWithKey (\fp (mime,contents) ->
85− ((fp, mime, fromIntegral $ BL.length contents):)) [] mediamap
85+ (((joinPath fp), mime, fromIntegral $ BL.length contents):)) [] mediamap
8686
8787-- | Extract contents of MediaBag to a given directory. Print informational
8888-- messages if 'verbose' is true.
@@ -93,7 +93,7 @@ extractMediaBag :: Bool
9393extractMediaBag verbose dir (MediaBag mediamap) = do
9494 sequence_ $ M.foldWithKey
9595 (\fp (_ ,contents) ->
96− ((writeMedia verbose dir (fp, contents)):)) [] mediamap
96+ ((writeMedia verbose dir (joinPath fp, contents)):)) [] mediamap
9797
9898writeMedia :: Bool -> FilePath -> (FilePath, BL.ByteString) -> IO ()
9999writeMedia verbose dir (subpath, bs) = do