on master help sign in
Expose pandoc options (patch by JD Marble).
06aa9fbJasper Van der Jeugt
examples/hakyll/about.markdown+2−1
@@ -26,4 +26,5 @@ you will have to license your code under a GPL-compatible license.
26## Authors
26## Authors
27
27
28Hakyll was originally written by [Jasper Van der Jeugt](http://jaspervdj.be). It
28Hakyll 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)
21import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
21import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
22import System.Time (getClockTime)
22import System.Time (getClockTime)
23
23
24+import Text.Pandoc
25+
24import Network.Hakyll.SimpleServer (simpleServer)
26import Network.Hakyll.SimpleServer (simpleServer)
25import Text.Hakyll.HakyllMonad
27import Text.Hakyll.HakyllMonad
26import Text.Hakyll.File
28import Text.Hakyll.File
27
29
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+
28-- | The default hakyll configuration.
46-- | The default hakyll configuration.
29defaultHakyllConfiguration :: HakyllConfiguration
47defaultHakyllConfiguration :: HakyllConfiguration
30defaultHakyllConfiguration = HakyllConfiguration
48defaultHakyllConfiguration = HakyllConfiguration
31− { absoluteUrl = ""
49+ { absoluteUrl = ""
32− , additionalContext = M.empty
50+ , additionalContext = M.empty
33− , siteDirectory = "_site"
51+ , siteDirectory = "_site"
34− , cacheDirectory = "_cache"
52+ , cacheDirectory = "_cache"
35− , enableIndexUrl = False
53+ , enableIndexUrl = False
36− , previewPollDelay = 1000000
54+ , previewPollDelay = 1000000
55+ , pandocParserState = defaultPandocParserState
56+ , pandocWriterOptions = defaultPandocWriterOptions
37 }
57 }
38
58
39-- | Main function to run Hakyll with the default configuration. The
59-- | 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)
10import Control.Monad (liftM)
10import Control.Monad (liftM)
11import qualified Data.Map as M
11import qualified Data.Map as M
12
12
13+import Text.Pandoc (ParserState, WriterOptions)
14+
13import Text.Hakyll.Context (Context)
15import Text.Hakyll.Context (Context)
14
16
15-- | Our custom monad stack.
17-- | Our custom monad stack.
@@ -18,18 +20,22 @@ type Hakyll = ReaderT HakyllConfiguration IO
18-- | Hakyll global configuration type.
20-- | Hakyll global configuration type.
19data HakyllConfiguration = HakyllConfiguration
21data HakyllConfiguration = HakyllConfiguration
20 { -- | Absolute URL of the site.
22 { -- | Absolute URL of the site.
21− absoluteUrl :: String
23+ absoluteUrl :: String
22 , -- | An additional context to use when rendering. This additional context
24 , -- | An additional context to use when rendering. This additional context
23 -- is used globally.
25 -- is used globally.
24− additionalContext :: Context
26+ additionalContext :: Context
25 , -- | Directory where the site is placed.
27 , -- | Directory where the site is placed.
26− siteDirectory :: FilePath
28+ siteDirectory :: FilePath
27 , -- | Directory for cache files.
29 , -- | Directory for cache files.
28− cacheDirectory :: FilePath
30+ cacheDirectory :: FilePath
29 , -- | Enable index links.
31 , -- | Enable index links.
30− enableIndexUrl :: Bool
32+ enableIndexUrl :: Bool
31 , -- | Delay between polls in preview mode.
33 , -- | 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
33 }
39 }
34
40
35-- | Simplified @ask@ function for the Hakyll monad stack.
41-- | Simplified @ask@ function for the Hakyll monad stack.
src/Text/Hakyll/Internal/Page.hs+14−27
@@ -1,5 +1,5 @@
1-- | A module for dealing with @Page@s. This module is mostly internally used.
1-- | 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
3 ( readPage
3 ( readPage
4 ) where
4 ) where
5
5
@@ -20,28 +20,15 @@ import Text.Hakyll.Util (trim)
20import Text.Hakyll.Internal.Cache
20import Text.Hakyll.Internal.Cache
21import Text.Hakyll.Internal.FileType
21import Text.Hakyll.Internal.FileType
22
22
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−
39-- | Get a render function for a given extension.
23-- | Get a render function for a given extension.
40−getRenderFunction :: FileType -> (String -> String)
24+getRenderFunction :: FileType -> Hakyll (String -> String)
41−getRenderFunction Html = id
25+getRenderFunction Html = return id
42−getRenderFunction Text = id
26+getRenderFunction Text = return id
27+getRenderFunction fileType = do
28+ parserState <- askHakyll pandocParserState
29+ writerOptions <- askHakyll pandocWriterOptions
43−getRenderFunction fileType = writeHtmlString writerOptions
30+ return $ writeHtmlString writerOptions
44− . readFunction fileType (readOptions fileType)
31+ . readFunction fileType (readOptions parserState fileType)
45 where
32 where
46 readFunction ReStructuredText = readRST
33 readFunction ReStructuredText = readRST
47 readFunction LaTeX = readLaTeX
34 readFunction LaTeX = readLaTeX
@@ -49,9 +36,9 @@ getRenderFunction fileType = writeHtmlString writerOptions
49 readFunction LiterateHaskellMarkdown = readMarkdown
36 readFunction LiterateHaskellMarkdown = readMarkdown
50 readFunction t = error $ "Cannot render " ++ show t
37 readFunction t = error $ "Cannot render " ++ show t
51
38
52− readOptions LiterateHaskellMarkdown =
39+ readOptions options LiterateHaskellMarkdown = options
53− readerOptions { stateLiterateHaskell = True }
40+ { stateLiterateHaskell = True }
54− readOptions _ = readerOptions
41+ readOptions options _ = options
55
42
56-- | Split a page into sections.
43-- | Split a page into sections.
57splitAtDelimiters :: [String] -> State (Maybe String) [[String]]
44splitAtDelimiters :: [String] -> State (Maybe String) [[String]]
@@ -103,8 +90,8 @@ readSection renderFunction isFirst ls
103-- has a @.markdown@ extension, it will be rendered using pandoc.
90-- has a @.markdown@ extension, it will be rendered using pandoc.
104readPageFromFile :: FilePath -> Hakyll Context
91readPageFromFile :: FilePath -> Hakyll Context
105readPageFromFile path = do
92readPageFromFile path = do
106− let renderFunction = getRenderFunction $ getFileType path
93+ renderFunction <- getRenderFunction $ getFileType path
107− sectionFunctions = map (readSection renderFunction)
94+ let sectionFunctions = map (readSection renderFunction)
108 (True : repeat False)
95 (True : repeat False)
109
96
110 -- Read file.
97 -- Read file.