From: BPJ <bpj-J3H7GcXPSITLoDKTGw+V6w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: help with lua filter "Replacing placeholders with their metadata value"
Date: Thu, 12 Jan 2023 18:35:48 +0100 [thread overview]
Message-ID: <CADAJKhCJK59eix-A_-21UfnxnuDPi6r_jZV0RNSF01UuFzKcbA@mail.gmail.com> (raw)
In-Reply-To: <8db3a838-8431-4b75-aac1-94bc29fac675n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 2565 bytes --]
Den tors 12 jan. 2023 18:00Howard Borchew <hborchew-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
> Hello,
>
> There is an example lua filter in pandoc.org called:
> "Replacing placeholders with their metadata value"
>
> This does exactly what I need but for one exception:
> If I set a metadata value on the pandoc command line
> with --metadata=KEY[:VALUE]
> then the placeholder is not replaced with anything and not the command
> line VALUE
> using this example lua filter.
>
Probably because if you set the metadata value on the command line it is
just a raw string, not a list of inlines as the filter and pandoc.Span
expect.
> Is there an easy fix for this?
>
Set the variables in a metadata block in the document or in a metadata file.
<https://pandoc.org/MANUAL.html#option--metadata-file>
> I am pasting the example from https://pandoc.org/lua-filters.html below.
>
> Thanks,
> Howard
> ----
> local vars = {}
>
> function get_vars (meta)
> for k, v in pairs(meta) do
> if pandoc.utils.type(v) == 'Inlines' then
> vars["%" .. k .. "%"] = {table.unpack(v)}
> end
> end
> end
>
It could be expanded to wrap a raw string value in a Str and an Inlines,
and to convert a Blocks value to an Inlines with
pandoc.utils.blocks_to_inlines.
> function replace (el)
> if vars[el.text] then
> return pandoc.Span(vars[el.text])
> else
> return el
> end
> end
>
> return {{Meta = get_vars}, {Str = replace}}
>
My take is to use a Code or CodeBlock with class .var and the variable name
as text. More to type but more robust.
--
> 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/8db3a838-8431-4b75-aac1-94bc29fac675n%40googlegroups.com
> <https://groups.google.com/d/msgid/pandoc-discuss/8db3a838-8431-4b75-aac1-94bc29fac675n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
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/CADAJKhCJK59eix-A_-21UfnxnuDPi6r_jZV0RNSF01UuFzKcbA%40mail.gmail.com.
[-- Attachment #2: Type: text/html, Size: 4954 bytes --]
next prev parent reply other threads:[~2023-01-12 17:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-12 16:59 Howard Borchew
[not found] ` <8db3a838-8431-4b75-aac1-94bc29fac675n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-01-12 17:35 ` BPJ [this message]
[not found] ` <CADAJKhCJK59eix-A_-21UfnxnuDPi6r_jZV0RNSF01UuFzKcbA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-01-13 0:13 ` Howard Borchew
[not found] ` <d1590311-ccb2-4e57-b518-be8c14c49ba8n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-01-13 9:11 ` Claudio Di Vita
2023-01-14 21:35 ` BPJ
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CADAJKhCJK59eix-A_-21UfnxnuDPi6r_jZV0RNSF01UuFzKcbA@mail.gmail.com \
--to=bpj-j3h7gcxpsitlodktgw+v6w@public.gmane.org \
--cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).