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 writeFB2 :: WriterOptions -- ^ conversion options
-> Pandoc -- ^ document to convert -> Pandoc -- ^ document to convert
-> IO String -- ^ FictionBook2 document (not encoded yet) -> IO String -- ^ FictionBook2 document (not encoded yet)
writeFB2 opts (Pandoc meta blocks) = flip evalStateT newFB $ do writeFB2 opts doc = flip evalStateT newFB $ pandocToFB2 opts doc
modify (\s -> s { writerOptions = opts })
pandocToFB2 :: WriterOptions
-> Pandoc
-> FBM String
pandocToFB2 opts (Pandoc meta blocks) = do
modify (\s -> s { writerOptions = opts { writerOptions = opts } })
desc <- description meta desc <- description meta
fp <- frontpage meta fp <- frontpage meta
secs <- renderSections 1 blocks secs <- renderSections 1 blocks
@ -95,7 +100,6 @@ writeFB2 opts (Pandoc meta blocks) = flip evalStateT newFB $ do
in [ uattr "xmlns" xmlns in [ uattr "xmlns" xmlns
, attr ("xmlns", "l") xlink ] , attr ("xmlns", "l") xlink ]
frontpage :: Meta -> FBM [Content] frontpage :: Meta -> FBM [Content]
frontpage meta' = do frontpage meta' = do
t <- cMapM toXml . docTitle $ meta' t <- cMapM toXml . docTitle $ meta'
@ -250,11 +254,13 @@ fetchImage href link = do
, uattr "content-type" imgtype] , uattr "content-type" imgtype]
, txt imgdata ) , txt imgdata )
_ -> return (Left ('#':href)) _ -> return (Left ('#':href))
where
nothingOnError :: (IO B.ByteString) -> (IO (Maybe B.ByteString))
nothingOnError action = liftM Just action `E.catch` omnihandler nothingOnError :: (IO B.ByteString) -> (IO (Maybe B.ByteString))
omnihandler :: E.SomeException -> IO (Maybe B.ByteString) nothingOnError action = liftM Just action `E.catch` omnihandler
omnihandler _ = return Nothing
omnihandler :: E.SomeException -> IO (Maybe B.ByteString)
omnihandler _ = return Nothing
-- | Extract mime type and encoded data from the Data URI. -- | Extract mime type and encoded data from the Data URI.
readDataURI :: String -- ^ URI readDataURI :: String -- ^ URI