diff options
-rw-r--r-- | hakyll.cabal | 6 | ||||
-rw-r--r-- | src/Hakyll/Web/Pandoc.hs | 63 | ||||
-rw-r--r-- | src/Hakyll/Web/Pandoc/Biblio.hs | 26 | ||||
-rw-r--r-- | web/releases.markdown | 25 | ||||
-rw-r--r-- | web/site.hs | 2 | ||||
-rw-r--r-- | web/templates/default.html | 1 |
6 files changed, 78 insertions, 45 deletions
diff --git a/hakyll.cabal b/hakyll.cabal index f33aa69..1af2122 100644 --- a/hakyll.cabal +++ b/hakyll.cabal @@ -1,5 +1,5 @@ Name: hakyll -Version: 4.0.0.0 +Version: 4.1.0.0 Synopsis: A static website compiler library Description: @@ -99,7 +99,7 @@ Library old-locale >= 1.0 && < 1.1, old-time >= 1.0 && < 1.2, cmdargs >= 0.10 && < 0.11, - pandoc >= 1.9.3 && < 1.10, + pandoc >= 1.10 && < 1.11, parsec >= 3.0 && < 3.2, process >= 1.0 && < 1.2, random >= 1.0 && < 1.1, @@ -198,7 +198,7 @@ Test-suite hakyll-tests old-locale >= 1.0 && < 1.1, old-time >= 1.0 && < 1.2, cmdargs >= 0.10 && < 0.11, - pandoc >= 1.9.3 && < 1.10, + pandoc >= 1.0 && < 1.11, parsec >= 3.0 && < 3.2, process >= 1.0 && < 1.2, random >= 1.0 && < 1.1, diff --git a/src/Hakyll/Web/Pandoc.hs b/src/Hakyll/Web/Pandoc.hs index 82784be..47972f5 100644 --- a/src/Hakyll/Web/Pandoc.hs +++ b/src/Hakyll/Web/Pandoc.hs @@ -15,13 +15,14 @@ module Hakyll.Web.Pandoc , pandocCompilerWithTransform -- * Default options - , defaultHakyllParserState + , defaultHakyllReaderOptions , defaultHakyllWriterOptions ) where -------------------------------------------------------------------------------- import Control.Applicative ((<$>)) +import qualified Data.Set as S import Text.Pandoc @@ -35,26 +36,28 @@ import Hakyll.Web.Pandoc.FileType -- | Read a string using pandoc, with the default options readPandoc :: Item String -- ^ String to read -> Item Pandoc -- ^ Resulting document -readPandoc = readPandocWith defaultHakyllParserState +readPandoc = readPandocWith defaultHakyllReaderOptions -------------------------------------------------------------------------------- -- | Read a string using pandoc, with the supplied options -readPandocWith :: ParserState -- ^ Parser options - -> Item String -- ^ String to read - -> Item Pandoc -- ^ Resulting document -readPandocWith state item = fmap (reader state (itemFileType item)) item +readPandocWith :: ReaderOptions -- ^ Parser options + -> Item String -- ^ String to read + -> Item Pandoc -- ^ Resulting document +readPandocWith ropt item = fmap (reader ropt (itemFileType item)) item where - reader s t = case t of - Html -> readHtml s - LaTeX -> readLaTeX s - LiterateHaskell t' -> reader s {stateLiterateHaskell = True} t' - Markdown -> readMarkdown s - Rst -> readRST s - Textile -> readTextile s + reader ro t = case t of + Html -> readHtml ro + LaTeX -> readLaTeX ro + LiterateHaskell t' -> reader (addExt ro Ext_literate_haskell) t' + Markdown -> readMarkdown ro + Rst -> readRST ro + Textile -> readTextile ro _ -> error $ - "Hakyll.Web.readPandocWith: I don't know how to read a file of the " ++ - "type " ++ show t ++ " for: " ++ show (itemIdentifier item) + "Hakyll.Web.readPandocWith: I don't know how to read a file of " ++ + "the type " ++ show t ++ " for: " ++ show (itemIdentifier item) + + addExt ro e = ro {readerExtensions = S.insert e $ readerExtensions ro} -------------------------------------------------------------------------------- @@ -69,63 +72,63 @@ writePandoc = writePandocWith defaultHakyllWriterOptions writePandocWith :: WriterOptions -- ^ Writer options for pandoc -> Item Pandoc -- ^ Document to write -> Item String -- ^ Resulting HTML -writePandocWith options = fmap $ writeHtmlString options +writePandocWith wopt = fmap $ writeHtmlString wopt -------------------------------------------------------------------------------- -- | Render the resource using pandoc renderPandoc :: Item String -> Item String renderPandoc = - renderPandocWith defaultHakyllParserState defaultHakyllWriterOptions + renderPandocWith defaultHakyllReaderOptions defaultHakyllWriterOptions -------------------------------------------------------------------------------- -- | Render the resource using pandoc -renderPandocWith :: ParserState -> WriterOptions -> Item String -> Item String -renderPandocWith state options = writePandocWith options . readPandocWith state +renderPandocWith :: ReaderOptions -> WriterOptions -> Item String -> Item String +renderPandocWith ropt wopt = writePandocWith wopt . readPandocWith ropt -------------------------------------------------------------------------------- -- | Read a page render using pandoc pandocCompiler :: Compiler (Item String) pandocCompiler = - pandocCompilerWith defaultHakyllParserState defaultHakyllWriterOptions + pandocCompilerWith defaultHakyllReaderOptions defaultHakyllWriterOptions -------------------------------------------------------------------------------- -- | A version of 'pandocCompiler' which allows you to specify your own pandoc -- options -pandocCompilerWith :: ParserState -> WriterOptions -> Compiler (Item String) -pandocCompilerWith state options = pandocCompilerWithTransform state options id +pandocCompilerWith :: ReaderOptions -> WriterOptions -> Compiler (Item String) +pandocCompilerWith ropt wopt = pandocCompilerWithTransform ropt wopt id -------------------------------------------------------------------------------- -- | An extension of 'pandocCompilerWith' which allows you to specify a custom -- pandoc transformation for the content -pandocCompilerWithTransform :: ParserState -> WriterOptions +pandocCompilerWithTransform :: ReaderOptions -> WriterOptions -> (Pandoc -> Pandoc) -> Compiler (Item String) -pandocCompilerWithTransform state options f = cached cacheName $ - writePandocWith options . fmap f . readPandocWith state <$> getResourceBody +pandocCompilerWithTransform ropt wopt f = cached cacheName $ + writePandocWith wopt . fmap f . readPandocWith ropt <$> getResourceBody where cacheName = "Hakyll.Web.Page.pageCompilerWithPandoc" -------------------------------------------------------------------------------- -- | The default reader options for pandoc parsing in hakyll -defaultHakyllParserState :: ParserState -defaultHakyllParserState = defaultParserState +defaultHakyllReaderOptions :: ReaderOptions +defaultHakyllReaderOptions = def { -- The following option causes pandoc to read smart typography, a nice -- and free bonus. - stateSmart = True + readerSmart = True } -------------------------------------------------------------------------------- -- | The default writer options for pandoc rendering in hakyll defaultHakyllWriterOptions :: WriterOptions -defaultHakyllWriterOptions = defaultWriterOptions +defaultHakyllWriterOptions = def { -- This option causes literate haskell to be written using '>' marks in -- html, which I think is a good default. - writerLiterateHaskell = True + writerExtensions = S.insert Ext_literate_haskell (writerExtensions def) } diff --git a/src/Hakyll/Web/Pandoc/Biblio.hs b/src/Hakyll/Web/Pandoc/Biblio.hs index 8c284a0..9c4b0bf 100644 --- a/src/Hakyll/Web/Pandoc/Biblio.hs +++ b/src/Hakyll/Web/Pandoc/Biblio.hs @@ -5,8 +5,8 @@ -- @.bib@) and a CSL file (@.csl@). Both need to be compiled with their -- respective compilers ('biblioCompiler' and 'cslCompiler'). Then, you can -- refer to these files when you use 'pageReadPandocBiblio'. This function also --- takes a parser state for completeness -- you can use --- 'defaultHakyllParserState' if you're unsure. +-- takes the reader options for completeness -- you can use +-- 'defaultHakyllReaderOptions' if you're unsure. {-# LANGUAGE Arrows #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} @@ -22,9 +22,10 @@ module Hakyll.Web.Pandoc.Biblio -------------------------------------------------------------------------------- import Control.Applicative ((<$>)) import Data.Binary (Binary (..)) +import Data.Traversable (traverse) import Data.Typeable (Typeable) import qualified Text.CSL as CSL -import Text.Pandoc (Pandoc, ParserState (..)) +import Text.Pandoc (Pandoc, ReaderOptions (..)) import Text.Pandoc.Biblio (processBiblio) @@ -84,19 +85,22 @@ biblioCompiler = do -------------------------------------------------------------------------------- -readPandocBiblio :: ParserState - -> Item CSL +readPandocBiblio :: ReaderOptions + -> Maybe (Item CSL) -> Item Biblio -> (Item String) -> Compiler (Item Pandoc) -readPandocBiblio state csl biblio item = do +readPandocBiblio ropt csl biblio item = do + -- Parse CSL file, if given + style <- unsafeCompiler $ + traverse (CSL.readCSLFile . toFilePath . itemIdentifier) csl + -- We need to know the citation keys, add then *before* actually parsing the -- actual page. If we don't do this, pandoc won't even consider them -- citations! let Biblio refs = itemBody biblio - cits = map CSL.refId refs - state' = state {stateCitations = stateCitations state ++ cits} - pandoc = itemBody $ readPandocWith state' item - cslPath = toFilePath $ itemIdentifier csl - pandoc' <- unsafeCompiler $ processBiblio cslPath Nothing refs pandoc + ropt' = ropt {readerReferences = readerReferences ropt ++ refs} + pandoc = itemBody $ readPandocWith ropt' item + pandoc' = processBiblio style refs pandoc + return $ fmap (const pandoc') item diff --git a/web/releases.markdown b/web/releases.markdown new file mode 100644 index 0000000..6ee53e1 --- /dev/null +++ b/web/releases.markdown @@ -0,0 +1,25 @@ +--- +title: Releases +--- + +## Hakyll 4.1.0.0 + +*January 20, 2013* + +Update to use Pandoc 1.10, this requires changes to your `site.hs` if you're +using custom Pandoc options or the `Hakyll.Web.Pandoc.Biblio` module. + +- `defaultHakyllParserState` renamed to `defaultHakyllReaderOptions` +- The type of `readPandocBiblio` changed + +Because of the many changes, this release is no longer compatible with Pandoc +1.9. + +## Hakyll 4.0.0.0 + +*January 16, 2013* + +The Initial release of Hakyll 4, see +[this blogpost](http://jaspervdj.be/posts/2013-01-16-hakyll-4.0.html) and +[the migration guide](/tutorials/hakyll-3-to-hakyll4-migration-guide.html) for +an overview of changes. diff --git a/web/site.hs b/web/site.hs index 8ff1712..45e6519 100644 --- a/web/site.hs +++ b/web/site.hs @@ -43,7 +43,7 @@ main = hakyllWith config $ do -- Tutorials match "tutorials/*" $ do route $ setExtension "html" - compile $ pandocCompilerWith defaultHakyllParserState withToc + compile $ pandocCompilerWith def withToc >>= loadAndApplyTemplate "templates/tutorial.html" defaultContext >>= loadAndApplyTemplate "templates/default.html" defaultContext >>= relativizeUrls diff --git a/web/templates/default.html b/web/templates/default.html index fbf84a0..320ff08 100644 --- a/web/templates/default.html +++ b/web/templates/default.html @@ -33,6 +33,7 @@ <a href="/about.html">about</a> <a href="/tutorials/faq.html">faq</a> <a href="/examples.html">examples</a> + <a href="/releases.html">releases</a> <a href="/hakyll3">Hakyll 3.X</a> <!-- Flattr button --> |