@@ -1,5 +1,5 @@
11-- | A module for dealing with @Page@s. This module is mostly internally used.
2−module Text.Hakyll.Internal.Page
2+module Text.Hakyll.Internal.Page
33 ( readPage
44 ) where
55
@@ -20,28 +20,15 @@ import Text.Hakyll.Util (trim)
2020import Text.Hakyll.Internal.Cache
2121import Text.Hakyll.Internal.FileType
2222
23−-- | The default reader options for pandoc parsing.
24−readerOptions :: ParserState
25−readerOptions = defaultParserState
26− { -- The following option causes pandoc to read smart typography, a nice
27− -- and free bonus.
28− stateSmart = True
29− }
30−
31−-- | The default writer options for pandoc rendering.
32−writerOptions :: WriterOptions
33−writerOptions = defaultWriterOptions
34− { -- This option causes literate haskell to be written using '>' marks in
35− -- html, which I think is a good default.
36− writerLiterateHaskell = True
37− }
38−
3923-- | Get a render function for a given extension.
40−getRenderFunction :: FileType -> (String -> String)
41−getRenderFunction Html = id
42−getRenderFunction Text = id
43−getRenderFunction fileType = writeHtmlString writerOptions
44− . readFunction fileType (readOptions fileType)
24+getRenderFunction :: FileType -> Hakyll (String -> String)
25+getRenderFunction Html = return id
26+getRenderFunction Text = return id
27+getRenderFunction fileType = do
28+ parserState <- askHakyll pandocParserState
29+ writerOptions <- askHakyll pandocWriterOptions
30+ return $ writeHtmlString writerOptions
31+ . readFunction fileType (readOptions parserState fileType)
4532 where
4633 readFunction ReStructuredText = readRST
4734 readFunction LaTeX = readLaTeX
@@ -49,9 +36,9 @@ getRenderFunction fileType = writeHtmlString writerOptions
4936 readFunction LiterateHaskellMarkdown = readMarkdown
5037 readFunction t = error $ "Cannot render " ++ show t
5138
52− readOptions LiterateHaskellMarkdown =
53− readerOptions { stateLiterateHaskell = True }
54− readOptions _ = readerOptions
39+ readOptions options LiterateHaskellMarkdown = options
40+ { stateLiterateHaskell = True }
41+ readOptions options _ = options
5542
5643-- | Split a page into sections.
5744splitAtDelimiters :: [String] -> State (Maybe String) [[String]]
@@ -103,8 +90,8 @@ readSection renderFunction isFirst ls
10390-- has a @.markdown@ extension, it will be rendered using pandoc.
10491readPageFromFile :: FilePath -> Hakyll Context
10592readPageFromFile path = do
106− let renderFunction = getRenderFunction $ getFileType path
107− sectionFunctions = map (readSection renderFunction)
93+ renderFunction <- getRenderFunction $ getFileType path
94+ let sectionFunctions = map (readSection renderFunction)
10895 (True : repeat False)
10996
11097 -- Read file.