git.iko.soy/typeable/pandoc
on master help sign in
Continue refactoring FB2 writer.
commit30cfda7a71cd8397dc8d19c9b53bed39d5c1afa1 authorJesse Rosenthal <jrosenthal@jhu.edu> dateFri 18 Nov 2016, 09:41 (10 years ago) parentd97fb5f
1 file changed+14−8
src/Text/Pandoc/Writers/FB2.hs+14−8
src/Text/Pandoc/Writers/FB2.hs+14−8
@@ -76,8 +76,13 @@ instance Show ImageMode where
7676writeFB2 :: WriterOptions -- ^ conversion options
7777 -> Pandoc -- ^ document to convert
7878 -> IO String -- ^ FictionBook2 document (not encoded yet)
79−writeFB2 opts (Pandoc meta blocks) = flip evalStateT newFB $ do
80− modify (\s -> s { writerOptions = opts })
79+writeFB2 opts doc = flip evalStateT newFB $ pandocToFB2 opts doc
80+
81+pandocToFB2 :: WriterOptions
82+ -> Pandoc
83+ -> FBM String
84+pandocToFB2 opts (Pandoc meta blocks) = do
85+ modify (\s -> s { writerOptions = opts { writerOptions = opts } })
8186 desc <- description meta
8287 fp <- frontpage meta
8388 secs <- renderSections 1 blocks
@@ -95,7 +100,6 @@ writeFB2 opts (Pandoc meta blocks) = flip evalStateT newFB $ do
95100 in [ uattr "xmlns" xmlns
96101 , attr ("xmlns", "l") xlink ]
97102
98−
99103frontpage :: Meta -> FBM [Content]
100104frontpage meta' = do
101105 t <- cMapM toXml . docTitle $ meta'
@@ -250,11 +254,13 @@ fetchImage href link = do
250254 , uattr "content-type" imgtype]
251255 , txt imgdata )
252256 _ -> return (Left ('#':href))
253− where
254− nothingOnError :: (IO B.ByteString) -> (IO (Maybe B.ByteString))
255− nothingOnError action = liftM Just action `E.catch` omnihandler
256− omnihandler :: E.SomeException -> IO (Maybe B.ByteString)
257− omnihandler _ = return Nothing
257+
258+
259+nothingOnError :: (IO B.ByteString) -> (IO (Maybe B.ByteString))
260+nothingOnError action = liftM Just action `E.catch` omnihandler
261+
262+omnihandler :: E.SomeException -> IO (Maybe B.ByteString)
263+omnihandler _ = return Nothing
258264
259265-- | Extract mime type and encoded data from the Data URI.
260266readDataURI :: String -- ^ URI