module Hakyll.Web.Pandoc
(
readPandoc
, readPandocWith
, writePandoc
, writePandocWith
, renderPandoc
, renderPandocWith
, renderPandocWithTransform
, renderPandocWithTransformM
, pandocCompiler
, pandocCompilerWith
, pandocCompilerWithTransform
, pandocCompilerWithTransformM
, defaultHakyllReaderOptions
, defaultHakyllWriterOptions
) where
import qualified Data.Text as T
import Text.Pandoc
import Text.Pandoc.Highlighting (pygments)
import Hakyll.Core.Compiler
import Hakyll.Core.Item
import Hakyll.Web.Pandoc.FileType
readPandoc
:: Item String
-> Compiler (Item Pandoc)
readPandoc :: Item String -> Compiler (Item Pandoc)
readPandoc = ReaderOptions -> Item String -> Compiler (Item Pandoc)
readPandocWith ReaderOptions
defaultHakyllReaderOptions
readPandocWith
:: ReaderOptions
-> Item String
-> Compiler (Item Pandoc)
readPandocWith :: ReaderOptions -> Item String -> Compiler (Item Pandoc)
readPandocWith ReaderOptions
ropt Item String
item =
case PandocPure (Item Pandoc) -> Either PandocError (Item Pandoc)
forall a. PandocPure a -> Either PandocError a
runPure (PandocPure (Item Pandoc) -> Either PandocError (Item Pandoc))
-> PandocPure (Item Pandoc) -> Either PandocError (Item Pandoc)
forall a b. (a -> b) -> a -> b
$ (Text -> PandocPure Pandoc)
-> Item Text -> PandocPure (Item Pandoc)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (ReaderOptions -> FileType -> Text -> PandocPure Pandoc
forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> FileType -> a -> m Pandoc
reader ReaderOptions
ropt (Item String -> FileType
forall a. Item a -> FileType
itemFileType Item String
item)) ((String -> Text) -> Item String -> Item Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Text
T.pack Item String
item) of
Left PandocError
err -> String -> Compiler (Item Pandoc)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Compiler (Item Pandoc))
-> String -> Compiler (Item Pandoc)
forall a b. (a -> b) -> a -> b
$
String
"Hakyll.Web.Pandoc.readPandocWith: parse failed: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ PandocError -> String
forall a. Show a => a -> String
show PandocError
err
Right Item Pandoc
item' -> Item Pandoc -> Compiler (Item Pandoc)
forall (m :: * -> *) a. Monad m => a -> m a
return Item Pandoc
item'
where
reader :: ReaderOptions -> FileType -> a -> m Pandoc
reader ReaderOptions
ro FileType
t = case FileType
t of
FileType
DocBook -> ReaderOptions -> a -> m Pandoc
forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> a -> m Pandoc
readDocBook ReaderOptions
ro
FileType
Html -> ReaderOptions -> a -> m Pandoc
forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> a -> m Pandoc
readHtml ReaderOptions
ro
FileType
Jupyter -> ReaderOptions -> a -> m Pandoc
forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> a -> m Pandoc
readIpynb ReaderOptions
ro
FileType
LaTeX -> ReaderOptions -> a -> m Pandoc
forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> a -> m Pandoc
readLaTeX ReaderOptions
ro
LiterateHaskell FileType
t' -> ReaderOptions -> FileType -> a -> m Pandoc
reader (ReaderOptions -> Extension -> ReaderOptions
addExt ReaderOptions
ro Extension
Ext_literate_haskell) FileType
t'
FileType
Markdown -> ReaderOptions -> a -> m Pandoc
forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> a -> m Pandoc
readMarkdown ReaderOptions
ro
FileType
MediaWiki -> ReaderOptions -> a -> m Pandoc
forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> a -> m Pandoc
readMediaWiki ReaderOptions
ro
FileType
OrgMode -> ReaderOptions -> a -> m Pandoc
forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> a -> m Pandoc
readOrg ReaderOptions
ro
FileType
Rst -> ReaderOptions -> a -> m Pandoc
forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> a -> m Pandoc
readRST ReaderOptions
ro
FileType
Textile -> ReaderOptions -> a -> m Pandoc
forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> a -> m Pandoc
readTextile ReaderOptions
ro
FileType
_ -> String -> a -> m Pandoc
forall a. HasCallStack => String -> a
error (String -> a -> m Pandoc) -> String -> a -> m Pandoc
forall a b. (a -> b) -> a -> b
$
String
"Hakyll.Web.readPandocWith: I don't know how to read a file of " String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"the type " String -> String -> String
forall a. [a] -> [a] -> [a]
++ FileType -> String
forall a. Show a => a -> String
show FileType
t String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" for: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Identifier -> String
forall a. Show a => a -> String
show (Item String -> Identifier
forall a. Item a -> Identifier
itemIdentifier Item String
item)
addExt :: ReaderOptions -> Extension -> ReaderOptions
addExt ReaderOptions
ro Extension
e = ReaderOptions
ro {readerExtensions :: Extensions
readerExtensions = Extension -> Extensions -> Extensions
enableExtension Extension
e (Extensions -> Extensions) -> Extensions -> Extensions
forall a b. (a -> b) -> a -> b
$ ReaderOptions -> Extensions
readerExtensions ReaderOptions
ro}
writePandoc :: Item Pandoc
-> Item String
writePandoc :: Item Pandoc -> Item String
writePandoc = WriterOptions -> Item Pandoc -> Item String
writePandocWith WriterOptions
defaultHakyllWriterOptions
writePandocWith :: WriterOptions
-> Item Pandoc
-> Item String
writePandocWith :: WriterOptions -> Item Pandoc -> Item String
writePandocWith WriterOptions
wopt (Item Identifier
itemi Pandoc
doc) =
case PandocPure Text -> Either PandocError Text
forall a. PandocPure a -> Either PandocError a
runPure (PandocPure Text -> Either PandocError Text)
-> PandocPure Text -> Either PandocError Text
forall a b. (a -> b) -> a -> b
$ WriterOptions -> Pandoc -> PandocPure Text
forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Pandoc -> m Text
writeHtml5String WriterOptions
wopt Pandoc
doc of
Left PandocError
err -> String -> Item String
forall a. HasCallStack => String -> a
error (String -> Item String) -> String -> Item String
forall a b. (a -> b) -> a -> b
$ String
"Hakyll.Web.Pandoc.writePandocWith: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ PandocError -> String
forall a. Show a => a -> String
show PandocError
err
Right Text
item' -> Identifier -> String -> Item String
forall a. Identifier -> a -> Item a
Item Identifier
itemi (String -> Item String) -> String -> Item String
forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack Text
item'
renderPandoc :: Item String -> Compiler (Item String)
renderPandoc :: Item String -> Compiler (Item String)
renderPandoc =
ReaderOptions
-> WriterOptions -> Item String -> Compiler (Item String)
renderPandocWith ReaderOptions
defaultHakyllReaderOptions WriterOptions
defaultHakyllWriterOptions
renderPandocWith
:: ReaderOptions -> WriterOptions -> Item String -> Compiler (Item String)
renderPandocWith :: ReaderOptions
-> WriterOptions -> Item String -> Compiler (Item String)
renderPandocWith ReaderOptions
ropt WriterOptions
wopt Item String
item =
WriterOptions -> Item Pandoc -> Item String
writePandocWith WriterOptions
wopt (Item Pandoc -> Item String)
-> Compiler (Item Pandoc) -> Compiler (Item String)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderOptions -> Item String -> Compiler (Item Pandoc)
readPandocWith ReaderOptions
ropt Item String
item
renderPandocWithTransform :: ReaderOptions -> WriterOptions
-> (Pandoc -> Pandoc)
-> Item String
-> Compiler (Item String)
renderPandocWithTransform :: ReaderOptions
-> WriterOptions
-> (Pandoc -> Pandoc)
-> Item String
-> Compiler (Item String)
renderPandocWithTransform ReaderOptions
ropt WriterOptions
wopt Pandoc -> Pandoc
f =
ReaderOptions
-> WriterOptions
-> (Pandoc -> Compiler Pandoc)
-> Item String
-> Compiler (Item String)
renderPandocWithTransformM ReaderOptions
ropt WriterOptions
wopt (Pandoc -> Compiler Pandoc
forall (m :: * -> *) a. Monad m => a -> m a
return (Pandoc -> Compiler Pandoc)
-> (Pandoc -> Pandoc) -> Pandoc -> Compiler Pandoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pandoc -> Pandoc
f)
renderPandocWithTransformM :: ReaderOptions -> WriterOptions
-> (Pandoc -> Compiler Pandoc)
-> Item String
-> Compiler (Item String)
renderPandocWithTransformM :: ReaderOptions
-> WriterOptions
-> (Pandoc -> Compiler Pandoc)
-> Item String
-> Compiler (Item String)
renderPandocWithTransformM ReaderOptions
ropt WriterOptions
wopt Pandoc -> Compiler Pandoc
f Item String
i =
WriterOptions -> Item Pandoc -> Item String
writePandocWith WriterOptions
wopt (Item Pandoc -> Item String)
-> Compiler (Item Pandoc) -> Compiler (Item String)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Pandoc -> Compiler Pandoc)
-> Item Pandoc -> Compiler (Item Pandoc)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Pandoc -> Compiler Pandoc
f (Item Pandoc -> Compiler (Item Pandoc))
-> Compiler (Item Pandoc) -> Compiler (Item Pandoc)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ReaderOptions -> Item String -> Compiler (Item Pandoc)
readPandocWith ReaderOptions
ropt Item String
i)
pandocCompiler :: Compiler (Item String)
pandocCompiler :: Compiler (Item String)
pandocCompiler =
ReaderOptions -> WriterOptions -> Compiler (Item String)
pandocCompilerWith ReaderOptions
defaultHakyllReaderOptions WriterOptions
defaultHakyllWriterOptions
pandocCompilerWith :: ReaderOptions -> WriterOptions -> Compiler (Item String)
pandocCompilerWith :: ReaderOptions -> WriterOptions -> Compiler (Item String)
pandocCompilerWith ReaderOptions
ropt WriterOptions
wopt =
String -> Compiler (Item String) -> Compiler (Item String)
forall a.
(Binary a, Typeable a) =>
String -> Compiler a -> Compiler a
cached String
"Hakyll.Web.Pandoc.pandocCompilerWith" (Compiler (Item String) -> Compiler (Item String))
-> Compiler (Item String) -> Compiler (Item String)
forall a b. (a -> b) -> a -> b
$
ReaderOptions
-> WriterOptions -> (Pandoc -> Pandoc) -> Compiler (Item String)
pandocCompilerWithTransform ReaderOptions
ropt WriterOptions
wopt Pandoc -> Pandoc
forall a. a -> a
id
pandocCompilerWithTransform :: ReaderOptions -> WriterOptions
-> (Pandoc -> Pandoc)
-> Compiler (Item String)
pandocCompilerWithTransform :: ReaderOptions
-> WriterOptions -> (Pandoc -> Pandoc) -> Compiler (Item String)
pandocCompilerWithTransform ReaderOptions
ropt WriterOptions
wopt Pandoc -> Pandoc
f =
ReaderOptions
-> WriterOptions
-> (Pandoc -> Compiler Pandoc)
-> Compiler (Item String)
pandocCompilerWithTransformM ReaderOptions
ropt WriterOptions
wopt (Pandoc -> Compiler Pandoc
forall (m :: * -> *) a. Monad m => a -> m a
return (Pandoc -> Compiler Pandoc)
-> (Pandoc -> Pandoc) -> Pandoc -> Compiler Pandoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pandoc -> Pandoc
f)
pandocCompilerWithTransformM :: ReaderOptions -> WriterOptions
-> (Pandoc -> Compiler Pandoc)
-> Compiler (Item String)
pandocCompilerWithTransformM :: ReaderOptions
-> WriterOptions
-> (Pandoc -> Compiler Pandoc)
-> Compiler (Item String)
pandocCompilerWithTransformM ReaderOptions
ropt WriterOptions
wopt Pandoc -> Compiler Pandoc
f =
Compiler (Item String)
getResourceBody Compiler (Item String)
-> (Item String -> Compiler (Item String))
-> Compiler (Item String)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ReaderOptions
-> WriterOptions
-> (Pandoc -> Compiler Pandoc)
-> Item String
-> Compiler (Item String)
renderPandocWithTransformM ReaderOptions
ropt WriterOptions
wopt Pandoc -> Compiler Pandoc
f
defaultHakyllReaderOptions :: ReaderOptions
defaultHakyllReaderOptions :: ReaderOptions
defaultHakyllReaderOptions = ReaderOptions
forall a. Default a => a
def
{
readerExtensions :: Extensions
readerExtensions = Extension -> Extensions -> Extensions
enableExtension Extension
Ext_smart Extensions
pandocExtensions
}
defaultHakyllWriterOptions :: WriterOptions
defaultHakyllWriterOptions :: WriterOptions
defaultHakyllWriterOptions = WriterOptions
forall a. Default a => a
def
{
writerExtensions :: Extensions
writerExtensions = Extension -> Extensions -> Extensions
enableExtension Extension
Ext_smart Extensions
pandocExtensions
,
writerHighlightStyle :: Maybe Style
writerHighlightStyle = Style -> Maybe Style
forall a. a -> Maybe a
Just Style
pygments
,
writerWrapText :: WrapOption
writerWrapText = WrapOption
WrapPreserve
}