@@ -26,6 +26,7 @@ import Control.Applicative ((<$>))
2626import qualified Data.Set as S
2727import Data.Traversable (traverse)
2828import Text.Pandoc
29+import Text.Pandoc.Error (PandocError (..))
2930
3031
3132--------------------------------------------------------------------------------
@@ -36,17 +37,25 @@ import Hakyll.Web.Pandoc.FileType
3637
3738--------------------------------------------------------------------------------
3839-- | Read a string using pandoc, with the default options
39−readPandoc :: Item String -- ^ String to read
40− -> Item Pandoc -- ^ Resulting document
40+readPandoc
41+ :: Item String -- ^ String to read
42+ -> Compiler (Item Pandoc) -- ^ Resulting document
4143readPandoc = readPandocWith defaultHakyllReaderOptions
4244
4345
4446--------------------------------------------------------------------------------
4547-- | Read a string using pandoc, with the supplied options
46−readPandocWith :: ReaderOptions -- ^ Parser options
47− -> Item String -- ^ String to read
48− -> Item Pandoc -- ^ Resulting document
49−readPandocWith ropt item = fmap (reader ropt (itemFileType item)) item
48+readPandocWith
49+ :: ReaderOptions -- ^ Parser options
50+ -> Item String -- ^ String to read
51+ -> Compiler (Item Pandoc) -- ^ Resulting document
52+readPandocWith ropt item =
53+ case traverse (reader ropt (itemFileType item)) item of
54+ Left (ParseFailure err) -> fail $
55+ "Hakyll.Web.Pandoc.readPandocWith: parse failed: " ++ err
56+ Left (ParsecError _ err) -> fail $
57+ "Hakyll.Web.Pandoc.readPandocWith: parse failed: " ++ show err
58+ Right item' -> return item'
5059 where
5160 reader ro t = case t of
5261 DocBook -> readDocBook ro
@@ -81,15 +90,17 @@ writePandocWith wopt = fmap $ writeHtmlString wopt
8190
8291--------------------------------------------------------------------------------
8392-- | Render the resource using pandoc
84−renderPandoc :: Item String -> Item String
93+renderPandoc :: Item String -> Compiler (Item String)
8594renderPandoc =
8695 renderPandocWith defaultHakyllReaderOptions defaultHakyllWriterOptions
8796
8897
8998--------------------------------------------------------------------------------
9099-- | Render the resource using pandoc
91−renderPandocWith :: ReaderOptions -> WriterOptions -> Item String -> Item String
92−renderPandocWith ropt wopt = writePandocWith wopt . readPandocWith ropt
100+renderPandocWith
101+ :: ReaderOptions -> WriterOptions -> Item String -> Compiler (Item String)
102+renderPandocWith ropt wopt item =
103+ writePandocWith wopt <$> readPandocWith ropt item
93104
94105
95106--------------------------------------------------------------------------------
@@ -128,7 +139,7 @@ pandocCompilerWithTransformM :: ReaderOptions -> WriterOptions
128139 -> Compiler (Item String)
129140pandocCompilerWithTransformM ropt wopt f =
130141 writePandocWith wopt <$>
131− (traverse f =<< readPandocWith ropt <$> getResourceBody)
142+ (traverse f =<< readPandocWith ropt =<< getResourceBody)
132143
133144
134145--------------------------------------------------------------------------------