diff options
Diffstat (limited to 'src/Hakyll/Web/Pandoc.hs')
-rw-r--r-- | src/Hakyll/Web/Pandoc.hs | 85 |
1 files changed, 48 insertions, 37 deletions
diff --git a/src/Hakyll/Web/Pandoc.hs b/src/Hakyll/Web/Pandoc.hs index 8b0e0de..7ebf4a2 100644 --- a/src/Hakyll/Web/Pandoc.hs +++ b/src/Hakyll/Web/Pandoc.hs @@ -1,5 +1,5 @@ --- | Module exporting pandoc bindings --- +-------------------------------------------------------------------------------- +-- | Module exporting convenientpandoc bindings module Hakyll.Web.Pandoc ( -- * The basic building blocks readPandoc @@ -19,34 +19,38 @@ module Hakyll.Web.Pandoc , defaultHakyllWriterOptions ) where -import Prelude hiding (id) -import Control.Applicative ((<$>)) -import Control.Arrow ((>>>), (>>^), (&&&), (***)) -import Control.Category (id) -import Data.Maybe (fromMaybe) -import Text.Pandoc +-------------------------------------------------------------------------------- +import Control.Arrow ((&&&), (***), (>>>), (>>^)) +import Control.Category (id) +import Data.Maybe (fromMaybe) +import Prelude hiding (id) +import Text.Pandoc -import Hakyll.Core.Compiler -import Hakyll.Core.Identifier -import Hakyll.Core.Util.Arrow -import Hakyll.Web.Pandoc.FileType -import Hakyll.Web.Page.Internal +-------------------------------------------------------------------------------- +import Hakyll.Core.Compiler +import Hakyll.Core.Identifier +import Hakyll.Core.Util.Arrow +import Hakyll.Web.Page.Internal +import Hakyll.Web.Pandoc.FileType + + +-------------------------------------------------------------------------------- -- | Read a string using pandoc, with the default options --- readPandoc :: FileType -- ^ Determines how parsing happens -> Maybe (Identifier a) -- ^ Optional, for better error messages - -> String -- ^ String to read + -> Page -- ^ String to read -> Pandoc -- ^ Resulting document readPandoc = readPandocWith defaultHakyllParserState + +-------------------------------------------------------------------------------- -- | Read a string using pandoc, with the supplied options --- readPandocWith :: ParserState -- ^ Parser options -> FileType -- ^ Determines parsing method -> Maybe (Identifier a) -- ^ Optional, for better error messages - -> String -- ^ String to read + -> Page -- ^ String to read -> Pandoc -- ^ Resulting document readPandocWith state fileType' id' = case fileType' of Html -> readHtml state @@ -60,54 +64,60 @@ readPandocWith state fileType' id' = case fileType' of "Hakyll.Web.readPandocWith: I don't know how to read a file of the " ++ "type " ++ show t ++ fromMaybe "" (fmap ((" for: " ++) . show) id') + +-------------------------------------------------------------------------------- -- | Write a document (as HTML) using pandoc, with the default options --- writePandoc :: Pandoc -- ^ Document to write - -> String -- ^ Resulting HTML + -> Page -- ^ Resulting HTML writePandoc = writePandocWith defaultHakyllWriterOptions + +-------------------------------------------------------------------------------- -- | Write a document (as HTML) using pandoc, with the supplied options --- writePandocWith :: WriterOptions -- ^ Writer options for pandoc -> Pandoc -- ^ Document to write - -> String -- ^ Resulting HTML + -> Page -- ^ Resulting HTML writePandocWith = writeHtmlString + +-------------------------------------------------------------------------------- -- | Read the resource using pandoc --- -pageReadPandoc :: Compiler (Page String) (Page Pandoc) +pageReadPandoc :: Compiler Page Pandoc pageReadPandoc = pageReadPandocWith defaultHakyllParserState + +-------------------------------------------------------------------------------- -- | Read the resource using pandoc --- -pageReadPandocWith :: ParserState -> Compiler (Page String) (Page Pandoc) +pageReadPandocWith :: ParserState -> Compiler Page Pandoc pageReadPandocWith state = constA state &&& id >>> pageReadPandocWithA + +-------------------------------------------------------------------------------- -- | Read the resource using pandoc. This is a (rarely needed) variant, which -- comes in very useful when the parser state is the result of some arrow. --- -pageReadPandocWithA :: Compiler (ParserState, Page String) (Page Pandoc) +pageReadPandocWithA :: Compiler (ParserState, Page) Pandoc pageReadPandocWithA = id *** id &&& getIdentifier &&& getFileType >>^ pageReadPandocWithA' where - pageReadPandocWithA' (s, (p, (i, t))) = readPandocWith s t (Just i) <$> p + pageReadPandocWithA' (s, (p, (i, t))) = readPandocWith s t (Just i) p + +-------------------------------------------------------------------------------- -- | Render the resource using pandoc --- -pageRenderPandoc :: Compiler (Page String) (Page String) +pageRenderPandoc :: Compiler Page Page pageRenderPandoc = pageRenderPandocWith defaultHakyllParserState defaultHakyllWriterOptions + +-------------------------------------------------------------------------------- -- | Render the resource using pandoc --- -pageRenderPandocWith :: ParserState - -> WriterOptions - -> Compiler (Page String) (Page String) +pageRenderPandocWith :: ParserState -> WriterOptions -> Compiler Page Page pageRenderPandocWith state options = - pageReadPandocWith state >>^ fmap (writePandocWith options) + pageReadPandocWith state >>^ writePandocWith options + +-------------------------------------------------------------------------------- -- | The default reader options for pandoc parsing in hakyll --- defaultHakyllParserState :: ParserState defaultHakyllParserState = defaultParserState { -- The following option causes pandoc to read smart typography, a nice @@ -115,8 +125,9 @@ defaultHakyllParserState = defaultParserState stateSmart = True } + +-------------------------------------------------------------------------------- -- | The default writer options for pandoc rendering in hakyll --- defaultHakyllWriterOptions :: WriterOptions defaultHakyllWriterOptions = defaultWriterOptions { -- This option causes literate haskell to be written using '>' marks in |