haskell - pandoc 在 haskell 中包含文件过滤器

标签 haskell pandoc

我正在使用这个 haskell pandoc 包含文件过滤器

#!/usr/bin/env runhaskell
-- includes.hs
import Text.Pandoc.JSON

doInclude :: Block -> IO Block
doInclude cb@(CodeBlock (id, classes, namevals) contents) =
  case lookup "include" namevals of
       Just f     -> return . (CodeBlock (id, classes, namevals)) =<< readFile f
       Nothing    -> return cb
doInclude x = return x

main :: IO ()
main = toJSONFilter doInclude

在 markdown 中使用以下代码片段

~~~~ {include="tasks/mdbook.js"}
~~~~

实际上,这确实将文件包含到 Markdown 中,但我希望它还包含代码格式,例如

```js
file content here
```

我如何更新上面的 haskell 代码来完成这个?类似的东西

~~~~ {code="tasks/mdbook.js", format="js"}
~~~~

最佳答案

由于include过滤器保留了代码块的所有,因此您可以简单地包含文件内容并对其应用代码格式:

~~~~ {.javascript include="tasks/mdbook.js"}
~~~~

关于haskell - pandoc 在 haskell 中包含文件过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21584396/

相关文章:

haskell - 使用 pandoc 作为库时,什么可能导致 "commitAndReleaseBuffer: invalid argument (invalid character)"?

r - RStudio 中的 Knitr HTML 预览失败,尽管 render() 成功创建了 HTML 文件

pandoc - 可以在不指定模板的情况下向 docx 添加页码和页脚吗?

haskell - 在简单的 http get 示例中找不到模块 `Network.HTTP'

haskell - 找不到网络模块

Haskell:类型不匹配

html - Pandoc 将文件渲染到同一文件夹。我可以更改目标文件夹吗?

haskell - Quickcheck:生成一个由给定池中的字符组成的字符串

haskell - :reload and run :main as a single command in GHCi?的正确方法是什么

haskell - 使用 cabal 编译 pandoc 失败