@@ -0,0 +1,98 @@
1+-- | Module exporting pandoc bindings
3+module Hakyll.Web.Pandoc
9+ , targetReadPandocWith
11+ , targetRenderPandocWith
13+ , defaultWriterOptions
16+import Control.Applicative ((<$>), (<*>))
18+import Text.Pandoc (Pandoc)
19+import qualified Text.Pandoc as P
21+import Hakyll.Web.FileType
22+import Hakyll.Core.Target
24+-- | Read a string using pandoc, with the default options
26+readPandoc :: FileType -- ^ File type, determines how parsing happens
27+ -> String -- ^ String to read
28+ -> Pandoc -- ^ Resulting document
29+readPandoc = readPandocWith defaultParserState
31+-- | Read a string using pandoc, with the supplied options
33+readPandocWith :: P.ParserState -- ^ Parser options
34+ -> FileType -- ^ File type, determines how parsing happens
35+ -> String -- ^ String to read
36+ -> Pandoc -- ^ Resulting document
37+readPandocWith state fileType' = case fileType' of
38+ Html -> P.readHtml state
39+ LaTeX -> P.readLaTeX state
40+ LiterateHaskell t -> readPandocWith state {P.stateLiterateHaskell = True} t
41+ Markdown -> P.readMarkdown state
42+ Rst -> P.readRST state
44+ "readPandoc: I don't know how to read " ++ show t
46+-- | Write a document (as HTML) using pandoc, with the default options
48+writePandoc :: Pandoc -- ^ Document to write
49+ -> String -- ^ Resulting HTML
50+writePandoc = writePandocWith defaultWriterOptions
52+-- | Write a document (as HTML) using pandoc, with the supplied options
54+writePandocWith :: P.WriterOptions -- ^ Writer options for pandoc
55+ -> Pandoc -- ^ Document to write
56+ -> String -- ^ Resulting HTML
57+writePandocWith = P.writeHtmlString
59+-- | Read the resource using pandoc
61+targetReadPandoc :: TargetM a Pandoc
62+targetReadPandoc = targetReadPandocWith defaultParserState
64+-- | Read the resource using pandoc
66+targetReadPandocWith :: P.ParserState -> TargetM a Pandoc
67+targetReadPandocWith state =
68+ readPandocWith state <$> getFileType <*> getResourceString
70+-- | Render the resource using pandoc
72+targetRenderPandoc :: TargetM a String
74+ targetRenderPandocWith defaultParserState defaultWriterOptions
76+-- | Render the resource using pandoc
78+targetRenderPandocWith :: P.ParserState -> P.WriterOptions -> TargetM a String
79+targetRenderPandocWith state options =
80+ writePandocWith options <$> targetReadPandocWith state
82+-- | The default reader options for pandoc parsing in hakyll
84+defaultParserState :: P.ParserState
85+defaultParserState = P.defaultParserState
86+ { -- The following option causes pandoc to read smart typography, a nice
91+-- | The default writer options for pandoc rendering in hakyll
93+defaultWriterOptions :: P.WriterOptions
94+defaultWriterOptions = P.defaultWriterOptions
95+ { -- This option causes literate haskell to be written using '>' marks in
96+ -- html, which I think is a good default.
97+ P.writerLiterateHaskell = True