* issue replacing placeholders with their metadata value with lua-filter
@ 2020-04-24 12:13 jamie bowman
[not found] ` <1125df10-2d3e-4c18-8e9e-b8c228b5118e-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 2+ messages in thread
From: jamie bowman @ 2020-04-24 12:13 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 1976 bytes --]
I'm using a Lua filter from the Pandoc example which replaces placeholder
values in a document with their corresponding metadata value:
local vars = {}
function get_vars (meta)
for k, v in pairs(meta) do
if v.t == 'MetaInlines' then
vars["$" .. k .. "$"] = {table.unpack(v)}
end
end
end
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}}
It is has worked OK thus far but I'm now encountering an issue when
coverting markdown to pdf where only the first placeholder is replaced if
there happens to be two of the same placeholders in the source document.
Really simplified, my markdown document looks something like:
# Publishing Agreement
Between \$contributor\$ (hereinafter called the 'Author'),
And
\$publisher\$ (hereinafter called the 'Publisher')
...
Signed by or on behalf of the Author:
\$contributor\$
Signed by or on behalf of the Author:
\$publisher\$
When I run
pandoc -f markdown -t latex --metadata-file data/contributor/example.yml --
lua-filter filters/meta-vars.lua -s -o example.pdf example.md
I get a pdf where only the first two instances of 'contributor' and
'publisher' are replaced. I have tried putting the placeholders inline,
changing the placeholder symbol that wraps the string (using % instead of
$), but I'm a bit out of my depth here. I was wondering if anybody could
help.
For clarity my example.yml file looks like:
contributor: "Contributor name"
publisher: "Publisher name"
Many thanks in advance.
--
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/1125df10-2d3e-4c18-8e9e-b8c228b5118e%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 16095 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: issue replacing placeholders with their metadata value with lua-filter
[not found] ` <1125df10-2d3e-4c18-8e9e-b8c228b5118e-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2020-04-24 15:40 ` jamie bowman
0 siblings, 0 replies; 2+ messages in thread
From: jamie bowman @ 2020-04-24 15:40 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 2401 bytes --]
Apologies but I've realised this is actually an issue with using the filter
in conjunction with the {multicol} package i.e. the placeholders are not
replaced when they are within an inititated column block initiated. Will
update accordingly.
On Friday, April 24, 2020 at 1:13:06 PM UTC+1, jamie bowman wrote:
>
> I'm using a Lua filter from the Pandoc example which replaces placeholder
> values in a document with their corresponding metadata value:
>
> local vars = {}
>
> function get_vars (meta)
> for k, v in pairs(meta) do
> if v.t == 'MetaInlines' then
> vars["$" .. k .. "$"] = {table.unpack(v)}
> end
> end
> end
>
> 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}}
>
> It is has worked OK thus far but I'm now encountering an issue when
> coverting markdown to pdf where only the first placeholder is replaced if
> there happens to be two of the same placeholders in the source document.
> Really simplified, my markdown document looks something like:
>
> # Publishing Agreement
>
> Between \$contributor\$ (hereinafter called the 'Author'),
>
> And
>
> \$publisher\$ (hereinafter called the 'Publisher')
>
> ...
>
> Signed by or on behalf of the Author:
>
> \$contributor\$
>
> Signed by or on behalf of the Author:
>
> \$publisher\$
>
> When I run
>
> pandoc -f markdown -t latex --metadata-file data/contributor/example.yml
> --lua-filter filters/meta-vars.lua -s -o example.pdf example.md
>
> I get a pdf where only the first two instances of 'contributor' and
> 'publisher' are replaced. I have tried putting the placeholders inline,
> changing the placeholder symbol that wraps the string (using % instead of
> $), but I'm a bit out of my depth here. I was wondering if anybody could
> help.
>
> For clarity my example.yml file looks like:
>
>
> contributor: "Contributor name"
> publisher: "Publisher name"
>
>
> Many thanks in advance.
>
--
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/7edfcf64-a538-4dbd-9a5f-4b26afce9e0b%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 10182 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-04-24 15:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-24 12:13 issue replacing placeholders with their metadata value with lua-filter jamie bowman
[not found] ` <1125df10-2d3e-4c18-8e9e-b8c228b5118e-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-04-24 15:40 ` jamie bowman
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).