You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

pandoc-citeproc API的processCites'未生成参考文献问题排查

Pandoc Haskell API处理参考文献失效的问题

我最近碰到个头疼的问题:用Haskell里的Pandoc API处理带参考文献的Markdown文件时,参考文献完全没被解析出来,但用命令行pandoc却能正常工作。

先说说我的场景:我有个叫postWithReference.md的Markdown文件,内容是这样的:

---
title: postWithReference
author: auf
date: 2010-07-29
keywords: homepage
abstract: |
  What are the objects of ontologists .
bibliography: "/home/frank/Workspace8/SSG/site/resources/BibTexLatex.bib"
csl: "/home/frank/Workspace8/SSG/site/resources/chicago-fullnote-bibliography-bb.csl"
---
An example post. With a reference to [@Frank2010a] and more[@navratil08].
## References

我用Haskell代码里的processCites'函数处理这个文件生成的Pandoc数据,按道理这个函数应该从文件元数据里读取bibliography和csl配置来解析参考文献,但处理完结果和输入完全一样,参考文献根本没被处理,而且过程还没报错。

但我用命令行跑下面的命令时,参考文献却能正常解析生成:

pandoc -f markdown -t html --filter=pandoc-citeproc -o p1.html postWithReference.md

显然问题出在我的API调用逻辑上,我的代码是这样的:

markdownToHTML4 :: Text -> PandocIO Value
markdownToHTML4 t = do
  pandoc <- readMarkdown markdownOptions t
  let meta2 = flattenMeta (getMeta pandoc)
  -- test if biblio is present and apply
  let bib = Just $ ( meta2) ^? key "bibliography" . _String
  pandoc2 <- case bib of
    Nothing -> return pandoc
    _ -> do
      res <- liftIO $ processCites' pandoc
      -- :: Pandoc -> IO Pandoc
      when (res == pandoc) $ liftIO $ putStrLn "*** markdownToHTML3 result without references ***"
      return res
  htmltex <- writeHtml5String html5Options pandoc2
  let withContent = ( meta2) & _Object . at "contentHtml" ?~ String ( htmltex)
  return withContent
getMeta :: Pandoc -> Meta
getMeta (Pandoc m _) = m

我想知道我对Pandoc API的理解哪里错了?是不是需要给阅读器设置特定的选项才能让citeproc识别参考文献?另外我的参考文献是BibLatex格式的。

还有,我在Hakyll的代码里看到一段注释,完全搞不懂它的意思,能不能帮忙解释下:

We need to know the citation keys, add then before actually parsing the
actual page. If we don't do this, pandoc won't even consider them
citations!

内容的提问来源于stack exchange,提问作者user855443

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 09:08:07