Continue refactoring FB2 writer.

This commit is contained in:
Jesse Rosenthal 2016-11-18 09:41:36 -05:00 committed by John MacFarlane
parent d97fb5f3c6
commit 30cfda7a71

View file

@ -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,9 +254,11 @@ 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