From c924611de526601f64154bef83035f75e8f4c334 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 12 Oct 2016 17:42:30 +0200 Subject: Basic support for images in ODT documents Highly influenced by the docx support, refactored some code to avoid DRY. --- src/Text/Pandoc/Shared.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/Text/Pandoc/Shared.hs') diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 04752a194..7e8cd571f 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -67,6 +67,7 @@ module Text.Pandoc.Shared ( Element (..), hierarchicalize, uniqueIdent, + inlineListToIdentifier, isHeaderBlock, headerShift, isTightList, @@ -84,6 +85,7 @@ module Text.Pandoc.Shared ( fetchItem', openURL, collapseFilePath, + filteredFilesFromArchive, -- * Error handling err, warn, @@ -110,6 +112,7 @@ import System.Exit (exitWith, ExitCode(..)) import Data.Char ( toLower, isLower, isUpper, isAlpha, isLetter, isDigit, isSpace ) import Data.List ( find, stripPrefix, intercalate ) +import Data.Maybe (mapMaybe) import Data.Version ( showVersion ) import qualified Data.Map as M import Network.URI ( escapeURIString, nonStrictRelativeTo, @@ -1028,6 +1031,19 @@ collapseFilePath = Posix.joinPath . reverse . foldl go [] . splitDirectories isSingleton _ = Nothing checkPathSeperator = fmap isPathSeparator . isSingleton +-- +-- File selection from the archive +-- +filteredFilesFromArchive :: Archive -> (FilePath -> Bool) -> [(FilePath, BL.ByteString)] +filteredFilesFromArchive zf f = + mapMaybe (fileAndBinary zf) (filter f (filesInArchive zf)) + where + fileAndBinary :: Archive -> FilePath -> Maybe (FilePath, BL.ByteString) + fileAndBinary a fp = + case findEntryByPath fp a of + Just e -> Just (fp, fromEntry e) + Nothing -> Nothing + --- --- Squash blocks into inlines --- -- cgit v1.2.3 From 4417e33ea9d49a2001091adb4d2b19ebdefe5795 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Mon, 17 Oct 2016 16:58:53 +0200 Subject: Use bind function instead of pattern matching --- src/Text/Pandoc/Shared.hs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/Text/Pandoc/Shared.hs') diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 7e8cd571f..0760b49f8 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -1039,10 +1039,7 @@ filteredFilesFromArchive zf f = mapMaybe (fileAndBinary zf) (filter f (filesInArchive zf)) where fileAndBinary :: Archive -> FilePath -> Maybe (FilePath, BL.ByteString) - fileAndBinary a fp = - case findEntryByPath fp a of - Just e -> Just (fp, fromEntry e) - Nothing -> Nothing + fileAndBinary a fp = findEntryByPath fp a >>= \e -> Just (fp, fromEntry e) --- --- Squash blocks into inlines -- cgit v1.2.3