public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* How to resolve citations inside attributes
@ 2021-09-09  8:27 Carsten Gips
       [not found] ` <0bc0abba-e2ba-4473-b768-fe3fbbbcc0ebn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Carsten Gips @ 2021-09-09  8:27 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 682 bytes --]

Dear all,

I'm trying to resolve citations inside attributes, i.e. 

```{.c caption="nice, see [@KEY]"}
...
```

Pandoc and Citeproc are currently not handling citations inside am 
attribute like in the example. How can I resolve these citations anyway?

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/0bc0abba-e2ba-4473-b768-fe3fbbbcc0ebn%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 1070 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to resolve citations inside attributes
       [not found] ` <0bc0abba-e2ba-4473-b768-fe3fbbbcc0ebn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2021-09-09  8:39   ` Carsten Gips
       [not found]     ` <782eda7c-31e7-45ac-928d-3fdea56e5412n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Carsten Gips @ 2021-09-09  8:39 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 3303 bytes --]

I've tried to resolve this manually by extracting this piece with a Lua 
filter, converting it into a new document and running Pandoc plus Citeproc 
on this temporary document with `pandoc.utils.run_json_filter`, retrieving 
the processed citation and putting it back as codeblock caption in the 
original document. However, this approach seems not to be working.

To narrow this down further, I wrote a short document (`test.md`, see 
attachment) and a Lua filter (`codecite.lua`, see attachment). (To make it 
even shorter, in the Lua filter I simply replace the text block of the 
document with a similar new block).

But this does not seem to work. The call `pandoc -L codecite.lua test.md -t 
json` returns only 

```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]"}]}]}
```
i.e. the citation is not resolved.

However, if I run Pandoc directly on this document, i.e `pandoc -t json 
--citeproc test.md`, the result is as expected:

```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":"”"}]]}]}]]}]]}]}
```

Clearly I'm missing something here. But what is it? Can you please advise?


PS: `pandoc --version`: pandoc 2.14.2

Carsten Gips schrieb am Donnerstag, 9. September 2021 um 10:27:36 UTC+2:

> Dear all,
>
> I'm trying to resolve citations inside attributes, i.e. 
>
> ```{.c caption="nice, see [@KEY]"}
> ...
> ```
>
> Pandoc and Citeproc are currently not handling citations inside am 
> attribute like in the example. How can I resolve these citations anyway?
>
> 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/782eda7c-31e7-45ac-928d-3fdea56e5412n%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 4006 bytes --]

