@@ -1,5 +1,5 @@
1−-- | Module exporting pandoc bindings
2−--
1+--------------------------------------------------------------------------------
2+-- | Module exporting convenientpandoc bindings
33module Hakyll.Web.Pandoc
44 ( -- * The basic building blocks
55 readPandoc
@@ -19,34 +19,38 @@ module Hakyll.Web.Pandoc
1919 , defaultHakyllWriterOptions
2020 ) where
2121
22−import Prelude hiding (id)
23−import Control.Applicative ((<$>))
24−import Control.Arrow ((>>>), (>>^), (&&&), (***))
25−import Control.Category (id)
26−import Data.Maybe (fromMaybe)
2722
28−import Text.Pandoc
23+--------------------------------------------------------------------------------
24+import Control.Arrow ((&&&), (***), (>>>), (>>^))
25+import Control.Category (id)
26+import Data.Maybe (fromMaybe)
27+import Prelude hiding (id)
28+import Text.Pandoc
2929
30−import Hakyll.Core.Compiler
31−import Hakyll.Core.Identifier
32−import Hakyll.Core.Util.Arrow
33−import Hakyll.Web.Pandoc.FileType
34−import Hakyll.Web.Page.Internal
3530
31+--------------------------------------------------------------------------------
32+import Hakyll.Core.Compiler
33+import Hakyll.Core.Identifier
34+import Hakyll.Core.Util.Arrow
35+import Hakyll.Web.Page.Internal
36+import Hakyll.Web.Pandoc.FileType
37+
38+
39+--------------------------------------------------------------------------------
3640-- | Read a string using pandoc, with the default options
37−--
3841readPandoc :: FileType -- ^ Determines how parsing happens
3942 -> Maybe (Identifier a) -- ^ Optional, for better error messages
40− -> String -- ^ String to read
43+ -> Page -- ^ String to read
4144 -> Pandoc -- ^ Resulting document
4245readPandoc = readPandocWith defaultHakyllParserState
4346
47+
48+--------------------------------------------------------------------------------
4449-- | Read a string using pandoc, with the supplied options
45−--
4650readPandocWith :: ParserState -- ^ Parser options
4751 -> FileType -- ^ Determines parsing method
4852 -> Maybe (Identifier a) -- ^ Optional, for better error messages
49− -> String -- ^ String to read
53+ -> Page -- ^ String to read
5054 -> Pandoc -- ^ Resulting document
5155readPandocWith state fileType' id' = case fileType' of
5256 Html -> readHtml state
@@ -60,54 +64,60 @@ readPandocWith state fileType' id' = case fileType' of
6064 "Hakyll.Web.readPandocWith: I don't know how to read a file of the " ++
6165 "type " ++ show t ++ fromMaybe "" (fmap ((" for: " ++) . show) id')
6266
67+
68+--------------------------------------------------------------------------------
6369-- | Write a document (as HTML) using pandoc, with the default options
64−--
6570writePandoc :: Pandoc -- ^ Document to write
66− -> String -- ^ Resulting HTML
71+ -> Page -- ^ Resulting HTML
6772writePandoc = writePandocWith defaultHakyllWriterOptions
6873
74+
75+--------------------------------------------------------------------------------
6976-- | Write a document (as HTML) using pandoc, with the supplied options
70−--
7177writePandocWith :: WriterOptions -- ^ Writer options for pandoc
7278 -> Pandoc -- ^ Document to write
73− -> String -- ^ Resulting HTML
79+ -> Page -- ^ Resulting HTML
7480writePandocWith = writeHtmlString
7581
82+
83+--------------------------------------------------------------------------------
7684-- | Read the resource using pandoc
77−--
78−pageReadPandoc :: Compiler (Page String) (Page Pandoc)
85+pageReadPandoc :: Compiler Page Pandoc
7986pageReadPandoc = pageReadPandocWith defaultHakyllParserState
8087
88+
89+--------------------------------------------------------------------------------
8190-- | Read the resource using pandoc
82−--
83−pageReadPandocWith :: ParserState -> Compiler (Page String) (Page Pandoc)
91+pageReadPandocWith :: ParserState -> Compiler Page Pandoc
8492pageReadPandocWith state = constA state &&& id >>> pageReadPandocWithA
8593
94+
95+--------------------------------------------------------------------------------
8696-- | Read the resource using pandoc. This is a (rarely needed) variant, which
8797-- comes in very useful when the parser state is the result of some arrow.
88−--
89−pageReadPandocWithA :: Compiler (ParserState, Page String) (Page Pandoc)
98+pageReadPandocWithA :: Compiler (ParserState, Page) Pandoc
9099pageReadPandocWithA =
91100 id *** id &&& getIdentifier &&& getFileType >>^ pageReadPandocWithA'
92101 where
93− pageReadPandocWithA' (s, (p, (i, t))) = readPandocWith s t (Just i) <$> p
102+ pageReadPandocWithA' (s, (p, (i, t))) = readPandocWith s t (Just i) p
103+
94104
105+--------------------------------------------------------------------------------
95106-- | Render the resource using pandoc
96−--
97−pageRenderPandoc :: Compiler (Page String) (Page String)
107+pageRenderPandoc :: Compiler Page Page
98108pageRenderPandoc =
99109 pageRenderPandocWith defaultHakyllParserState defaultHakyllWriterOptions
100110
111+
112+--------------------------------------------------------------------------------
101113-- | Render the resource using pandoc
102−--
103−pageRenderPandocWith :: ParserState
104− -> WriterOptions
105− -> Compiler (Page String) (Page String)
114+pageRenderPandocWith :: ParserState -> WriterOptions -> Compiler Page Page
106115pageRenderPandocWith state options =
107− pageReadPandocWith state >>^ fmap (writePandocWith options)
116+ pageReadPandocWith state >>^ writePandocWith options
117+
108118
119+--------------------------------------------------------------------------------
109120-- | The default reader options for pandoc parsing in hakyll
110−--
111121defaultHakyllParserState :: ParserState
112122defaultHakyllParserState = defaultParserState
113123 { -- The following option causes pandoc to read smart typography, a nice
@@ -115,8 +125,9 @@ defaultHakyllParserState = defaultParserState
115125 stateSmart = True
116126 }
117127
128+
129+--------------------------------------------------------------------------------
118130-- | The default writer options for pandoc rendering in hakyll
119−--
120131defaultHakyllWriterOptions :: WriterOptions
121132defaultHakyllWriterOptions = defaultWriterOptions
122133 { -- This option causes literate haskell to be written using '>' marks in