diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2013-01-20 09:35:39 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2013-01-20 09:35:39 +0100 |
commit | 064128305e5e1a99d20afa62331c7a3bdf566c8a (patch) | |
tree | 641211bb47064fdde9ddfeb53b07bdde11e1c857 /src/Hakyll/Web | |
parent | 21b897a6827cdcee8c5d2b11932250202e96a2f4 (diff) | |
download | hakyll-064128305e5e1a99d20afa62331c7a3bdf566c8a.tar.gz |
Update to use pandoc 1.9
Diffstat (limited to 'src/Hakyll/Web')
-rw-r--r-- | src/Hakyll/Web/Pandoc.hs | 63 | ||||
-rw-r--r-- | src/Hakyll/Web/Pandoc/Biblio.hs | 26 |
2 files changed, 48 insertions, 41 deletions
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 |