From bda268273b6cc18d8d1d9fb3170f92a06f6f45b8 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Mon, 27 Dec 2010 11:14:04 +0100 Subject: Make pandoc functions work on pages by default --- src/Hakyll/Web/Page/Read.hs | 2 +- src/Hakyll/Web/Pandoc.hs | 46 +++++++++++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/Hakyll/Web/Page/Read.hs b/src/Hakyll/Web/Page/Read.hs index c886fab..82224a4 100644 --- a/src/Hakyll/Web/Page/Read.hs +++ b/src/Hakyll/Web/Page/Read.hs @@ -6,7 +6,7 @@ module Hakyll.Web.Page.Read import Control.Applicative ((<$>), (<*>)) import Control.Arrow (second, (***)) -import Control.Monad.State +import Control.Monad.State (State, get, put, evalState) import Data.List (isPrefixOf) import Data.Map (Map) import qualified Data.Map as M diff --git a/src/Hakyll/Web/Pandoc.hs b/src/Hakyll/Web/Pandoc.hs index 52572a7..57fd1ac 100644 --- a/src/Hakyll/Web/Pandoc.hs +++ b/src/Hakyll/Web/Pandoc.hs @@ -1,25 +1,31 @@ -- | Module exporting pandoc bindings -- module Hakyll.Web.Pandoc - ( readPandoc + ( -- * The basic building blocks + readPandoc , readPandocWith , writePandoc , writePandocWith - , targetReadPandoc - , targetReadPandocWith - , targetRenderPandoc - , targetRenderPandocWith + + -- * Functions working on pages/targets + , pageReadPandoc + , pageReadPandocWith + , pageRenderPandoc + , pageRenderPandocWith + + -- * Default options , defaultParserState , defaultWriterOptions ) where -import Control.Applicative ((<$>), (<*>)) +import Control.Applicative ((<$>)) import Text.Pandoc (Pandoc) import qualified Text.Pandoc as P -import Hakyll.Web.FileType import Hakyll.Core.Target +import Hakyll.Web.FileType +import Hakyll.Web.Page -- | Read a string using pandoc, with the default options -- @@ -58,26 +64,30 @@ writePandocWith = P.writeHtmlString -- | Read the resource using pandoc -- -targetReadPandoc :: TargetM a Pandoc -targetReadPandoc = targetReadPandocWith defaultParserState +pageReadPandoc :: Page String -> TargetM a (Page Pandoc) +pageReadPandoc = pageReadPandocWith defaultParserState -- | Read the resource using pandoc -- -targetReadPandocWith :: P.ParserState -> TargetM a Pandoc -targetReadPandocWith state = - readPandocWith state <$> getFileType <*> getResourceString +pageReadPandocWith :: P.ParserState -> Page String -> TargetM a (Page Pandoc) +pageReadPandocWith state page = do + fileType' <- getFileType + return $ readPandocWith state fileType' <$> page -- | Render the resource using pandoc -- -targetRenderPandoc :: TargetM a String -targetRenderPandoc = - targetRenderPandocWith defaultParserState defaultWriterOptions +pageRenderPandoc :: Page String -> TargetM a (Page String) +pageRenderPandoc = pageRenderPandocWith defaultParserState defaultWriterOptions -- | Render the resource using pandoc -- -targetRenderPandocWith :: P.ParserState -> P.WriterOptions -> TargetM a String -targetRenderPandocWith state options = - writePandocWith options <$> targetReadPandocWith state +pageRenderPandocWith :: P.ParserState + -> P.WriterOptions + -> Page String + -> TargetM a (Page String) +pageRenderPandocWith state options page = do + pandoc <- pageReadPandocWith state page + return $ writePandocWith options <$> pandoc -- | The default reader options for pandoc parsing in hakyll -- -- cgit v1.2.3