[-- Attachment #2: codecite.lua --]
[-- Type: application/octet-stream, Size: 366 bytes --]

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

[-- Attachment #3: test.md --]
[-- Type: text/markdown, Size: 91 bytes --]

---
references:
- author:
  - family: Wuppie
  id: FOO
  title: Lorem Ipsum
---
see [@FOO]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to resolve citations inside attributes
       [not found]     ` <782eda7c-31e7-45ac-928d-3fdea56e5412n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2021-09-09 17:22       ` John MacFarlane
       [not found]         ` <m21r5x3br7.fsf-jF64zX8BO0+FqBokazbCQ6OPv3vYUT2dxr7GGTnW70NeoWH0uzbU5w@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: John MacFarlane @ 2021-09-09 17:22 UTC (permalink / raw)
  To: Carsten Gips, pandoc-discuss


Citations are only recognized when they're parsed as markdown.
@key in a code block or attribute won't be parsed.

You could use the pandoc Lua 'read' function to parse the
contents of your attribute as Markdown and then do something with that.

Carsten Gips <cagixcagix-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> I've tried to resolve this manually by extracting this piece with a Lua 
> filter, converting it into a new document and running Pandoc plus Citeproc 
> on this temporary document with `pandoc.utils.run_json_filter`, retrieving 
> the processed citation and putting it back as codeblock caption in the 
> original document. However, this approach seems not to be working.
>
> To narrow this down further, I wrote a short document (`test.md`, see 
> attachment) and a Lua filter (`codecite.lua`, see attachment). (To make it 
> even shorter, in the Lua filter I simply replace the text block of the 
> document with a similar new block).
>
> But this does not seem to work. The call `pandoc -L codecite.lua test.md -t 
> json` returns only 
>
> ```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]"}]}]}
> ```
> i.e. the citation is not resolved.
>
> However, if I run Pandoc directly on this document, i.e `pandoc -t json 
> --citeproc test.md`, the result is as expected:
>
> ```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":"”"}]]}]}]]}]]}]}
> ```
>
> Clearly I'm missing something here. But what is it? Can you please advise?
>
>
> PS: `pandoc --version`: pandoc 2.14.2
>
> Carsten Gips schrieb am Donnerstag, 9. September 2021 um 10:27:36 UTC+2:
>
>> Dear all,
>>
>> I'm trying to resolve citations inside attributes, i.e. 
>>
>> ```{.c caption="nice, see [@KEY]"}
>> ...
>> ```
>>
>> Pandoc and Citeproc are currently not handling citations inside am 
>> attribute like in the example. How can I resolve these citations anyway?
>>
>> 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/782eda7c-31e7-45ac-928d-3fdea56e5412n%40googlegroups.com.
> ---
> references:
> - author:
>   - family: Wuppie
>   id: FOO
>   title: Lorem Ipsum
> ---
> see [@FOO]

-- 
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/m21r5x3br7.fsf%40MacBook-Pro-2.hsd1.ca.comcast.net.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to resolve citations inside attributes
       [not found]         ` <m21r5x3br7.fsf-jF64zX8BO0+FqBokazbCQ6OPv3vYUT2dxr7GGTnW70NeoWH0uzbU5w@public.gmane.org>
@ 2021-09-13  7:54           ` Carsten Gips
  0 siblings, 0 replies; 4+ messages in thread
From: Carsten Gips @ 2021-09-13  7:54 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 4563 bytes --]


Thanks, 'read' was the hint I was looking for! It's working now :)
John MacFarlane schrieb am Donnerstag, 9. September 2021 um 19:22:19 UTC+2:

>
> Citations are only recognized when they're parsed as markdown.
> @key in a code block or attribute won't be parsed.
>
> You could use the pandoc Lua 'read' function to parse the
> contents of your attribute as Markdown and then do something with that.
>
> Carsten Gips <cagix...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>
> > I've tried to resolve this manually by extracting this piece with a Lua 
> > filter, converting it into a new document and running Pandoc plus 
> Citeproc 
> > on this temporary document with `pandoc.utils.run_json_filter`, 
> retrieving 
> > the processed citation and putting it back as codeblock caption in the 
> > original document. However, this approach seems not to be working.
> >
> > To narrow this down further, I wrote a short document (`test.md`, see 
> > attachment) and a Lua filter (`codecite.lua`, see attachment). (To make 
> it 
> > even shorter, in the Lua filter I simply replace the text block of the 
> > document with a similar new block).
> >
> > But this does not seem to work. The call `pandoc -L codecite.lua test.md 
> -t 
> > json` returns only 
> >
> > ```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]"}]}]}
> > ```
> > i.e. the citation is not resolved.
> >
> > However, if I run Pandoc directly on this document, i.e `pandoc -t json 
> > --citeproc test.md`, the result is as expected:
> >
> > ```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":"”"}]]}]}]]}]]}]}
> > ```
> >
> > Clearly I'm missing something here. But what is it? Can you please 
> advise?
> >
> >
> > PS: `pandoc --version`: pandoc 2.14.2
> >
> > Carsten Gips schrieb am Donnerstag, 9. September 2021 um 10:27:36 UTC+2:
> >
> >> Dear all,
> >>
> >> I'm trying to resolve citations inside attributes, i.e. 
> >>
> >> ```{.c caption="nice, see [@KEY]"}
> >> ...
> >> ```
> >>
> >> Pandoc and Citeproc are currently not handling citations inside am 
> >> attribute like in the example. How can I resolve these citations anyway?
> >>
> >> 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-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/pandoc-discuss/782eda7c-31e7-45ac-928d-3fdea56e5412n%40googlegroups.com
> .
> > ---
> > references:
> > - author:
> > - family: Wuppie
> > id: FOO
> > title: Lorem Ipsum
> > ---
> > see [@FOO]
>

-- 
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/9c08fc54-f3bf-451a-92fe-14d9c978711dn%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 7716 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-13  7:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-09  8:27 How to resolve citations inside attributes Carsten Gips
     [not found] ` <0bc0abba-e2ba-4473-b768-fe3fbbbcc0ebn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-09-09  8:39   ` Carsten Gips
     [not found]     ` <782eda7c-31e7-45ac-928d-3fdea56e5412n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-09-09 17:22       ` John MacFarlane
     [not found]         ` <m21r5x3br7.fsf-jF64zX8BO0+FqBokazbCQ6OPv3vYUT2dxr7GGTnW70NeoWH0uzbU5w@public.gmane.org>
2021-09-13  7:54           ` 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).