如何在 Haskell 中使用 Pandoc 的 Citeproc 处理引用?
从 Pandoc 文档中的“一个简单示例”开始,我想添加引文处理功能。 Text.Pandoc.Citeproc 的文档 显示一个处理引用的函数 testing< ;/跨度> [@test2022]processCitations
。然而,给定简单的组织模式输入和引用[@test2022]
,它似乎不起作用。它编译并运行得很好,但下面代码的输出是:
,即引文实际上并未被处理。我做错了什么?我怎样才能让它处理我的引文?
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}
}
Starting with "A Simple Example" from the Pandoc documentation, I want to add citation processing functionality. The docs for Text.Pandoc.Citeproc show a function processCitations
which supposedly processes citations. Yet given simple org-mode input, and a citation [@test2022]
, it doesn't seem to work. It compiles and runs just fine, but the output of the code below is: <p><span class="spurious-link" target="url"><em>testing</em></span> [@test2022]</p>
, i.e., the citation isn't actually processed. What am I doing wrong? And how can I get this to process my citation?
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
For reference, here's my test.bib
bibtex file:
@Book{test2022,
author = {Barus, Foobius},
title = {The Very Persistent Foo or Bar},
publisher = {Foobar Publications, Inc},
year = {2022}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最终我自己弄清楚了这一点。结果您必须设置一些扩展名和一些选项,并设置文档的元数据:
I figured this out myself, eventually. Turns out you have to set some extensions, and some options, and set the metadata for the document: