on master help sign in
Update to use pandoc 1.9
commit064128305e5e1a99d20afa62331c7a3bdf566c8a authorJasper Van der Jeugt <m@jaspervdj.be> dateSun 20 Jan 2013, 09:35 (14 years ago) parent21b897a
6 files changed+78−45
hakyll.cabal+3−3 src/Hakyll/Web/Pandoc.hs+33−30 src/Hakyll/Web/Pandoc/Biblio.hs+15−11 web/releases.markdown+25 web/site.hs+1−1 web/templates/default.html+1
hakyll.cabal+3−3
@@ -1,5 +1,5 @@
11Name: hakyll
2−Version: 4.0.0.0
2+Version: 4.1.0.0
33
44Synopsis: A static website compiler library
55Description:
@@ -99,7 +99,7 @@ Library
9999 old-locale >= 1.0 && < 1.1,
100100 old-time >= 1.0 && < 1.2,
101101 cmdargs >= 0.10 && < 0.11,
102− pandoc >= 1.9.3 && < 1.10,
102+ pandoc >= 1.10 && < 1.11,
103103 parsec >= 3.0 && < 3.2,
104104 process >= 1.0 && < 1.2,
105105 random >= 1.0 && < 1.1,
@@ -198,7 +198,7 @@ Test-suite hakyll-tests
198198 old-locale >= 1.0 && < 1.1,
199199 old-time >= 1.0 && < 1.2,
200200 cmdargs >= 0.10 && < 0.11,
201− pandoc >= 1.9.3 && < 1.10,
201+ pandoc >= 1.0 && < 1.11,
202202 parsec >= 3.0 && < 3.2,
203203 process >= 1.0 && < 1.2,
204204 random >= 1.0 && < 1.1,
src/Hakyll/Web/Pandoc.hs+33−30
@@ -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 }
src/Hakyll/Web/Pandoc/Biblio.hs+15−11
@@ -5,8 +5,8 @@
55-- @.bib@) and a CSL file (@.csl@). Both need to be compiled with their
66-- respective compilers ('biblioCompiler' and 'cslCompiler'). Then, you can
77-- refer to these files when you use 'pageReadPandocBiblio'. This function also
8−-- takes a parser state for completeness -- you can use
9−-- 'defaultHakyllParserState' if you're unsure.
8+-- takes the reader options for completeness -- you can use
9+-- 'defaultHakyllReaderOptions' if you're unsure.
1010{-# LANGUAGE Arrows #-}
1111{-# LANGUAGE DeriveDataTypeable #-}
1212{-# LANGUAGE GeneralizedNewtypeDeriving #-}
@@ -22,9 +22,10 @@ module Hakyll.Web.Pandoc.Biblio
2222--------------------------------------------------------------------------------
2323import Control.Applicative ((<$>))
2424import Data.Binary (Binary (..))
25+import Data.Traversable (traverse)
2526import Data.Typeable (Typeable)
2627import qualified Text.CSL as CSL
27−import Text.Pandoc (Pandoc, ParserState (..))
28+import Text.Pandoc (Pandoc, ReaderOptions (..))
2829import Text.Pandoc.Biblio (processBiblio)
2930
3031
@@ -84,19 +85,22 @@ biblioCompiler = do
8485
8586
8687--------------------------------------------------------------------------------
87−readPandocBiblio :: ParserState
88− -> Item CSL
88+readPandocBiblio :: ReaderOptions
89+ -> Maybe (Item CSL)
8990 -> Item Biblio
9091 -> (Item String)
9192 -> Compiler (Item Pandoc)
92−readPandocBiblio state csl biblio item = do
93+readPandocBiblio ropt csl biblio item = do
94+ -- Parse CSL file, if given
95+ style <- unsafeCompiler $
96+ traverse (CSL.readCSLFile . toFilePath . itemIdentifier) csl
97+
9398 -- We need to know the citation keys, add then *before* actually parsing the
9499 -- actual page. If we don't do this, pandoc won't even consider them
95100 -- citations!
96101 let Biblio refs = itemBody biblio
97− cits = map CSL.refId refs
98− state' = state {stateCitations = stateCitations state ++ cits}
99− pandoc = itemBody $ readPandocWith state' item
100− cslPath = toFilePath $ itemIdentifier csl
101− pandoc' <- unsafeCompiler $ processBiblio cslPath Nothing refs pandoc
102+ ropt' = ropt {readerReferences = readerReferences ropt ++ refs}
103+ pandoc = itemBody $ readPandocWith ropt' item
104+ pandoc' = processBiblio style refs pandoc
105+
102106 return $ fmap (const pandoc') item
web/releases.markdownnew file+25
@@ -0,0 +1,25 @@
1+---
2+title: Releases
3+---
4+
5+## Hakyll 4.1.0.0
6+
7+*January 20, 2013*
8+
9+Update to use Pandoc 1.10, this requires changes to your `site.hs` if you're
10+using custom Pandoc options or the `Hakyll.Web.Pandoc.Biblio` module.
11+
12+- `defaultHakyllParserState` renamed to `defaultHakyllReaderOptions`
13+- The type of `readPandocBiblio` changed
14+
15+Because of the many changes, this release is no longer compatible with Pandoc
16+1.9.
17+
18+## Hakyll 4.0.0.0
19+
20+*January 16, 2013*
21+
22+The Initial release of Hakyll 4, see
23+[this blogpost](http://jaspervdj.be/posts/2013-01-16-hakyll-4.0.html) and
24+[the migration guide](/tutorials/hakyll-3-to-hakyll4-migration-guide.html) for
25+an overview of changes.
web/site.hs+1−1
@@ -43,7 +43,7 @@ main = hakyllWith config $ do
4343 -- Tutorials
4444 match "tutorials/*" $ do
4545 route $ setExtension "html"
46− compile $ pandocCompilerWith defaultHakyllParserState withToc
46+ compile $ pandocCompilerWith def withToc
4747 >>= loadAndApplyTemplate "templates/tutorial.html" defaultContext
4848 >>= loadAndApplyTemplate "templates/default.html" defaultContext
4949 >>= relativizeUrls
web/templates/default.html+1
@@ -33,6 +33,7 @@
3333 <a href="/about.html">about</a>
3434 <a href="/tutorials/faq.html">faq</a>
3535 <a href="/examples.html">examples</a>
36+ <a href="/releases.html">releases</a>
3637 <a href="/hakyll3">Hakyll 3.X</a>
3738
3839 <!-- Flattr button -->