hakyll icon indicating copy to clipboard operation
hakyll copied to clipboard

Hakyll only supports `PandocPure` `PandocMonad`

Open colehaus opened this issue 7 years ago • 2 comments

In readPandocWith, runPure is used so pandoc is run in PandocPure. PandocPure doesn't support all pandoc functionality (in particular, I needed PandocIO so that pandoc would honor org mode includes).

Options I can imagine:

  • Add functionality to support running pandoc in IO (unsafeCompiler . runIO seems to Just Work.)
  • Document this behavior. It was definitely confusing for me when hakyll's pandoc behavior silently differed from directly running pandoc (pandoc from the CLI defaults to PandocIO)
  • Examine log messages in CommonState and print them or even crash if they're present

colehaus avatar May 10 '18 07:05 colehaus

Has this been addressed in newer versions? If not did you get a workaround for this?

HaoZeke avatar Feb 08 '19 00:02 HaoZeke

I import Text.Pandoc myself and wrap everything up with an unsafeCompiler:

-- Run pandoc in IO instead of purely so that we can work with org mode file includes
readPandocWith ::
     ReaderOptions -- ^ Parser options
  -> Item String -- ^ String to read
  -> Compiler (Item Pandoc) -- ^ Resulting document
readPandocWith ropt item =
  unsafeCompiler $
  runIO (traverse (reader ropt (itemFileType item)) (fmap T.pack item)) >>= \case
    Left err ->
      fail $ "Hakyll.Web.Pandoc.readPandocWith: parse failed: " ++ show err
    Right item' -> return item'
  where
    reader ro t =
      case t of
        DocBook -> readDocBook ro
        Html -> readHtml ro
        LaTeX -> readLaTeX ro
        LiterateHaskell t' -> reader (addExt ro Ext_literate_haskell) t'
        Markdown -> readMarkdown ro
        MediaWiki -> readMediaWiki ro
        OrgMode -> readOrg 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)
    addExt ro e =
      ro {readerExtensions = enableExtension e $ readerExtensions ro}

colehaus avatar Feb 11 '19 18:02 colehaus