* Resolving citations inside attributes
@ 2021-09-09 8:14 Carsten Gips
0 siblings, 0 replies; only message in thread
From: Carsten Gips @ 2021-09-09 8:14 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 3533 bytes --]
Hi, I'm trying to resolve citations inside attributes, i.e. something like
```{.c caption="nice piece, cf. [@FOO]"}
int main() {
return 42;
}
```
Since Pandoc/Citeproc currently do not handle citations of this kind, I'm
trying to resolve this manually with a Lua filter: Put this piece into a
new temporary document, run Pandoc+Citeproc on this document using
`pandoc.utils.run_json_filter`, retrieve the processed string and put back
it in the original place, i.e. the caption.
However, this approach seems to be not working?
As a MWE I've tried this document `test.md`:
```markdown
---
references:
- author:
- family: Wuppie
id: FOO
title: Lorem Ipsum
---
see [@FOO]
```
Running `pandoc -t json --citeproc test.md` the result is
```json
{"pandoc-api-version":[1,22],"meta":{"references":{"t":"MetaList","c":[{"t":"MetaMap","c":{"author":{"t":"MetaList","c":[{"t":"MetaMap","c":{"family":{"t":"MetaInlines","c":[{"t":"Str","c":"Wuppie"}]}}}]},"id":{"t":"MetaInlines","c":[{"t":"Str","c":"FOO"}]},"title":{"t":"MetaInlines","c":[{"t":"Str","c":"Lorem"},{"t":"Space"},{"t":"Str","c":"Ipsum"}]}}}]}},"blocks":[{"t":"Para","c":[{"t":"Str","c":"see"},{"t":"Space"},{"t":"Cite","c":[[{"citationId":"FOO","citationPrefix":[],"citationSuffix":[],"citationMode":{"t":"NormalCitation"},"citationNoteNum":1,"citationHash":0}],[{"t":"Str","c":"(Wuppie,"},{"t":"Space"},{"t":"Str","c":"n.d.)"}]]}]},{"t":"Div","c":[["refs",["references","csl-bib-body","hanging-indent"],[]],[{"t":"Div","c":[["ref-FOO",["csl-entry"],[]],[{"t":"Para","c":[{"t":"Str","c":"Wuppie."},{"t":"Space"},{"t":"Str","c":"n.d."},{"t":"Space"},{"t":"Span","c":[["",[],[]],[{"t":"Str","c":"“"},{"t":"Str","c":"Lorem"},{"t":"Space"},{"t":"Str","c":"Ipsum"},{"t":"Str","c":"."},{"t":"Str","c":"”"}]]}]}]]}]]}]}
```
, i.e. the citation is properly resolved (as expected).
However, using the Lua filter `codecite.lua` (for the sake of simplicity,
I'll just replace the old block directly with a citation):
```lua
local meta
function render_blocks(b)
local blocks = {pandoc.Para{pandoc.Str("see [@FOO]")}}
local tmp = pandoc.utils.run_json_filter(
pandoc.Pandoc(blocks, meta),
'pandoc',
{'--from=json', '--to=json', '--citeproc'}
)
return tmp.blocks
end
return {
{ Meta = function (m) meta = m end },
{ Block = render_blocks }
}
```
and running `pandoc -L codecite.lua test.md -t json` the result is just
```json
{"pandoc-api-version":[1,22],"meta":{"references":{"t":"MetaList","c":[{"t":"MetaMap","c":{"author":{"t":"MetaList","c":[{"t":"MetaMap","c":{"family":{"t":"MetaInlines","c":[{"t":"Str","c":"Wuppie"}]}}}]},"id":{"t":"MetaInlines","c":[{"t":"Str","c":"FOO"}]},"title":{"t":"MetaInlines","c":[{"t":"Str","c":"Lorem"},{"t":"Space"},{"t":"Str","c":"Ipsum"}]}}}]}},"blocks":[{"t":"Para","c":[{"t":"Str","c":"see
[@FOO]"}]}]}
```
, which is unexpected (citation is not resolved).
Clearly I'm missing something here. But what is it? Can you please advise?
`pandoc --version`: pandoc 2.14.2
Thanks!
Carsten
--
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/bcb42d1a-cd9f-45f1-a1f4-5f21cb9ae46an%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 4678 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-09-09 8:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-09 8:14 Resolving citations inside attributes Carsten Gips
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).