on master help sign in
Some better error messages
commit6e207e4793215c14d6dd429b88551173ca948abe authorJasper Van der Jeugt <jaspervdj@gmail.com> dateTue 17 May 2011, 10:46 (15 years ago) parent01fdbd5
1 file changed+15−9
src/Hakyll/Web/Pandoc.hs+15−9
src/Hakyll/Web/Pandoc.hs+15−9
@@ -22,34 +22,40 @@ import Prelude hiding (id)
2222import Control.Applicative ((<$>))
2323import Control.Arrow ((>>^), (&&&))
2424import Control.Category (id)
25+import Data.Maybe (fromMaybe)
2526
2627import Text.Pandoc
2728
2829import Hakyll.Core.Compiler
30+import Hakyll.Core.Identifier
2931import Hakyll.Web.Pandoc.FileType
3032import Hakyll.Web.Page.Internal
3133
3234-- | Read a string using pandoc, with the default options
3335--
3436readPandoc :: FileType -- ^ File type, determines how parsing happens
37+ -> Maybe Identifier -- ^ Optional, for better error messages
3538 -> String -- ^ String to read
3639 -> Pandoc -- ^ Resulting document
3740readPandoc = readPandocWith defaultHakyllParserState
3841
3942-- | Read a string using pandoc, with the supplied options
4043--
41−readPandocWith :: ParserState -- ^ Parser options
42− -> FileType -- ^ File type, determines how parsing happens
43− -> String -- ^ String to read
44− -> Pandoc -- ^ Resulting document
45−readPandocWith state fileType' = case fileType' of
44+readPandocWith :: ParserState -- ^ Parser options
45+ -> FileType -- ^ File type, determines parsing method
46+ -> Maybe Identifier -- ^ Optional, for better error messages
47+ -> String -- ^ String to read
48+ -> Pandoc -- ^ Resulting document
49+readPandocWith state fileType' id' = case fileType' of
4650 Html -> readHtml state
4751 LaTeX -> readLaTeX state
48− LiterateHaskell t -> readPandocWith state {stateLiterateHaskell = True} t
52+ LiterateHaskell t ->
53+ readPandocWith state {stateLiterateHaskell = True} t id'
4954 Markdown -> readMarkdown state
5055 Rst -> readRST state
5156 t -> error $
52− "Hakyll.Web.readPandocWith: I don't know how to read " ++ show t
57+ "Hakyll.Web.readPandocWith: I don't know how to read a file of the " ++
58+ "type " ++ show t ++ fromMaybe "" (fmap ((" for: " ++) . show) id')
5359
5460-- | Write a document (as HTML) using pandoc, with the default options
5561--
@@ -73,9 +79,9 @@ pageReadPandoc = pageReadPandocWith defaultHakyllParserState
7379--
7480pageReadPandocWith :: ParserState -> Compiler (Page String) (Page Pandoc)
7581pageReadPandocWith state =
76− id &&& getFileType >>^ pageReadPandocWith'
82+ id &&& getIdentifier &&& getFileType >>^ pageReadPandocWith'
7783 where
78− pageReadPandocWith' (p, t) = readPandocWith state t <$> p
84+ pageReadPandocWith' (p, (i, t)) = readPandocWith state t (Just i) <$> p
7985
8086-- | Render the resource using pandoc
8187--