diff options
| author | John MacFarlane <[email protected]> | 2024-10-01 10:15:50 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2024-10-01 10:15:50 -0700 |
| commit | c3eec896ab9ea0c88795972fecb7699fffa4e1ab (patch) | |
| tree | 200131cb56aa7de27d1c82c710575ffb50a81c67 /src | |
| parent | 4f15b03ad264009b54ff078011a54f2df3511f7e (diff) | |
Text.Pandoc.Class: export extractURIData.
[API change]
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Class/PandocMonad.hs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Class/PandocMonad.hs b/src/Text/Pandoc/Class/PandocMonad.hs index fdec5616d..51d017c06 100644 --- a/src/Text/Pandoc/Class/PandocMonad.hs +++ b/src/Text/Pandoc/Class/PandocMonad.hs @@ -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 = |
