0

我在 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'它有一个参数,即PandocreadMarkdown. 参考书目和 csl 样式应取自输入文件。

该过程不会产生错误,但结果processCites是与输入相同的文本;根本不处理引用。对于相同的输入,使用独立 pandoc 解决引用(这不包括参考书目和 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

我有什么误解?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!
4

2 回答 2

0

最初的问题很简单:我没有Ext_citationsmarkdownOptions. 当它包含在内时,该示例有效(感谢我从pandoc-citeproc问题页面收到的帮助)。引用的代码已更新...

于 2019-01-21T19:49:25.363 回答
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

t2s并且s2t是字符串和文本之间的转换实用程序,本质ErrIO上是处理错误。ErrorT Text a IOcallIOliftIO

于 2019-01-20T09:19:56.980 回答