pandoc-citeproc作为API:processCites'不添加引用

时间:2019-01-18 22:34:35

标签: pandoc-citeproc

我在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具有单个参数,即readMarkdown产生的processCites数据。参考书目和csl样式应从输入文件中获取。

该过程不会产生错误,但是pandoc -f markdown -t html --filter=pandoc-citeproc -o p1.html postWithReference.md 的结果与输入内容相同;引用完全不被处理。对于相同的输入,引用由独立的pandoc解析(这不包括书目和csl样式中的错误)

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

因此,问题出在API中。我的代码是:

-- 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!

我误解了什么? citeproc是否需要阅读器选项?参考书目是一个BibLatex文件。

我在hakyll code中发现了一条注释,根据那里的代码,我无法理解该注释-也许有人知道意图是什么。

="select 'foo' as Foo"

2 个答案:

答案 0 :(得分:0)

我有一个解决方法(不是原始问题的答案,我仍然希望有人可以识别我的错误!)。用pandoc调用独立的System.readProess很简单,并传递文本并返回结果,甚至不读写文件:

processCites2x :: Maybe FilePath -> Maybe FilePath -> Text ->   ErrIO Text
-- porcess the cites in the text (not with the API)
-- using systemcall because the standalone pandoc works with 
-- call: pandoc -f markdown -t html  --filter=pandoc-citeproc
-- with the input text on stdin and the result on stdout
-- the csl and bib file are used from text, not from what is in the arguments

processCites2x _ _  t  = do
        putIOwords ["processCite2" ] -- - filein\n", showT styleFn2, "\n", showT bibfn2]

        let cmd = "pandoc"
        let cmdargs = ["--from=markdown", "--to=html5", "--filter=pandoc-citeproc" ]

        let cmdinp = t2s t
        res :: String <- callIO $ System.readProcess cmd cmdargs cmdinp

        return . s2t $ res
        -- error are properly caught and reported in ErrIO

t2ss2t是字符串和文本之间的转换实用程序,ErrIOErrorT Text a IO,而callIO实际上是liftIO,具有错误处理功能。

答案 1 :(得分:0)

最初的问题非常简单:我没有在Ext_citations中包括选项markdownOptions。包含该示例后,该示例将起作用(感谢我从pandoc-citeproc问题页面获得的帮助)。引用的代码已更新...