From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/31986 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Howard Borchew Newsgroups: gmane.text.pandoc Subject: Re: help with lua filter "Replacing placeholders with their metadata value" Date: Thu, 12 Jan 2023 16:13:41 -0800 (PST) Message-ID: References: <8db3a838-8431-4b75-aac1-94bc29fac675n@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_5210_1175844000.1673568821485" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5156"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCBJHLEY5IOBBOGEQKPAMGQEGUGZJEI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Jan 13 01:13:48 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-ot1-f60.google.com ([209.85.210.60]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pG7hb-00018V-Fi for gtp-pandoc-discuss@m.gmane-mx.org; Fri, 13 Jan 2023 01:13:47 +0100 Original-Received: by mail-ot1-f60.google.com with SMTP id y14-20020a0568301d8e00b00670641b451bsf9813042oti.15 for ; Thu, 12 Jan 2023 16:13:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:x-original-sender :mime-version:subject:references:in-reply-to:message-id:to:from:date :sender:from:to:cc:subject:date:message-id:reply-to; bh=sBd55/3xPHAOEoueNdvlOIfmIu3Es99VRLYpX0H95hQ=; b=PPhY8gPa5MREvN/8ko0WwV7YRyrYBqo76FEUo9TZna1/HQr/pHDvmnbOnFbTmDieJh Tc969+DBGl1dZ0M6LgZ9e7CDcL3ECDPsVTWTZtqSwpO+uSbUy0XepvD0km2GGzRihUaY GmVKPnV8qKOQB4MLFk+slrbRxTZ8cLNiro9VoV3ToLhv+fhqrtJWtH9yF4O7hlOAtUND NPmwQFASxG5nb3AkoL2n2G0eURrpJRjgnlaKZpPdocQEeJLW9tXNmg8Ll2ecZt4Cs/Ic xdPN7xaDXqTTjhvVfnFMPRGgXk7XdS2HDnrUhCUz2juMZY9mEbhByh2/jMOgs3DDfN6q di6A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:x-original-sender :mime-version:subject:references:in-reply-to:message-id:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=sBd55/3xPHAOEoueNdvlOIfmIu3Es99VRLYpX0H95hQ=; b=qe5xaHBZRJp1H4ZCx7sXT4kQiL2zWt6kuSiL2F9UqW7ylF7UMYvHm8Ru1Glsf0G6PK BnjHcvaOCokZDf3wyL+t4dRJXrWpVaTn8J5xf2INjBNcIztcyTfK+s3AE/G6NQ9ijSae vPBpkkURQt5O6GB6fXzmVOfclXg9Z5/DcI0VMlfpnNhSsEJsFgBzOOYb2vQSauL26xtw cIKR77zCuodmXScCIHq/esLTOLVDZff8PcHKLTdTVb5STHTHurSJ5zdc5NPYzITlNzLS 4rIQYzTgiCSaFHJkgOvz9KgdhuVycnqLh05NSXbyIVaPtaDNHrjHGfthuBkeClx3wNzY IT4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence:reply-to :x-original-sender:mime-version:subject:references:in-reply-to :message-id:to:from:date:x-gm-message-state:sender:from:to:cc :subject:date:message-id:reply-to; bh=sBd55/3xPHAOEoueNdvlOIfmIu3Es99VRLYpX0H95hQ=; b=3Vgn88fRiRaXf7HZsdBvl4yT+/O4GegBCNDbSJ9tl9jQfU0TomsOSUqT0rtRFHkVZP nCcZFMMx8syt/JAuKXOkrQJxzbCPyKcfCaoDP68CNX0nlllsTh8TkeCWtjKpH8Z4J+// D9Lo22Jl/Aq5LjZKL7hagAbmosxI1KIGh1uB/EzhB1QafraoVECxV+3YB0XlV02XT1fZ OyFeCy3Q4vvSWcIa6bLQKr3UvCp7cVdtTCAyL28av7FeMGL/BETngL1MrStRH8J4tzCV VwcIBqMKQ2PCcZAq/e0XtsDpyaHbS/FRGZCNMa5Lk0kYJ2nmQZLTcLbuGv5rNWNhByOe /gSg== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AFqh2koP8yjYIav/hov+UAmaRZlgu0SAIpQwRaZAatwu/hhnlmp71dUl NiAPcKTsOaJEE6VkoQslp0g= X-Google-Smtp-Source: AMrXdXu82PgovMOe1ERV+sEESkIAX2OHMuU40Ck6c5SjcUAO2NWkFPVfMfw61hSfllScbHMMFaLONg== X-Received: by 2002:a05:6870:4256:b0:148:5f4a:7f19 with SMTP id v22-20020a056870425600b001485f4a7f19mr6912077oac.120.1673568826328; Thu, 12 Jan 2023 16:13:46 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6870:770e:b0:13d:173c:e583 with SMTP id dw14-20020a056870770e00b0013d173ce583ls1569089oab.0.-pod-prod-gmail; Thu, 12 Jan 2023 16:13:44 -0800 (PST) X-Received: by 2002:a05:6870:c18f:b0:137:49e:98ef with SMTP id h15-20020a056870c18f00b00137049e98efmr256140oad.0.1673568823795; Thu, 12 Jan 2023 16:13:43 -0800 (PST) In-Reply-To: X-Original-Sender: hborchew-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.io gmane.text.pandoc:31986 Archived-At: ------=_Part_5210_1175844000.1673568821485 Content-Type: multipart/alternative; boundary="----=_Part_5211_2085599316.1673568821485" ------=_Part_5211_2085599316.1673568821485 Content-Type: text/plain; charset="UTF-8" On Thursday, January 12, 2023 at 9:36:04 AM UTC-8 BPJ wrote: Den tors 12 jan. 2023 18:00Howard Borchew 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. The document is under revision control and I want to change placeholders from the command line at the time of running pandoc. 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. I don't quite get your suggestion: I presume the list gets to get_vars through the argument meta and meta is iterated over in key(k)/value(v) pairs in the for-do loop. Only when passing the value(v) type=="Inlines" check does a placeholder %key% and value(v) get added to the vars table. While iterating over pairs(meta) would the for-do loop encounter the --metadata KEY[VALUE] items that were set by the command line switch? Is it then simply a matter to pass that type check and add it to vars (type is raw string keyword?). 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. If I can get the command line KEY[VALUE] table items into vars above, I don't think this replace function would need to change. Can you show some examples what you have in mind? Code or CodeBlock? -- 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/8db3a838-8431-4b75-aac1-94bc29fac675n%40googlegroups.com . -- 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/d1590311-ccb2-4e57-b518-be8c14c49ba8n%40googlegroups.com. ------=_Part_5211_2085599316.1673568821485 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Thursday, January 12, 2023 at 9:36:04= AM UTC-8 BPJ wrote:


Den tors 12 jan. 2023 18:00Howard Borchew <hbor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
Hello,

There is an example lua filter in pandoc.o= rg called:
"Replacing placeholders with their metadata value"=

This does exactly what I need but for one excep= tion:
If I set a metadata value on the pandoc command line with= =C2=A0--metadata=3DKEY[:VALUE]
then the placeholder is not replac= ed with anything and not the command line VALUE
using this exampl= e lua filter.

<= /div>
Probably because if you set the me= tadata value on the command line it is just a raw string, not a list of inl= ines as the filter and pandoc.Span expect.


=

Is there an easy fix for this?
<= /div>

Set the variables in a metadata block in the document = or in a metadata file.


The documen= t is under revision control and I want to change placeholders from the comm= and line at the time of running pandoc.=C2=A0
=
=C2=A0
=

I am pasting the example from=C2=A0https://pandoc.org/lua-filters.html = below.

Thanks,
Howard
----
local vars =3D {}

function get_vars (meta)
=C2=A0 = for k, v in pairs(meta) do
=C2=A0 =C2=A0 if pandoc.utils.type(v) =3D= =3D 'Inlines' then
=C2=A0 =C2=A0 =C2=A0 vars["%" .. k .. "%"] =3D {tab= le.unpack(v)}
=C2=A0 =C2=A0 end
=C2=A0 end
end

It could be expanded to wrap a raw string value in a St= r and an Inlines, and to convert a Blocks value to an Inlines with pandoc.u= tils.blocks_to_inlines.


I don't quite get your suggestio= n: I presume the list gets to get_vars through the argument meta and meta i= s iterated over in key(k)/value(v) pairs in the for-do loop.
Only= when passing the value(v) type=3D=3D"Inlines" check does a placeholder %ke= y% and value(v) get added to the vars table.
While iterating over= pairs(meta) would the for-do loop encounter the --metadata KEY[VALUE] item= s that were set by the command line switch?
Is it then simply a m= atter to pass that type check and add it to vars (type is raw string keywor= d?).


=

function replace (el)=C2=A0 if vars[el.text] then
=C2=A0 =C2=A0 return pandoc.Span(vars[= el.text])
=C2=A0 else
=C2=A0 =C2=A0 return el
=C2=A0 end
end

return {{Meta =3D get_vars}, {Str =3D replace}}

My take is to use a Code or CodeBlock with class .va= r and the variable name as text. More to type but more robust.


If I can get the = command line KEY[VALUE] table items into vars above, I don't think this rep= lace function would need to change.

Can you show some e= xamples what you have in mind? Code or CodeBlock?=C2=A0

--
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 e= mail to pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.c= om/d/msgid/pandoc-discuss/8db3a838-8431-4b75-aac1-94bc29fac675n%40googlegro= ups.com.

--
You received this message because you are subscribed to the Google Groups &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d= /msgid/pandoc-discuss/d1590311-ccb2-4e57-b518-be8c14c49ba8n%40googlegroups.= com.
------=_Part_5211_2085599316.1673568821485-- ------=_Part_5210_1175844000.1673568821485--