summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web/Pandoc.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-11-18 21:56:52 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2012-11-18 21:56:52 +0100
commit877cb21d1630d32c6e40eb7c6f0ecc7e1da2bd52 (patch)
tree57ce11325adbbb7502086450dd1d1a9f1e81b8f2 /src/Hakyll/Web/Pandoc.hs
parent1347b0fa6cdd98986f927368e76e849068f69e1a (diff)
downloadhakyll-877cb21d1630d32c6e40eb7c6f0ecc7e1da2bd52.tar.gz
Add Item abstraction
Diffstat (limited to 'src/Hakyll/Web/Pandoc.hs')
-rw-r--r--src/Hakyll/Web/Pandoc.hs87
1 files changed, 30 insertions, 57 deletions
diff --git a/src/Hakyll/Web/Pandoc.hs b/src/Hakyll/Web/Pandoc.hs
index caada26..c2319dc 100644
--- a/src/Hakyll/Web/Pandoc.hs
+++ b/src/Hakyll/Web/Pandoc.hs
@@ -6,12 +6,8 @@ module Hakyll.Web.Pandoc
, readPandocWith
, writePandoc
, writePandocWith
-
- -- * Functions working on pages/compilers
- , pageReadPandoc
- , pageReadPandocWith
- , pageRenderPandoc
- , pageRenderPandocWith
+ , renderPandoc
+ , renderPandocWith
-- * Default options
, defaultHakyllParserState
@@ -20,89 +16,66 @@ module Hakyll.Web.Pandoc
--------------------------------------------------------------------------------
-import Control.Applicative ((<$>))
-import Data.Maybe (fromMaybe)
import Text.Pandoc
--------------------------------------------------------------------------------
-import Hakyll.Core.Compiler
-import Hakyll.Core.Identifier
-import Hakyll.Web.Page.Internal
+import Hakyll.Core.Item
import Hakyll.Web.Pandoc.FileType
--------------------------------------------------------------------------------
-- | Read a string using pandoc, with the default options
-readPandoc :: FileType -- ^ Determines how parsing happens
- -> Maybe Identifier -- ^ Optional, for better error messages
- -> Page -- ^ String to read
- -> Pandoc -- ^ Resulting document
+readPandoc :: Item String -- ^ String to read
+ -> Item 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 -- ^ Optional, for better error messages
- -> Page -- ^ String to read
- -> Pandoc -- ^ Resulting document
-readPandocWith state fileType' id' = case fileType' of
- Html -> readHtml state
- LaTeX -> readLaTeX state
- LiterateHaskell t ->
- readPandocWith state {stateLiterateHaskell = True} t id'
- Markdown -> readMarkdown state
- Rst -> readRST state
- Textile -> readTextile state
- t -> error $
- "Hakyll.Web.readPandocWith: I don't know how to read a file of the " ++
- "type " ++ show t ++ fromMaybe "" (fmap ((" for: " ++) . show) id')
+readPandocWith :: ParserState -- ^ Parser options
+ -> Item String -- ^ String to read
+ -> Item Pandoc -- ^ Resulting document
+readPandocWith state item = fmap (reader state (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
+ _ -> error $
+ "Hakyll.Web.readPandocWith: I don't know how to read a file of the " ++
+ "type " ++ show t ++ " for: " ++ show (itemIdentifier item)
--------------------------------------------------------------------------------
-- | Write a document (as HTML) using pandoc, with the default options
-writePandoc :: Pandoc -- ^ Document to write
- -> Page -- ^ Resulting HTML
+writePandoc :: Item Pandoc -- ^ Document to write
+ -> Item String -- ^ 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
- -> Page -- ^ Resulting HTML
-writePandocWith = writeHtmlString
-
-
---------------------------------------------------------------------------------
--- | Read the resource using pandoc
-pageReadPandoc :: Page -> Compiler Pandoc
-pageReadPandoc = pageReadPandocWith defaultHakyllParserState
-
-
---------------------------------------------------------------------------------
--- | Read the resource using pandoc
-pageReadPandocWith :: ParserState -> Page -> Compiler Pandoc
-pageReadPandocWith state page = do
- identifier <- getIdentifier
- fileType' <- getFileType
- return $ readPandocWith state fileType' (Just identifier) page
+ -> Item Pandoc -- ^ Document to write
+ -> Item String -- ^ Resulting HTML
+writePandocWith options = fmap $ writeHtmlString options
--------------------------------------------------------------------------------
-- | Render the resource using pandoc
-pageRenderPandoc :: Page -> Compiler Page
-pageRenderPandoc =
- pageRenderPandocWith defaultHakyllParserState defaultHakyllWriterOptions
+renderPandoc :: Item String -> Item String
+renderPandoc =
+ renderPandocWith defaultHakyllParserState defaultHakyllWriterOptions
--------------------------------------------------------------------------------
-- | Render the resource using pandoc
-pageRenderPandocWith :: ParserState -> WriterOptions -> Page -> Compiler Page
-pageRenderPandocWith state options page =
- writePandocWith options <$> pageReadPandocWith state page
+renderPandocWith :: ParserState -> WriterOptions -> Item String -> Item String
+renderPandocWith state options = writePandocWith options . readPandocWith state
--------------------------------------------------------------------------------