module Hakyll.Web.Pandoc
(
readPandoc
, readPandocWith
, writePandoc
, writePandocWith
, pageReadPandoc
, pageReadPandocWith
, pageReadPandocWithA
, pageRenderPandoc
, pageRenderPandocWith
, defaultHakyllParserState
, defaultHakyllWriterOptions
) where
import Prelude hiding (id)
import Control.Applicative ((<$>))
import Control.Arrow ((>>>), (>>^), (&&&), (***))
import Control.Category (id)
import Data.Maybe (fromMaybe)
import Text.Pandoc
import Hakyll.Core.Compiler
import Hakyll.Core.Identifier
import Hakyll.Core.Util.Arrow
import Hakyll.Web.Pandoc.FileType
import Hakyll.Web.Page.Internal
readPandoc :: FileType
-> Maybe (Identifier a)
-> String
-> Pandoc
readPandoc = readPandocWith defaultHakyllParserState
readPandocWith :: ParserState
-> FileType
-> Maybe (Identifier a)
-> String
-> Pandoc
readPandocWith state fileType' id' = case fileType' of
Html -> readHtml state
LaTeX -> readLaTeX state
LiterateHaskell t ->
readPandocWith state {stateLiterateHaskell = True} t id'
Markdown -> readMarkdown state
Rst -> readRST state
Textile -> readTextile state
t -> error $
"Hakyll.Web.readPandocWith: I don't know how to read a file of the " ++
"type " ++ show t ++ fromMaybe "" (fmap ((" for: " ++) . show) id')
writePandoc :: Pandoc
-> String
writePandoc = writePandocWith defaultHakyllWriterOptions
writePandocWith :: WriterOptions
-> Pandoc
-> String
writePandocWith = writeHtmlString
pageReadPandoc :: Compiler (Page String) (Page Pandoc)
pageReadPandoc = pageReadPandocWith defaultHakyllParserState
pageReadPandocWith :: ParserState -> Compiler (Page String) (Page Pandoc)
pageReadPandocWith state = constA state &&& id >>> pageReadPandocWithA
pageReadPandocWithA :: Compiler (ParserState, Page String) (Page Pandoc)
pageReadPandocWithA =
id *** id &&& getIdentifier &&& getFileType >>^ pageReadPandocWithA'
where
pageReadPandocWithA' (s, (p, (i, t))) = readPandocWith s t (Just i) <$> p
pageRenderPandoc :: Compiler (Page String) (Page String)
pageRenderPandoc =
pageRenderPandocWith defaultHakyllParserState defaultHakyllWriterOptions
pageRenderPandocWith :: ParserState
-> WriterOptions
-> Compiler (Page String) (Page String)
pageRenderPandocWith state options =
pageReadPandocWith state >>^ fmap (writePandocWith options)
defaultHakyllParserState :: ParserState
defaultHakyllParserState = defaultParserState
{
stateSmart = True
}
defaultHakyllWriterOptions :: WriterOptions
defaultHakyllWriterOptions = defaultWriterOptions
{
writerLiterateHaskell = True
}