jgm/citeproc

Citations inside listing captions are not resolving

174n opened this issue · 1 comments

174n commented

Steps to reproduce

create test.md:

---
bibliography: [bibliography.bib]
citeproc: true
link-citations: true
listings: true
codeBlockCaptions: true
---

Test: [@Test]

```{#lst:example .java caption="Example (vgl. [@Test])"}
// hello world
```

create bibliography.bib:

@misc{Test,
author = {},
title = {GitHub - jgm/citeproc: CSL citation processing library in Haskell},
howpublished = {\url{https://github.com/jgm/citeproc}},
month = {},
year = {},
note = {(Accessed on 06/29/2022)}
}

run:

pandoc test.md -o test.pdf --listings --citeproc

Expected behavior

Both citations should resolve, but instead the one inside of the listing caption does not

jgm commented

Attributes are parsed as plain strings, so nothing in them is interpreted as Markdown. Citations are resolved in the parsing phase, so by the time we get to the writer nothing can be done.

It's probably possible to work around this with a Lua filter. The filter would need to match code blocks, then adjust the caption attribute by:

  • creating a new markdown document consisting of the attribute's string content and a YAML metadata block specifying the bibliography and csl stylesheet
  • calling pandoc.read with input format markdown and PANDOC_READER_OPTIONS as options
  • using pandoc.utils.stringify to convert the Pandoc document produced by pandoc.read to a plain string
  • replacing the caption attribute's value with this plain string