diff options
author | Hubert Plociniczak <hubert.plociniczak@gmail.com> | 2016-10-12 17:42:30 +0200 |
---|---|---|
committer | Hubert Plociniczak <hubert.plociniczak@gmail.com> | 2016-10-12 17:50:35 +0200 |
commit | c924611de526601f64154bef83035f75e8f4c334 (patch) | |
tree | f665c276c4683f018e06357b0efe34ff43450c6b /src/Text/Pandoc/Readers/Odt.hs | |
parent | cbeb72d06b4eb3718479eba5257a33a385f642fe (diff) | |
download | pandoc-c924611de526601f64154bef83035f75e8f4c334.tar.gz |
Basic support for images in ODT documents
Highly influenced by the docx support, refactored
some code to avoid DRY.
Diffstat (limited to 'src/Text/Pandoc/Readers/Odt.hs')
-rw-r--r-- | src/Text/Pandoc/Readers/Odt.hs | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/src/Text/Pandoc/Readers/Odt.hs b/src/Text/Pandoc/Readers/Odt.hs index 68e89263c..046fb4d6d 100644 --- a/src/Text/Pandoc/Readers/Odt.hs +++ b/src/Text/Pandoc/Readers/Odt.hs @@ -37,6 +37,8 @@ import qualified Text.XML.Light as XML import qualified Data.ByteString.Lazy as B +import System.FilePath + import Text.Pandoc.Definition import Text.Pandoc.Error import Text.Pandoc.Options @@ -48,39 +50,49 @@ import Text.Pandoc.Readers.Odt.StyleReader import Text.Pandoc.Readers.Odt.Generic.XMLConverter import Text.Pandoc.Readers.Odt.Generic.Fallible +import Text.Pandoc.Shared (filteredFilesFromArchive) -- readOdt :: ReaderOptions -> B.ByteString -> Either PandocError (Pandoc, MediaBag) -readOdt _ bytes = case bytesToOdt bytes of - Right pandoc -> Right (pandoc , mempty) - Left err -> Left err +readOdt _ bytes = bytesToOdt bytes-- of +-- Right (pandoc, mediaBag) -> Right (pandoc , mediaBag) +-- Left err -> Left err -- -bytesToOdt :: B.ByteString -> Either PandocError Pandoc +bytesToOdt :: B.ByteString -> Either PandocError (Pandoc, MediaBag) bytesToOdt bytes = case toArchiveOrFail bytes of Right archive -> archiveToOdt archive Left _ -> Left $ ParseFailure "Couldn't parse odt file." -- -archiveToOdt :: Archive -> Either PandocError Pandoc +archiveToOdt :: Archive -> Either PandocError (Pandoc, MediaBag) archiveToOdt archive - | Just contentEntry <- findEntryByPath "content.xml" archive - , Just stylesEntry <- findEntryByPath "styles.xml" archive - , Just contentElem <- entryToXmlElem contentEntry - , Just stylesElem <- entryToXmlElem stylesEntry - , Right styles <- chooseMax (readStylesAt stylesElem ) - (readStylesAt contentElem) - , startState <- readerState styles - , Right pandoc <- runConverter' read_body - startState - contentElem - = Right pandoc + | Just contentEntry <- findEntryByPath "content.xml" archive + , Just stylesEntry <- findEntryByPath "styles.xml" archive + , Just contentElem <- entryToXmlElem contentEntry + , Just stylesElem <- entryToXmlElem stylesEntry + , Right styles <- chooseMax (readStylesAt stylesElem ) + (readStylesAt contentElem) + , media <- filteredFilesFromArchive archive filePathIsOdtMedia + , startState <- readerState styles media + , Right pandocWithMedia <- runConverter' read_body + startState + contentElem + + = Right pandocWithMedia | otherwise -- Not very detailed, but I don't think more information would be helpful = Left $ ParseFailure "Couldn't parse odt file." + where + filePathIsOdtMedia :: FilePath -> Bool + filePathIsOdtMedia fp = + let (dir, _) = splitFileName fp + in + (dir == "Pictures/") + -- entryToXmlElem :: Entry -> Maybe XML.Element |