module Hakyll.Web.Pandoc
(
readPandoc
, readPandocWith
, writePandoc
, writePandocWith
, renderPandoc
, renderPandocWith
, pandocCompiler
, pandocCompilerWith
, pandocCompilerWithTransform
, defaultHakyllReaderOptions
, defaultHakyllWriterOptions
) where
import Control.Applicative ((<$>))
import qualified Data.Set as S
import Text.Pandoc
import Hakyll.Core.Compiler
import Hakyll.Core.Item
import Hakyll.Web.Pandoc.FileType
readPandoc :: Item String
-> Item Pandoc
readPandoc = readPandocWith defaultHakyllReaderOptions
readPandocWith :: ReaderOptions
-> Item String
-> Item Pandoc
readPandocWith ropt item = fmap (reader ropt (itemFileType item)) item
where
reader ro t = case t of
Html -> readHtml ro
LaTeX -> readLaTeX ro
LiterateHaskell t' -> reader (addExt ro Ext_literate_haskell) t'
Markdown -> readMarkdown ro
Rst -> readRST ro
Textile -> readTextile ro
_ -> error $
"Hakyll.Web.readPandocWith: I don't know how to read a file of " ++
"the type " ++ show t ++ " for: " ++ show (itemIdentifier item)
addExt ro e = ro {readerExtensions = S.insert e $ readerExtensions ro}
writePandoc :: Item Pandoc
-> Item String
writePandoc = writePandocWith defaultHakyllWriterOptions
writePandocWith :: WriterOptions
-> Item Pandoc
-> Item String
writePandocWith wopt = fmap $ writeHtmlString wopt
renderPandoc :: Item String -> Item String
renderPandoc =
renderPandocWith defaultHakyllReaderOptions defaultHakyllWriterOptions
renderPandocWith :: ReaderOptions -> WriterOptions -> Item String -> Item String
renderPandocWith ropt wopt = writePandocWith wopt . readPandocWith ropt
pandocCompiler :: Compiler (Item String)
pandocCompiler =
pandocCompilerWith defaultHakyllReaderOptions defaultHakyllWriterOptions
pandocCompilerWith :: ReaderOptions -> WriterOptions -> Compiler (Item String)
pandocCompilerWith ropt wopt = pandocCompilerWithTransform ropt wopt id
pandocCompilerWithTransform :: ReaderOptions -> WriterOptions
-> (Pandoc -> Pandoc)
-> Compiler (Item String)
pandocCompilerWithTransform ropt wopt f = cached cacheName $
writePandocWith wopt . fmap f . readPandocWith ropt <$> getResourceBody
where
cacheName = "Hakyll.Web.Page.pageCompilerWithPandoc"
defaultHakyllReaderOptions :: ReaderOptions
defaultHakyllReaderOptions = def
{
readerSmart = True
}
defaultHakyllWriterOptions :: WriterOptions
defaultHakyllWriterOptions = def
{
writerExtensions = S.insert Ext_literate_haskell (writerExtensions def)
}