@@ -6,12 +6,8 @@ module Hakyll.Web.Pandoc
66 , readPandocWith
77 , writePandoc
88 , writePandocWith
9−
10− -- * Functions working on pages/compilers
11− , pageReadPandoc
12− , pageReadPandocWith
13− , pageRenderPandoc
14− , pageRenderPandocWith
9+ , renderPandoc
10+ , renderPandocWith
1511
1612 -- * Default options
1713 , defaultHakyllParserState
@@ -20,89 +16,66 @@ module Hakyll.Web.Pandoc
2016
2117
2218--------------------------------------------------------------------------------
23−import Control.Applicative ((<$>))
24−import Data.Maybe (fromMaybe)
2519import Text.Pandoc
2620
2721
2822--------------------------------------------------------------------------------
29−import Hakyll.Core.Compiler
30−import Hakyll.Core.Identifier
31−import Hakyll.Web.Page.Internal
23+import Hakyll.Core.Item
3224import Hakyll.Web.Pandoc.FileType
3325
3426
3527--------------------------------------------------------------------------------
3628-- | Read a string using pandoc, with the default options
37−readPandoc :: FileType -- ^ Determines how parsing happens
38− -> Maybe Identifier -- ^ Optional, for better error messages
39− -> Page -- ^ String to read
40− -> Pandoc -- ^ Resulting document
29+readPandoc :: Item String -- ^ String to read
30+ -> Item Pandoc -- ^ Resulting document
4131readPandoc = readPandocWith defaultHakyllParserState
4232
4333
4434--------------------------------------------------------------------------------
4535-- | Read a string using pandoc, with the supplied options
46−readPandocWith :: ParserState -- ^ Parser options
47− -> FileType -- ^ Determines parsing method
48− -> Maybe Identifier -- ^ Optional, for better error messages
49− -> Page -- ^ String to read
50− -> Pandoc -- ^ Resulting document
51−readPandocWith state fileType' id' = case fileType' of
52− Html -> readHtml state
53− LaTeX -> readLaTeX state
54− LiterateHaskell t ->
55− readPandocWith state {stateLiterateHaskell = True} t id'
56− Markdown -> readMarkdown state
57− Rst -> readRST state
58− Textile -> readTextile state
59− t -> error $
60− "Hakyll.Web.readPandocWith: I don't know how to read a file of the " ++
61− "type " ++ show t ++ fromMaybe "" (fmap ((" for: " ++) . show) id')
36+readPandocWith :: ParserState -- ^ Parser options
37+ -> Item String -- ^ String to read
38+ -> Item Pandoc -- ^ Resulting document
39+readPandocWith state item = fmap (reader state (itemFileType item)) item
40+ where
41+ reader s t = case t of
42+ Html -> readHtml s
43+ LaTeX -> readLaTeX s
44+ LiterateHaskell t' -> reader s {stateLiterateHaskell = True} t'
45+ Markdown -> readMarkdown s
46+ Rst -> readRST s
47+ Textile -> readTextile s
48+ _ -> error $
49+ "Hakyll.Web.readPandocWith: I don't know how to read a file of the " ++
50+ "type " ++ show t ++ " for: " ++ show (itemIdentifier item)
6251
6352
6453--------------------------------------------------------------------------------
6554-- | Write a document (as HTML) using pandoc, with the default options
66−writePandoc :: Pandoc -- ^ Document to write
67− -> Page -- ^ Resulting HTML
55+writePandoc :: Item Pandoc -- ^ Document to write
56+ -> Item String -- ^ Resulting HTML
6857writePandoc = writePandocWith defaultHakyllWriterOptions
6958
7059
7160--------------------------------------------------------------------------------
7261-- | Write a document (as HTML) using pandoc, with the supplied options
7362writePandocWith :: WriterOptions -- ^ Writer options for pandoc
74− -> Pandoc -- ^ Document to write
75− -> Page -- ^ Resulting HTML
76−writePandocWith = writeHtmlString
77−
78−
79−--------------------------------------------------------------------------------
80−-- | Read the resource using pandoc
81−pageReadPandoc :: Page -> Compiler Pandoc
82−pageReadPandoc = pageReadPandocWith defaultHakyllParserState
83−
84−
85−--------------------------------------------------------------------------------
86−-- | Read the resource using pandoc
87−pageReadPandocWith :: ParserState -> Page -> Compiler Pandoc
88−pageReadPandocWith state page = do
89− identifier <- getIdentifier
90− fileType' <- getFileType
91− return $ readPandocWith state fileType' (Just identifier) page
63+ -> Item Pandoc -- ^ Document to write
64+ -> Item String -- ^ Resulting HTML
65+writePandocWith options = fmap $ writeHtmlString options
9266
9367
9468--------------------------------------------------------------------------------
9569-- | Render the resource using pandoc
96−pageRenderPandoc :: Page -> Compiler Page
97−pageRenderPandoc =
98− pageRenderPandocWith defaultHakyllParserState defaultHakyllWriterOptions
70+renderPandoc :: Item String -> Item String
71+renderPandoc =
72+ renderPandocWith defaultHakyllParserState defaultHakyllWriterOptions
9973
10074
10175--------------------------------------------------------------------------------
10276-- | Render the resource using pandoc
103−pageRenderPandocWith :: ParserState -> WriterOptions -> Page -> Compiler Page
104−pageRenderPandocWith state options page =
105− writePandocWith options <$> pageReadPandocWith state page
77+renderPandocWith :: ParserState -> WriterOptions -> Item String -> Item String
78+renderPandocWith state options = writePandocWith options . readPandocWith state
10679
10780
10881--------------------------------------------------------------------------------