@@ -15,13 +15,14 @@ module Hakyll.Web.Pandoc
1515 , pandocCompilerWithTransform
1616
1717 -- * Default options
18− , defaultHakyllParserState
18+ , defaultHakyllReaderOptions
1919 , defaultHakyllWriterOptions
2020 ) where
2121
2222
2323--------------------------------------------------------------------------------
2424import Control.Applicative ((<$>))
25+import qualified Data.Set as S
2526import Text.Pandoc
2627
2728
@@ -35,26 +36,28 @@ import Hakyll.Web.Pandoc.FileType
3536-- | Read a string using pandoc, with the default options
3637readPandoc :: Item String -- ^ String to read
3738 -> Item Pandoc -- ^ Resulting document
38−readPandoc = readPandocWith defaultHakyllParserState
39+readPandoc = readPandocWith defaultHakyllReaderOptions
3940
4041
4142--------------------------------------------------------------------------------
4243-- | Read a string using pandoc, with the supplied options
43−readPandocWith :: ParserState -- ^ Parser options
44− -> Item String -- ^ String to read
45− -> Item Pandoc -- ^ Resulting document
46−readPandocWith state item = fmap (reader state (itemFileType item)) item
44+readPandocWith :: ReaderOptions -- ^ Parser options
45+ -> Item String -- ^ String to read
46+ -> Item Pandoc -- ^ Resulting document
47+readPandocWith ropt item = fmap (reader ropt (itemFileType item)) item
4748 where
48− reader s t = case t of
49− Html -> readHtml s
50− LaTeX -> readLaTeX s
51− LiterateHaskell t' -> reader s {stateLiterateHaskell = True} t'
52− Markdown -> readMarkdown s
53− Rst -> readRST s
54− Textile -> readTextile s
49+ reader ro t = case t of
50+ Html -> readHtml ro
51+ LaTeX -> readLaTeX ro
52+ LiterateHaskell t' -> reader (addExt ro Ext_literate_haskell) t'
53+ Markdown -> readMarkdown ro
54+ Rst -> readRST ro
55+ Textile -> readTextile ro
5556 _ -> error $
56− "Hakyll.Web.readPandocWith: I don't know how to read a file of the " ++
57− "type " ++ show t ++ " for: " ++ show (itemIdentifier item)
57+ "Hakyll.Web.readPandocWith: I don't know how to read a file of " ++
58+ "the type " ++ show t ++ " for: " ++ show (itemIdentifier item)
59+
60+ addExt ro e = ro {readerExtensions = S.insert e $ readerExtensions ro}
5861
5962
6063--------------------------------------------------------------------------------
@@ -69,63 +72,63 @@ writePandoc = writePandocWith defaultHakyllWriterOptions
6972writePandocWith :: WriterOptions -- ^ Writer options for pandoc
7073 -> Item Pandoc -- ^ Document to write
7174 -> Item String -- ^ Resulting HTML
72−writePandocWith options = fmap $ writeHtmlString options
75+writePandocWith wopt = fmap $ writeHtmlString wopt
7376
7477
7578--------------------------------------------------------------------------------
7679-- | Render the resource using pandoc
7780renderPandoc :: Item String -> Item String
7881renderPandoc =
79− renderPandocWith defaultHakyllParserState defaultHakyllWriterOptions
82+ renderPandocWith defaultHakyllReaderOptions defaultHakyllWriterOptions
8083
8184
8285--------------------------------------------------------------------------------
8386-- | Render the resource using pandoc
84−renderPandocWith :: ParserState -> WriterOptions -> Item String -> Item String
85−renderPandocWith state options = writePandocWith options . readPandocWith state
87+renderPandocWith :: ReaderOptions -> WriterOptions -> Item String -> Item String
88+renderPandocWith ropt wopt = writePandocWith wopt . readPandocWith ropt
8689
8790
8891--------------------------------------------------------------------------------
8992-- | Read a page render using pandoc
9093pandocCompiler :: Compiler (Item String)
9194pandocCompiler =
92− pandocCompilerWith defaultHakyllParserState defaultHakyllWriterOptions
95+ pandocCompilerWith defaultHakyllReaderOptions defaultHakyllWriterOptions
9396
9497
9598--------------------------------------------------------------------------------
9699-- | A version of 'pandocCompiler' which allows you to specify your own pandoc
97100-- options
98−pandocCompilerWith :: ParserState -> WriterOptions -> Compiler (Item String)
99−pandocCompilerWith state options = pandocCompilerWithTransform state options id
101+pandocCompilerWith :: ReaderOptions -> WriterOptions -> Compiler (Item String)
102+pandocCompilerWith ropt wopt = pandocCompilerWithTransform ropt wopt id
100103
101104
102105--------------------------------------------------------------------------------
103106-- | An extension of 'pandocCompilerWith' which allows you to specify a custom
104107-- pandoc transformation for the content
105−pandocCompilerWithTransform :: ParserState -> WriterOptions
108+pandocCompilerWithTransform :: ReaderOptions -> WriterOptions
106109 -> (Pandoc -> Pandoc)
107110 -> Compiler (Item String)
108−pandocCompilerWithTransform state options f = cached cacheName $
109− writePandocWith options . fmap f . readPandocWith state <$> getResourceBody
111+pandocCompilerWithTransform ropt wopt f = cached cacheName $
112+ writePandocWith wopt . fmap f . readPandocWith ropt <$> getResourceBody
110113 where
111114 cacheName = "Hakyll.Web.Page.pageCompilerWithPandoc"
112115
113116
114117--------------------------------------------------------------------------------
115118-- | The default reader options for pandoc parsing in hakyll
116−defaultHakyllParserState :: ParserState
117−defaultHakyllParserState = defaultParserState
119+defaultHakyllReaderOptions :: ReaderOptions
120+defaultHakyllReaderOptions = def
118121 { -- The following option causes pandoc to read smart typography, a nice
119122 -- and free bonus.
120− stateSmart = True
123+ readerSmart = True
121124 }
122125
123126
124127--------------------------------------------------------------------------------
125128-- | The default writer options for pandoc rendering in hakyll
126129defaultHakyllWriterOptions :: WriterOptions
127−defaultHakyllWriterOptions = defaultWriterOptions
130+defaultHakyllWriterOptions = def
128131 { -- This option causes literate haskell to be written using '>' marks in
129132 -- html, which I think is a good default.
130− writerLiterateHaskell = True
133+ writerExtensions = S.insert Ext_literate_haskell (writerExtensions def)
131134 }