首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可以将asciidoc与hakyll一起使用吗?

可以将asciidoc与hakyll一起使用吗?
EN

Stack Overflow用户
提问于 2019-01-24 10:08:19
回答 1查看 282关注 0票数 3

我跟随this tutorial使用hakyll创建了一个基本的静态网页。它包括许多从posts目录中的markdown呈现的页面,例如2015-08-12-spqr.markdown

我更喜欢asciidoc而不是markdown,并尝试在post目录中添加一个asciidoc 2018-01-23_adoc-user-manual.asciidoc。但是,在尝试编译页面时,hakyll会抛出错误:

代码语言:javascript
复制
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

这个问题是不是pandocCompiler不能处理asciidoc?是否可以在hakyll中使用asciidoc

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-24 12:16:00

当前的Pandoc可以写Asciidoc,但不能读它:Issue

此外,似乎没有用Haskell编写的Asciidoc解析器,所以没有纯粹的Haskell解决方案。

然而,Hakyll有unixFilter,它可以使用从标准输入和输出到标准输出的任何命令。因此,您可以调用asciidoctor命令来转换.asciidoc文件。

下面是步骤:

1.安装asciidoctor

Ubuntu

$ apt-get install asciidoctor

软呢帽

$ dnf install asciidoctor

Arch Linux

$ pacman -S asciidoctor

红宝石

$ gem install asciidoctor

2.定义pandocCompilerWithAsciidoctor

将以下代码添加到site.hs

代码语言:javascript
复制
pandocCompilerWithAsciidoctor :: Compiler (Item String)
pandocCompilerWithAsciidoctor = do
  extension <- getUnderlyingExtension
  if extension == ".asciidoc" then
    getResourceString >>= withItemBody (unixFilter "asciidoctor" ["-"])
  else
    pandocCompiler

site.hs中的pandocCompiler替换为pandocCompilerWithAsciidoctor

3.重新编译

代码语言:javascript
复制
$ stack build
$ stack exec site rebuild

请注意,文件名必须是2018-01-23-adoc-user-manual.asciidoc而不是2018-01-23_adoc-user-manual.asciidoc,否则将出现错误:[ERROR] Missing field $date$ in context for item posts/2018-01-23_adoc-user-manual.asciidoc

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54338415

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档