Expose pandoc options (patch by JD Marble).

This commit is contained in:
Jasper Van der Jeugt 2010-05-20 23:54:38 +02:00
parent e7d446c1a4
commit 06aa9fbc7b
4 changed files with 54 additions and 40 deletions

View file

@ -26,4 +26,5 @@ you will have to license your code under a GPL-compatible license.
## Authors ## Authors
Hakyll was originally written by [Jasper Van der Jeugt](http://jaspervdj.be). It Hakyll was originally written by [Jasper Van der Jeugt](http://jaspervdj.be). It
also received contributions from [seschwar](http://github.com/seschwar). also received contributions from [seschwar](http://github.com/seschwar) and
[JD Marble](http://github.com/jdmarble/).

View file

@ -21,19 +21,39 @@ import System.Environment (getArgs, getProgName)
import System.Directory (doesDirectoryExist, removeDirectoryRecursive) import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
import System.Time (getClockTime) import System.Time (getClockTime)
import Text.Pandoc
import Network.Hakyll.SimpleServer (simpleServer) import Network.Hakyll.SimpleServer (simpleServer)
import Text.Hakyll.HakyllMonad import Text.Hakyll.HakyllMonad
import Text.Hakyll.File import Text.Hakyll.File
-- | The default reader options for pandoc parsing.
defaultPandocParserState :: ParserState
defaultPandocParserState = defaultParserState
{ -- The following option causes pandoc to read smart typography, a nice
-- and free bonus.
stateSmart = True
}
-- | The default writer options for pandoc rendering.
defaultPandocWriterOptions :: WriterOptions
defaultPandocWriterOptions = defaultWriterOptions
{ -- This option causes literate haskell to be written using '>' marks in
-- html, which I think is a good default.
writerLiterateHaskell = True
}
-- | The default hakyll configuration. -- | The default hakyll configuration.
defaultHakyllConfiguration :: HakyllConfiguration defaultHakyllConfiguration :: HakyllConfiguration
defaultHakyllConfiguration = HakyllConfiguration defaultHakyllConfiguration = HakyllConfiguration
{ absoluteUrl = "" { absoluteUrl = ""
, additionalContext = M.empty , additionalContext = M.empty
, siteDirectory = "_site" , siteDirectory = "_site"
, cacheDirectory = "_cache" , cacheDirectory = "_cache"
, enableIndexUrl = False , enableIndexUrl = False
, previewPollDelay = 1000000 , previewPollDelay = 1000000
, pandocParserState = defaultPandocParserState
, pandocWriterOptions = defaultPandocWriterOptions
} }
-- | Main function to run Hakyll with the default configuration. The -- | Main function to run Hakyll with the default configuration. The

View file

@ -10,6 +10,8 @@ import Control.Monad.Reader (ReaderT, ask)
import Control.Monad (liftM) import Control.Monad (liftM)
import qualified Data.Map as M import qualified Data.Map as M
import Text.Pandoc (ParserState, WriterOptions)
import Text.Hakyll.Context (Context) import Text.Hakyll.Context (Context)
-- | Our custom monad stack. -- | Our custom monad stack.
@ -18,18 +20,22 @@ type Hakyll = ReaderT HakyllConfiguration IO
-- | Hakyll global configuration type. -- | Hakyll global configuration type.
data HakyllConfiguration = HakyllConfiguration data HakyllConfiguration = HakyllConfiguration
{ -- | Absolute URL of the site. { -- | Absolute URL of the site.
absoluteUrl :: String absoluteUrl :: String
, -- | An additional context to use when rendering. This additional context , -- | An additional context to use when rendering. This additional context
-- is used globally. -- is used globally.
additionalContext :: Context additionalContext :: Context
, -- | Directory where the site is placed. , -- | Directory where the site is placed.
siteDirectory :: FilePath siteDirectory :: FilePath
, -- | Directory for cache files. , -- | Directory for cache files.
cacheDirectory :: FilePath cacheDirectory :: FilePath
, -- | Enable index links. , -- | Enable index links.
enableIndexUrl :: Bool enableIndexUrl :: Bool
, -- | Delay between polls in preview mode. , -- | Delay between polls in preview mode.
previewPollDelay :: Int previewPollDelay :: Int
, -- | Pandoc parsing options
pandocParserState :: ParserState
, -- | Pandoc writer options
pandocWriterOptions :: WriterOptions
} }
-- | Simplified @ask@ function for the Hakyll monad stack. -- | Simplified @ask@ function for the Hakyll monad stack.

View file

@ -1,5 +1,5 @@
-- | A module for dealing with @Page@s. This module is mostly internally used. -- | A module for dealing with @Page@s. This module is mostly internally used.
module Text.Hakyll.Internal.Page module Text.Hakyll.Internal.Page
( readPage ( readPage
) where ) where
@ -20,28 +20,15 @@ import Text.Hakyll.Util (trim)
import Text.Hakyll.Internal.Cache import Text.Hakyll.Internal.Cache
import Text.Hakyll.Internal.FileType import Text.Hakyll.Internal.FileType
-- | The default reader options for pandoc parsing.
readerOptions :: ParserState
readerOptions = defaultParserState
{ -- The following option causes pandoc to read smart typography, a nice
-- and free bonus.
stateSmart = True
}
-- | The default writer options for pandoc rendering.
writerOptions :: WriterOptions
writerOptions = defaultWriterOptions
{ -- This option causes literate haskell to be written using '>' marks in
-- html, which I think is a good default.
writerLiterateHaskell = True
}
-- | Get a render function for a given extension. -- | Get a render function for a given extension.
getRenderFunction :: FileType -> (String -> String) getRenderFunction :: FileType -> Hakyll (String -> String)
getRenderFunction Html = id getRenderFunction Html = return id
getRenderFunction Text = id getRenderFunction Text = return id
getRenderFunction fileType = writeHtmlString writerOptions getRenderFunction fileType = do
. readFunction fileType (readOptions fileType) parserState <- askHakyll pandocParserState
writerOptions <- askHakyll pandocWriterOptions
return $ writeHtmlString writerOptions
. readFunction fileType (readOptions parserState fileType)
where where
readFunction ReStructuredText = readRST readFunction ReStructuredText = readRST
readFunction LaTeX = readLaTeX readFunction LaTeX = readLaTeX
@ -49,9 +36,9 @@ getRenderFunction fileType = writeHtmlString writerOptions
readFunction LiterateHaskellMarkdown = readMarkdown readFunction LiterateHaskellMarkdown = readMarkdown
readFunction t = error $ "Cannot render " ++ show t readFunction t = error $ "Cannot render " ++ show t
readOptions LiterateHaskellMarkdown = readOptions options LiterateHaskellMarkdown = options
readerOptions { stateLiterateHaskell = True } { stateLiterateHaskell = True }
readOptions _ = readerOptions readOptions options _ = options
-- | Split a page into sections. -- | Split a page into sections.
splitAtDelimiters :: [String] -> State (Maybe String) [[String]] splitAtDelimiters :: [String] -> State (Maybe String) [[String]]
@ -103,8 +90,8 @@ readSection renderFunction isFirst ls
-- has a @.markdown@ extension, it will be rendered using pandoc. -- has a @.markdown@ extension, it will be rendered using pandoc.
readPageFromFile :: FilePath -> Hakyll Context readPageFromFile :: FilePath -> Hakyll Context
readPageFromFile path = do readPageFromFile path = do
let renderFunction = getRenderFunction $ getFileType path renderFunction <- getRenderFunction $ getFileType path
sectionFunctions = map (readSection renderFunction) let sectionFunctions = map (readSection renderFunction)
(True : repeat False) (True : repeat False)
-- Read file. -- Read file.