on master help sign in
Make pandoc functions work on pages by default
bda2682Jasper Van der Jeugt
src/Hakyll/Web/Page/Read.hs+1−1
@@ -6,7 +6,7 @@ module Hakyll.Web.Page.Read
6
6
7import Control.Applicative ((<$>), (<*>))
7import Control.Applicative ((<$>), (<*>))
8import Control.Arrow (second, (***))
8import Control.Arrow (second, (***))
9−import Control.Monad.State
9+import Control.Monad.State (State, get, put, evalState)
10import Data.List (isPrefixOf)
10import Data.List (isPrefixOf)
11import Data.Map (Map)
11import Data.Map (Map)
12import qualified Data.Map as M
12import qualified Data.Map as M
src/Hakyll/Web/Pandoc.hs+28−18
@@ -1,25 +1,31 @@
1-- | Module exporting pandoc bindings
1-- | Module exporting pandoc bindings
2--
2--
3module Hakyll.Web.Pandoc
3module Hakyll.Web.Pandoc
4+ ( -- * The basic building blocks
4− ( readPandoc
5+ readPandoc
5 , readPandocWith
6 , readPandocWith
6 , writePandoc
7 , writePandoc
7 , writePandocWith
8 , writePandocWith
8− , targetReadPandoc
9+
9− , targetReadPandocWith
10+ -- * Functions working on pages/targets
10− , targetRenderPandoc
11+ , pageReadPandoc
11− , targetRenderPandocWith
12+ , pageReadPandocWith
13+ , pageRenderPandoc
14+ , pageRenderPandocWith
15+
16+ -- * Default options
12 , defaultParserState
17 , defaultParserState
13 , defaultWriterOptions
18 , defaultWriterOptions
14 ) where
19 ) where
15
20
16−import Control.Applicative ((<$>), (<*>))
21+import Control.Applicative ((<$>))
17
22
18import Text.Pandoc (Pandoc)
23import Text.Pandoc (Pandoc)
19import qualified Text.Pandoc as P
24import qualified Text.Pandoc as P
20
25
21−import Hakyll.Web.FileType
22import Hakyll.Core.Target
26import Hakyll.Core.Target
27+import Hakyll.Web.FileType
28+import Hakyll.Web.Page
23
29
24-- | Read a string using pandoc, with the default options
30-- | Read a string using pandoc, with the default options
25--
31--
@@ -58,26 +64,30 @@ writePandocWith = P.writeHtmlString
58
64
59-- | Read the resource using pandoc
65-- | Read the resource using pandoc
60--
66--
61−targetReadPandoc :: TargetM a Pandoc
67+pageReadPandoc :: Page String -> TargetM a (Page Pandoc)
62−targetReadPandoc = targetReadPandocWith defaultParserState
68+pageReadPandoc = pageReadPandocWith defaultParserState
63
69
64-- | Read the resource using pandoc
70-- | Read the resource using pandoc
65--
71--
66−targetReadPandocWith :: P.ParserState -> TargetM a Pandoc
72+pageReadPandocWith :: P.ParserState -> Page String -> TargetM a (Page Pandoc)
67−targetReadPandocWith state =
73+pageReadPandocWith state page = do
74+ fileType' <- getFileType
68− readPandocWith state <$> getFileType <*> getResourceString
75+ return $ readPandocWith state fileType' <$> page
69
76
70-- | Render the resource using pandoc
77-- | Render the resource using pandoc
71--
78--
72−targetRenderPandoc :: TargetM a String
79+pageRenderPandoc :: Page String -> TargetM a (Page String)
73−targetRenderPandoc =
74− targetRenderPandocWith defaultParserState defaultWriterOptions
80+pageRenderPandoc = pageRenderPandocWith defaultParserState defaultWriterOptions
75
81
76-- | Render the resource using pandoc
82-- | Render the resource using pandoc
77--
83--
78−targetRenderPandocWith :: P.ParserState -> P.WriterOptions -> TargetM a String
84+pageRenderPandocWith :: P.ParserState
79−targetRenderPandocWith state options =
85+ -> P.WriterOptions
86+ -> Page String
87+ -> TargetM a (Page String)
88+pageRenderPandocWith state options page = do
89+ pandoc <- pageReadPandocWith state page
80− writePandocWith options <$> targetReadPandocWith state
90+ return $ writePandocWith options <$> pandoc
81
91
82-- | The default reader options for pandoc parsing in hakyll
92-- | The default reader options for pandoc parsing in hakyll
83--
93--