0

I have a small text file in 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

and process it in Haskell with processCites' which has a single argument, namely the Pandoc data resulting from readMarkdown. The bibliography and the csl style should be taken from the input file.

The process does not produce errors, but the result of processCites is the same text as the input; references are not treated at all. For the same input the references are resolved with the standalone pandoc (this excludes errors in the bibliography and the csl style)

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

The issue is therefore in the API. The code I have is:

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

What do I misunderstand? are there any reader options necessary for citeproc? The bibliography is a BibLatex file.

I found in hakyll code a comment, which I cannot understand in light of the code there - perhaps somebody knows what the intention is.

-- 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!
user855443
  • 2,596
  • 3
  • 25
  • 37

2 Answers2

0

I have a workaround (not an answer to the original question, I still hope that somebody can identify my error!). It is simple to call the standalone pandoc with System.readProess and pass the text and get the result back, not even reading and writing files:

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 and s2t are conversion utilities between string and text, ErrIO is ErrorT Text a IO and callIO is essentially liftIO with handling of errors.

user855443
  • 2,596
  • 3
  • 25
  • 37
0

The original problem was very simple: I had not included the option Ext_citations in the markdownOptions. When it is included, the example works (thanks to help I received from the pandoc-citeproc issue page). The referenced code is updated...

user855443
  • 2,596
  • 3
  • 25
  • 37