@@ -1,5 +1,5 @@
1+--------------------------------------------------------------------------------
1−-- | Module exporting pandoc bindings
2+-- | Module exporting convenientpandoc bindings
3module Hakyll.Web.Pandoc
3module Hakyll.Web.Pandoc
4 ( -- * The basic building blocks
4 ( -- * The basic building blocks
@@ -19,34 +19,38 @@ module Hakyll.Web.Pandoc
19 , defaultHakyllWriterOptions
19 , defaultHakyllWriterOptions
22−import Prelude hiding (id)
23−import Control.Applicative ((<$>))
24−import Control.Arrow ((>>>), (>>^), (&&&), (***))
25−import Control.Category (id)
26−import Data.Maybe (fromMaybe)
23+--------------------------------------------------------------------------------
24+import Control.Arrow ((&&&), (***), (>>>), (>>^))
25+import Control.Category (id)
26+import Data.Maybe (fromMaybe)
27+import Prelude hiding (id)
28−import Text.Pandoc
28+import Text.Pandoc
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
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
39+--------------------------------------------------------------------------------
36-- | Read a string using pandoc, with the default options
40-- | Read a string using pandoc, with the default options
38readPandoc :: FileType -- ^ Determines how parsing happens
41readPandoc :: FileType -- ^ Determines how parsing happens
39 -> Maybe (Identifier a) -- ^ Optional, for better error messages
42 -> Maybe (Identifier a) -- ^ Optional, for better error messages
40− -> String -- ^ String to read
43+ -> Page -- ^ String to read
41 -> Pandoc -- ^ Resulting document
44 -> Pandoc -- ^ Resulting document
42readPandoc = readPandocWith defaultHakyllParserState
45readPandoc = readPandocWith defaultHakyllParserState
48+--------------------------------------------------------------------------------
44-- | Read a string using pandoc, with the supplied options
49-- | Read a string using pandoc, with the supplied options
46readPandocWith :: ParserState -- ^ Parser options
50readPandocWith :: ParserState -- ^ Parser options
47 -> FileType -- ^ Determines parsing method
51 -> FileType -- ^ Determines parsing method
48 -> Maybe (Identifier a) -- ^ Optional, for better error messages
52 -> Maybe (Identifier a) -- ^ Optional, for better error messages
49− -> String -- ^ String to read
53+ -> Page -- ^ String to read
50 -> Pandoc -- ^ Resulting document
54 -> Pandoc -- ^ Resulting document
51readPandocWith state fileType' id' = case fileType' of
55readPandocWith state fileType' id' = case fileType' of
52 Html -> readHtml state
56 Html -> readHtml state
@@ -60,54 +64,60 @@ readPandocWith state fileType' id' = case fileType' of
60 "Hakyll.Web.readPandocWith: I don't know how to read a file of the " ++
64 "Hakyll.Web.readPandocWith: I don't know how to read a file of the " ++
61 "type " ++ show t ++ fromMaybe "" (fmap ((" for: " ++) . show) id')
65 "type " ++ show t ++ fromMaybe "" (fmap ((" for: " ++) . show) id')
68+--------------------------------------------------------------------------------
63-- | Write a document (as HTML) using pandoc, with the default options
69-- | Write a document (as HTML) using pandoc, with the default options
65writePandoc :: Pandoc -- ^ Document to write
70writePandoc :: Pandoc -- ^ Document to write
66− -> String -- ^ Resulting HTML
71+ -> Page -- ^ Resulting HTML
67writePandoc = writePandocWith defaultHakyllWriterOptions
72writePandoc = writePandocWith defaultHakyllWriterOptions
75+--------------------------------------------------------------------------------
69-- | Write a document (as HTML) using pandoc, with the supplied options
76-- | Write a document (as HTML) using pandoc, with the supplied options
71writePandocWith :: WriterOptions -- ^ Writer options for pandoc
77writePandocWith :: WriterOptions -- ^ Writer options for pandoc
72 -> Pandoc -- ^ Document to write
78 -> Pandoc -- ^ Document to write
73− -> String -- ^ Resulting HTML
79+ -> Page -- ^ Resulting HTML
74writePandocWith = writeHtmlString
80writePandocWith = writeHtmlString
83+--------------------------------------------------------------------------------
76-- | Read the resource using pandoc
84-- | Read the resource using pandoc
78−pageReadPandoc :: Compiler (Page String) (Page Pandoc)
85+pageReadPandoc :: Compiler Page Pandoc
79pageReadPandoc = pageReadPandocWith defaultHakyllParserState
86pageReadPandoc = pageReadPandocWith defaultHakyllParserState
89+--------------------------------------------------------------------------------
81-- | Read the resource using pandoc
90-- | Read the resource using pandoc
83−pageReadPandocWith :: ParserState -> Compiler (Page String) (Page Pandoc)
91+pageReadPandocWith :: ParserState -> Compiler Page Pandoc
84pageReadPandocWith state = constA state &&& id >>> pageReadPandocWithA
92pageReadPandocWith state = constA state &&& id >>> pageReadPandocWithA
95+--------------------------------------------------------------------------------
86-- | Read the resource using pandoc. This is a (rarely needed) variant, which
96-- | Read the resource using pandoc. This is a (rarely needed) variant, which
87-- comes in very useful when the parser state is the result of some arrow.
97-- comes in very useful when the parser state is the result of some arrow.
89−pageReadPandocWithA :: Compiler (ParserState, Page String) (Page Pandoc)
98+pageReadPandocWithA :: Compiler (ParserState, Page) Pandoc
90pageReadPandocWithA =
99pageReadPandocWithA =
91 id *** id &&& getIdentifier &&& getFileType >>^ pageReadPandocWithA'
100 id *** id &&& getIdentifier &&& getFileType >>^ pageReadPandocWithA'
93− pageReadPandocWithA' (s, (p, (i, t))) = readPandocWith s t (Just i) <$> p
102+ pageReadPandocWithA' (s, (p, (i, t))) = readPandocWith s t (Just i) p
105+--------------------------------------------------------------------------------
95-- | Render the resource using pandoc
106-- | Render the resource using pandoc
97−pageRenderPandoc :: Compiler (Page String) (Page String)
107+pageRenderPandoc :: Compiler Page Page
98pageRenderPandoc =
108pageRenderPandoc =
99 pageRenderPandocWith defaultHakyllParserState defaultHakyllWriterOptions
109 pageRenderPandocWith defaultHakyllParserState defaultHakyllWriterOptions
112+--------------------------------------------------------------------------------
101-- | Render the resource using pandoc
113-- | Render the resource using pandoc
103−pageRenderPandocWith :: ParserState
114+pageRenderPandocWith :: ParserState -> WriterOptions -> Compiler Page Page
105− -> Compiler (Page String) (Page String)
106pageRenderPandocWith state options =
115pageRenderPandocWith state options =
107− pageReadPandocWith state >>^ fmap (writePandocWith options)
116+ pageReadPandocWith state >>^ writePandocWith options
119+--------------------------------------------------------------------------------
109-- | The default reader options for pandoc parsing in hakyll
120-- | The default reader options for pandoc parsing in hakyll
111defaultHakyllParserState :: ParserState
121defaultHakyllParserState :: ParserState
112defaultHakyllParserState = defaultParserState
122defaultHakyllParserState = defaultParserState
113 { -- The following option causes pandoc to read smart typography, a nice
123 { -- The following option causes pandoc to read smart typography, a nice
@@ -115,8 +125,9 @@ defaultHakyllParserState = defaultParserState
115 stateSmart = True
125 stateSmart = True
129+--------------------------------------------------------------------------------
118-- | The default writer options for pandoc rendering in hakyll
130-- | The default writer options for pandoc rendering in hakyll
120defaultHakyllWriterOptions :: WriterOptions
131defaultHakyllWriterOptions :: WriterOptions
121defaultHakyllWriterOptions = defaultWriterOptions
132defaultHakyllWriterOptions = defaultWriterOptions
122 { -- This option causes literate haskell to be written using '>' marks in
133 { -- This option causes literate haskell to be written using '>' marks in