diff options
author | Jesse Rosenthal <jrosenthal@jhu.edu> | 2016-11-18 09:41:36 -0500 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-01-25 17:07:39 +0100 |
commit | 30cfda7a71cd8397dc8d19c9b53bed39d5c1afa1 (patch) | |
tree | 47ff3f123730b25bd09ad302e57a079ad8f6ba10 | |
parent | d97fb5f3c600e9171bb80a7dde358282580da9ea (diff) | |
download | pandoc-30cfda7a71cd8397dc8d19c9b53bed39d5c1afa1.tar.gz |
Continue refactoring FB2 writer.
-rw-r--r-- | src/Text/Pandoc/Writers/FB2.hs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Writers/FB2.hs b/src/Text/Pandoc/Writers/FB2.hs index 70044bd96..41ad9bb2d 100644 --- a/src/Text/Pandoc/Writers/FB2.hs +++ b/src/Text/Pandoc/Writers/FB2.hs @@ -76,8 +76,13 @@ instance Show ImageMode where writeFB2 :: WriterOptions -- ^ conversion options -> Pandoc -- ^ document to convert -> IO String -- ^ FictionBook2 document (not encoded yet) -writeFB2 opts (Pandoc meta blocks) = flip evalStateT newFB $ do - modify (\s -> s { writerOptions = opts }) +writeFB2 opts doc = flip evalStateT newFB $ pandocToFB2 opts doc + +pandocToFB2 :: WriterOptions + -> Pandoc + -> FBM String +pandocToFB2 opts (Pandoc meta blocks) = do + modify (\s -> s { writerOptions = opts { writerOptions = opts } }) desc <- description meta fp <- frontpage meta secs <- renderSections 1 blocks @@ -95,7 +100,6 @@ writeFB2 opts (Pandoc meta blocks) = flip evalStateT newFB $ do in [ uattr "xmlns" xmlns , attr ("xmlns", "l") xlink ] - frontpage :: Meta -> FBM [Content] frontpage meta' = do t <- cMapM toXml . docTitle $ meta' @@ -250,11 +254,13 @@ fetchImage href link = do , uattr "content-type" imgtype] , txt imgdata ) _ -> return (Left ('#':href)) - where - nothingOnError :: (IO B.ByteString) -> (IO (Maybe B.ByteString)) - nothingOnError action = liftM Just action `E.catch` omnihandler - omnihandler :: E.SomeException -> IO (Maybe B.ByteString) - omnihandler _ = return Nothing + + +nothingOnError :: (IO B.ByteString) -> (IO (Maybe B.ByteString)) +nothingOnError action = liftM Just action `E.catch` omnihandler + +omnihandler :: E.SomeException -> IO (Maybe B.ByteString) +omnihandler _ = return Nothing -- | Extract mime type and encoded data from the Data URI. readDataURI :: String -- ^ URI |