on master help sign in
Expose pandoc options (patch by JD Marble).
commit06aa9fbc7b73bdc3b04bc9bf6ffc224f61198412 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateThu 20 May 2010, 23:54 (16 years ago) parente7d446c
4 files changed+54−40
examples/hakyll/about.markdown+2−1 src/Text/Hakyll.hs+26−6 src/Text/Hakyll/HakyllMonad.hs+12−6 src/Text/Hakyll/Internal/Page.hs+14−27
examples/hakyll/about.markdown+2−1
@@ -26,4 +26,5 @@ you will have to license your code under a GPL-compatible license.
2626## Authors
2727
2828Hakyll was originally written by [Jasper Van der Jeugt](http://jaspervdj.be). It
29−also received contributions from [seschwar](http://github.com/seschwar).
29+also received contributions from [seschwar](http://github.com/seschwar) and
30+[JD Marble](http://github.com/jdmarble/).
src/Text/Hakyll.hs+26−6
@@ -21,19 +21,39 @@ import System.Environment (getArgs, getProgName)
2121import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
2222import System.Time (getClockTime)
2323
24+import Text.Pandoc
25+
2426import Network.Hakyll.SimpleServer (simpleServer)
2527import Text.Hakyll.HakyllMonad
2628import Text.Hakyll.File
2729
30+-- | The default reader options for pandoc parsing.
31+defaultPandocParserState :: ParserState
32+defaultPandocParserState = defaultParserState
33+ { -- The following option causes pandoc to read smart typography, a nice
34+ -- and free bonus.
35+ stateSmart = True
36+ }
37+
38+-- | The default writer options for pandoc rendering.
39+defaultPandocWriterOptions :: WriterOptions
40+defaultPandocWriterOptions = defaultWriterOptions
41+ { -- This option causes literate haskell to be written using '>' marks in
42+ -- html, which I think is a good default.
43+ writerLiterateHaskell = True
44+ }
45+
2846-- | The default hakyll configuration.
2947defaultHakyllConfiguration :: HakyllConfiguration
3048defaultHakyllConfiguration = HakyllConfiguration
31− { absoluteUrl = ""
32− , additionalContext = M.empty
33− , siteDirectory = "_site"
34− , cacheDirectory = "_cache"
35− , enableIndexUrl = False
36− , previewPollDelay = 1000000
49+ { absoluteUrl = ""
50+ , additionalContext = M.empty
51+ , siteDirectory = "_site"
52+ , cacheDirectory = "_cache"
53+ , enableIndexUrl = False
54+ , previewPollDelay = 1000000
55+ , pandocParserState = defaultPandocParserState
56+ , pandocWriterOptions = defaultPandocWriterOptions
3757 }
3858
3959-- | Main function to run Hakyll with the default configuration. The
src/Text/Hakyll/HakyllMonad.hs+12−6
@@ -10,6 +10,8 @@ import Control.Monad.Reader (ReaderT, ask)
1010import Control.Monad (liftM)
1111import qualified Data.Map as M
1212
13+import Text.Pandoc (ParserState, WriterOptions)
14+
1315import Text.Hakyll.Context (Context)
1416
1517-- | Our custom monad stack.
@@ -18,18 +20,22 @@ type Hakyll = ReaderT HakyllConfiguration IO
1820-- | Hakyll global configuration type.
1921data HakyllConfiguration = HakyllConfiguration
2022 { -- | Absolute URL of the site.
21− absoluteUrl :: String
23+ absoluteUrl :: String
2224 , -- | An additional context to use when rendering. This additional context
2325 -- is used globally.
24− additionalContext :: Context
26+ additionalContext :: Context
2527 , -- | Directory where the site is placed.
26− siteDirectory :: FilePath
28+ siteDirectory :: FilePath
2729 , -- | Directory for cache files.
28− cacheDirectory :: FilePath
30+ cacheDirectory :: FilePath
2931 , -- | Enable index links.
30− enableIndexUrl :: Bool
32+ enableIndexUrl :: Bool
3133 , -- | Delay between polls in preview mode.
32− previewPollDelay :: Int
34+ previewPollDelay :: Int
35+ , -- | Pandoc parsing options
36+ pandocParserState :: ParserState
37+ , -- | Pandoc writer options
38+ pandocWriterOptions :: WriterOptions
3339 }
3440
3541-- | Simplified @ask@ function for the Hakyll monad stack.
src/Text/Hakyll/Internal/Page.hs+14−27
@@ -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.