git.iko.soy/typeable/pandoc
on master help sign in
Continue refactoring FB2 writer.
30cfda7Jesse Rosenthal
src/Text/Pandoc/Writers/FB2.hs+14−8
@@ -76,8 +76,13 @@ instance Show ImageMode where
76writeFB2 :: WriterOptions -- ^ conversion options
76writeFB2 :: WriterOptions -- ^ conversion options
77 -> Pandoc -- ^ document to convert
77 -> Pandoc -- ^ document to convert
78 -> IO String -- ^ FictionBook2 document (not encoded yet)
78 -> IO String -- ^ FictionBook2 document (not encoded yet)
79−writeFB2 opts (Pandoc meta blocks) = flip evalStateT newFB $ do
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
80− modify (\s -> s { writerOptions = opts })
85+ modify (\s -> s { writerOptions = opts { writerOptions = opts } })
81 desc <- description meta
86 desc <- description meta
82 fp <- frontpage meta
87 fp <- frontpage meta
83 secs <- renderSections 1 blocks
88 secs <- renderSections 1 blocks
@@ -95,7 +100,6 @@ writeFB2 opts (Pandoc meta blocks) = flip evalStateT newFB $ do
95 in [ uattr "xmlns" xmlns
100 in [ uattr "xmlns" xmlns
96 , attr ("xmlns", "l") xlink ]
101 , attr ("xmlns", "l") xlink ]
97
102
98−
99frontpage :: Meta -> FBM [Content]
103frontpage :: Meta -> FBM [Content]
100frontpage meta' = do
104frontpage meta' = do
101 t <- cMapM toXml . docTitle $ meta'
105 t <- cMapM toXml . docTitle $ meta'
@@ -250,11 +254,13 @@ fetchImage href link = do
250 , uattr "content-type" imgtype]
254 , uattr "content-type" imgtype]
251 , txt imgdata )
255 , txt imgdata )
252 _ -> return (Left ('#':href))
256 _ -> return (Left ('#':href))
253− where
257+
258+
254− nothingOnError :: (IO B.ByteString) -> (IO (Maybe B.ByteString))
259+nothingOnError :: (IO B.ByteString) -> (IO (Maybe B.ByteString))
255− nothingOnError action = liftM Just action `E.catch` omnihandler
260+nothingOnError action = liftM Just action `E.catch` omnihandler
261+
256− omnihandler :: E.SomeException -> IO (Maybe B.ByteString)
262+omnihandler :: E.SomeException -> IO (Maybe B.ByteString)
257− omnihandler _ = return Nothing
263+omnihandler _ = return Nothing
258
264
259-- | Extract mime type and encoded data from the Data URI.
265-- | Extract mime type and encoded data from the Data URI.
260readDataURI :: String -- ^ URI
266readDataURI :: String -- ^ URI