我如何在 Haskell 中使用 Pandoc 的 Citeproc 处理引文?

How can I process citations using Pandoc's Citeproc, in Haskell?

"A Simple Example" from the Pandoc documentation, I want to add citation processing functionality. The docs for Text.Pandoc.Citeproc 开始显示一个函数 processCitations,据称可以处理引文。然而,给定简单的组织模式输入和引用 [@test2022],它似乎不起作用。它编译并运行得很好,但下面代码的输出是:<p><span class="spurious-link" target="url"><em>testing</em></span> [@test2022]</p>,即引用实际上没有被处理。我究竟做错了什么?我怎样才能让它处理我的引文?

import Text.Pandoc
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import Text.Pandoc.Filter
import Text.Pandoc.Citeproc

main :: IO ()
main = do
  result <- runIO $ do
    doc <- readOrg def (T.pack "#+bibliography: test.bib\n [[url][testing]]\n[@test2022]")
    processed <- processCitations doc
    writeHtml5String def processed
  html <- handleError result
  TIO.putStrLn html

作为参考,这是我的 test.bib bibtex 文件:

@Book{test2022,
  author =    {Barus, Foobius},
  title =        {The Very Persistent Foo or Bar},
  publisher =    {Foobar Publications, Inc},
  year =         {2022}
}

我最终自己弄明白了。事实证明您必须设置一些扩展名和一些选项,并设置文档的元数据:

{-# LANGUAGE OverloadedStrings #-}

import Text.Pandoc
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import Text.Pandoc.Filter
import Text.Pandoc.Citeproc
import qualified Data.Map as M
import Text.Pandoc.Builder (setMeta)

main :: IO ()
main = do
  let exts = extensionsFromList [ Ext_citations ]
  let readerOptions = def{ readerExtensions = exts}
  let writerOptions = def{ writerExtensions = exts}
  result <- runIO $ do
    doc <- readMarkdown readerOptions (T.pack "Testing testing\n[@test2022]\n")
    let doc' = setMeta (T.pack "bibliography") (T.pack "test.bib") doc :: Pandoc
    processed <- processCitations doc'
    writeHtml5String writerOptions processed
  html <- handleError result
  TIO.putStrLn html