mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-25 17:56:32 +00:00
Text.Pandoc.Class: export extractURIData.
[API change]
This commit is contained in:
@@ -40,6 +40,7 @@ module Text.Pandoc.Class.PandocMonad
|
||||
, setUserDataDir
|
||||
, getUserDataDir
|
||||
, fetchItem
|
||||
, extractURIData
|
||||
, getInputFiles
|
||||
, setInputFiles
|
||||
, getOutputFile
|
||||
@@ -78,6 +79,8 @@ import Text.Pandoc.MediaBag (MediaBag, lookupMedia, MediaItem(..))
|
||||
import Text.Pandoc.Shared (safeRead, makeCanonical, tshow)
|
||||
import Text.Pandoc.URI (uriPathToPath)
|
||||
import Text.Pandoc.Walk (walkM)
|
||||
import qualified Text.Pandoc.UTF8 as UTF8
|
||||
import Data.ByteString.Base64 (decodeLenient)
|
||||
import Text.Parsec (ParsecT, getPosition, sourceLine, sourceName)
|
||||
import qualified Data.ByteString as B
|
||||
import qualified Data.ByteString.Lazy as BL
|
||||
@@ -372,6 +375,16 @@ downloadOrRead s = do
|
||||
convertSlash '\\' = '/'
|
||||
convertSlash x = x
|
||||
|
||||
-- Extract data from a data URI's path component.
|
||||
extractURIData :: String -> (B.ByteString, Maybe MimeType)
|
||||
extractURIData upath =
|
||||
case break (== ';') (filter (/= ' ') mimespec) of
|
||||
(mime', ";base64") -> (decodeLenient contents, Just (T.pack mime'))
|
||||
(mime', _) -> (contents, Just (T.pack mime'))
|
||||
where
|
||||
(mimespec, rest) = break (== ',') $ unEscapeString upath
|
||||
contents = UTF8.fromString $ drop 1 rest
|
||||
|
||||
-- | Checks if the file path is relative to a parent directory.
|
||||
isRelativeToParentDir :: FilePath -> Bool
|
||||
isRelativeToParentDir fname =
|
||||
|
||||
Reference in New Issue
Block a user