@@ -1,4 +1,3 @@
1−{-# LANGUAGE PatternGuards #-}
21{-# LANGUAGE OverloadedStrings #-}
32{- |
43 Module : Text.Pandoc.Reader.Odt
@@ -67,29 +66,27 @@ bytesToOdt bytes = case toArchiveOrFail bytes of
6766
6867--
6968archiveToOdt :: Archive -> Either PandocError (Pandoc, MediaBag)
70−archiveToOdt archive
71− | Just contentEntry <- findEntryByPath "content.xml" archive
72− , Just stylesEntry <- findEntryByPath "styles.xml" archive
73− , Just contentElem <- entryToXmlElem contentEntry
74− , Just stylesElem <- entryToXmlElem stylesEntry
75− , Right styles <- chooseMax (readStylesAt stylesElem )
76− (readStylesAt contentElem)
77− , media <- filteredFilesFromArchive archive filePathIsOdtMedia
78− , startState <- readerState styles media
79− , Right pandocWithMedia <- runConverter' read_body
80− startState
81− contentElem
82−
83− = Right pandocWithMedia
84−
85− | otherwise
86− -- Not very detailed, but I don't think more information would be helpful
87− = Left $ PandocParseError "Couldn't parse odt file."
88− where
89− filePathIsOdtMedia :: FilePath -> Bool
69+archiveToOdt archive = either (Left. PandocParseError) Right $ do
70+ let onFailure msg Nothing = Left msg
71+ onFailure _ (Just x) = Right x
72+ contentEntry <- onFailure "Could not find content.xml"
73+ (findEntryByPath "content.xml" archive)
74+ stylesEntry <- onFailure "Could not find styles.xml"
75+ (findEntryByPath "styles.xml" archive)
76+ contentElem <- onFailure "Could not find content element"
77+ (entryToXmlElem contentEntry)
78+ stylesElem <- onFailure "Could not find styles element"
79+ (entryToXmlElem stylesEntry)
80+ styles <- either (\_ -> Left "Could not read styles") Right
81+ (chooseMax (readStylesAt stylesElem ) (readStylesAt contentElem))
82+ let filePathIsOdtMedia :: FilePath -> Bool
9083 filePathIsOdtMedia fp =
9184 let (dir, name) = splitFileName fp
9285 in (dir == "Pictures/") || (dir /= "./" && name == "content.xml")
86+ let media = filteredFilesFromArchive archive filePathIsOdtMedia
87+ let startState = readerState styles media
88+ either (\_ -> Left "Could not convert opendocument") Right
89+ (runConverter' read_body startState contentElem)
9390
9491
9592--