@@ -26,6 +26,7 @@ import Control.Applicative ((<$>))
26import qualified Data.Set as S
26import qualified Data.Set as S
27import Data.Traversable (traverse)
27import Data.Traversable (traverse)
28import Text.Pandoc
28import Text.Pandoc
29+import Text.Pandoc.Error (PandocError (..))
31--------------------------------------------------------------------------------
32--------------------------------------------------------------------------------
@@ -36,17 +37,25 @@ import Hakyll.Web.Pandoc.FileType
37--------------------------------------------------------------------------------
38--------------------------------------------------------------------------------
38-- | Read a string using pandoc, with the default options
39-- | Read a string using pandoc, with the default options
39−readPandoc :: Item String -- ^ String to read
41+ :: Item String -- ^ String to read
40− -> Item Pandoc -- ^ Resulting document
42+ -> Compiler (Item Pandoc) -- ^ Resulting document
41readPandoc = readPandocWith defaultHakyllReaderOptions
43readPandoc = readPandocWith defaultHakyllReaderOptions
44--------------------------------------------------------------------------------
46--------------------------------------------------------------------------------
45-- | Read a string using pandoc, with the supplied options
47-- | Read a string using pandoc, with the supplied options
46−readPandocWith :: ReaderOptions -- ^ Parser options
49+ :: ReaderOptions -- ^ Parser options
47− -> Item String -- ^ String to read
50+ -> Item String -- ^ String to read
48− -> Item Pandoc -- ^ Resulting document
51+ -> Compiler (Item Pandoc) -- ^ Resulting document
52+readPandocWith ropt item =
49−readPandocWith ropt item = fmap (reader ropt (itemFileType item)) 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'
51 reader ro t = case t of
60 reader ro t = case t of
52 DocBook -> readDocBook ro
61 DocBook -> readDocBook ro
@@ -81,15 +90,17 @@ writePandocWith wopt = fmap $ writeHtmlString wopt
82--------------------------------------------------------------------------------
91--------------------------------------------------------------------------------
83-- | Render the resource using pandoc
92-- | Render the resource using pandoc
84−renderPandoc :: Item String -> Item String
93+renderPandoc :: Item String -> Compiler (Item String)
85renderPandoc =
94renderPandoc =
86 renderPandocWith defaultHakyllReaderOptions defaultHakyllWriterOptions
95 renderPandocWith defaultHakyllReaderOptions defaultHakyllWriterOptions
89--------------------------------------------------------------------------------
98--------------------------------------------------------------------------------
90-- | Render the resource using pandoc
99-- | Render the resource using pandoc
91−renderPandocWith :: ReaderOptions -> WriterOptions -> Item String -> Item String
101+ :: ReaderOptions -> WriterOptions -> Item String -> Compiler (Item String)
102+renderPandocWith ropt wopt item =
92−renderPandocWith ropt wopt = writePandocWith wopt . readPandocWith ropt
103+ writePandocWith wopt <$> readPandocWith ropt item
95--------------------------------------------------------------------------------
106--------------------------------------------------------------------------------
@@ -128,7 +139,7 @@ pandocCompilerWithTransformM :: ReaderOptions -> WriterOptions
128 -> Compiler (Item String)
139 -> Compiler (Item String)
129pandocCompilerWithTransformM ropt wopt f =
140pandocCompilerWithTransformM ropt wopt f =
130 writePandocWith wopt <$>
141 writePandocWith wopt <$>
131− (traverse f =<< readPandocWith ropt <$> getResourceBody)
142+ (traverse f =<< readPandocWith ropt =<< getResourceBody)
134--------------------------------------------------------------------------------
145--------------------------------------------------------------------------------