4

I followed this tutorial to create a basic static web page using hakyll. It includes a number of pages rendered from markdown in the posts directory, e.g. 2015-08-12-spqr.markdown.

I prefer asciidoc to markdown, and tried adding an asciidoc 2018-01-23_adoc-user-manual.asciidoc to the post directory. However, hakyll throws an error when attempting to compile the page:

Initialising...
  Creating store...
  Creating provider...
  Running rules...
Checking for out-of-date items
Compiling
  updated templates/default.html
  updated about.rst
  updated templates/post.html
  updated posts/2015-08-12-spqr.markdown
  updated posts/2015-10-07-rosa-rosa-rosam.markdown
  updated posts/2015-11-28-carpe-diem.markdown
  updated posts/2015-12-07-tu-quoque.markdown
  [ERROR] Hakyll.Web.readPandocWith: I don't know how to read a file of the type Binary for: posts/2018-01-23_adoc-user-manual.asciidoc
CallStack (from HasCallStack):
  error, called at lib/Hakyll/Web/Pandoc.hs:66:31 in hakyll-4.12.5.0-8ZITvFN5YREEKv6B76SCAd:Hakyll.Web.Pandoc

Is this problem that pandocCompiler cannot handle asciidoc? Is it possible to use asciidoc with hakyll?

mherzl
  • 5,624
  • 6
  • 34
  • 75

1 Answers1

9

Current Pandoc can write Asciidoc but cannot read it: Issue.

Besides, there seems no Asciidoc parser written in Haskell, so there's no pure Haskell solution.

However, Hakyll has unixFilter which can use any command which inputs from stdin and outputs to stdout. Therefore, you can call asciidoctor command for converting .asciidoc file.

Here's the step:

1. Install asciidoctor

Ubuntu

$ apt-get install asciidoctor

Fedora

$ dnf install asciidoctor

Arch Linux

$ pacman -S asciidoctor

Ruby Gem

$ gem install asciidoctor

2. Define pandocCompilerWithAsciidoctor

Add following code to site.hs

pandocCompilerWithAsciidoctor :: Compiler (Item String)
pandocCompilerWithAsciidoctor = do
  extension <- getUnderlyingExtension
  if extension == ".asciidoc" then
    getResourceString >>= withItemBody (unixFilter "asciidoctor" ["-"])
  else
    pandocCompiler

replace pandocCompiler in site.hs with pandocCompilerWithAsciidoctor

3. Recompile

$ stack build
$ stack exec site rebuild

Note that filename have to be 2018-01-23-adoc-user-manual.asciidoc instead of 2018-01-23_adoc-user-manual.asciidoc, or you get error: [ERROR] Missing field $date$ in context for item posts/2018-01-23_adoc-user-manual.asciidoc

ymonad
  • 11,710
  • 1
  • 38
  • 49
  • I have the same [problem](https://github.com/jaspervdj/hakyll/issues/600) long time ago. Keep waiting for `pandoc` to support `asciidoc` since then. Thank to you, now I can try using `asciidoc` – wizzup Jan 26 '19 at 06:52
  • `unixFilter`, brilliant! I doubt I'd have been able to get asciidoc working without this helpful answer. Using `nixos` I additionally had to add `asciidoctor` to my nix packages in `stack.yaml`. Thank you! – mherzl Mar 14 '20 at 04:00
  • `asciidoc-hs` is an Haskell project for parsing `AsciiDoc` as far as I've seen – Hartmut Pfarr Jun 25 '22 at 17:15