From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/31987 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Claudio Di Vita Newsgroups: gmane.text.pandoc Subject: Re: help with lua filter "Replacing placeholders with their metadata value" Date: Fri, 13 Jan 2023 01:11:25 -0800 (PST) Message-ID: <1d02199c-86ad-4730-9458-419babd9fab3n@googlegroups.com> 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_4866_91183408.1673601085704" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5122"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBDOYFIOXRYHRBP6AQSPAMGQEZZK5BZQ-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Jan 13 10:11:30 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oa1-f64.google.com ([209.85.160.64]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pGG5y-00018W-Ea for gtp-pandoc-discuss@m.gmane-mx.org; Fri, 13 Jan 2023 10:11:30 +0100 Original-Received: by mail-oa1-f64.google.com with SMTP id 586e51a60fabf-15b907e71edsf6172954fac.17 for ; Fri, 13 Jan 2023 01:11:30 -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=Bw8fQdTdJn6uQ5tz9Gmr+5YGOOY0TGDy7BIcaZ+MXas=; b=A8hJpK1ANOXdFOZOpJKjbekq6DNYIvvN9iJC70e42VT0L/st4i3Cf4/JbNn5mYUPep gcT7l8FcNofxvB0E04SEOatSy1B8l+fOXZNjnletW5cINxoi0HxNGU/BQH6tuPuquodk SscN3xddIFrdxDw/Uu/UCAsshP4326BrMOy8CMce+QSiK2Ac0bdUBQNLs5Iwe45CF+o8 PHEIgTC5AE1KlSbd56/mRPZz0xiqbstBhqfMFFGqnUR0KTd9EIas8NI8u4+1Rh6eJJ9V yDOZju/h9oS2H4ih2bDsVKo1cv1PNKPOjZCjDLODTFboi+AzI10YzFD+NahtxLA9FtQ0 uVAA== 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=Bw8fQdTdJn6uQ5tz9Gmr+5YGOOY0TGDy7BIcaZ+MXas=; b=T914Jnpi8fW4DTJpQry6N040D9cjJMPYveUpiQkG+3HYz/8mEMTqCoV1+WaLJd32Yj HB1OUxbisWrDu24RgtVSN91ndZQgYcd5Olv9aVNNs5wL68Llgcu8Ffp5LJ4sM4fayTeB vsf4IgPqnFz1Z/42IPtU7FWuOuEL7OSQH2f92dfpw3NGraGlHwwMtcvmEl81QYvdbya+ 7yolxKILta1ujqkFG4ohxYoiEMPEVJ7zvRHZhhpze/v37tj24FMGzNDKXLkUyUIrhBEj d3p4FHlx9uccNZ+GCTqnaI1qPRtDWkBDUD9uWSQAXiUyx62gqAQa9l+NtMkpsP9DGxxb 3MKA== 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=Bw8fQdTdJn6uQ5tz9Gmr+5YGOOY0TGDy7BIcaZ+MXas=; b=yWEWwSgjwlYOiJM7rFMQ30u7cADtlC4dl74oY0CZBeLQvdcZvEc73kfXgP+Ho+EPkO YsKuKIwXJsBp+1AXqKJJVhpycI8w7IM0PIw4aCENpRKRj8n1lZgBdY6ZmS2+r+GmUdbl DHPGdJ4CX+ILTZblRajzwrGSd9Z96IEZaGZ2rH2VTPC7ii0Dx0JvSvIyIYgmoCvRbjYi Gr985SqupKzO6m+XeYFCY9BVDhjQVJ6TLMyYAa+nUyCZUZBKB0uxKdAqxrKppoOUhz+z 693KcK7nhvYJBYfUscZ5Zzl2qcSF2JciJvkqrIR2WprCczG6uOlJcP2os6CUTI5rGaW9 IKgQ== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AFqh2kpi9NluaiezMLYlsLY571y4PYonKF/RFsb2tI9B/0gEZXP2krg+ 1Za+o/kuJMZKcODBX8Suzf8= X-Google-Smtp-Source: AMrXdXuZbozeHdK0XwohRH35LNmeXUxA+tS3A0FW5H1MKUHOJBKSLYmI8N3Wlxx7AI2ODkWQOZWDlw== X-Received: by 2002:a05:6870:42d0:b0:13b:ade2:46d with SMTP id z16-20020a05687042d000b0013bade2046dmr5205725oah.65.1673601089256; Fri, 13 Jan 2023 01:11:29 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6830:608b:b0:66d:e033:27e5 with SMTP id by11-20020a056830608b00b0066de03327e5ls925226otb.1.-pod-prod-gmail; Fri, 13 Jan 2023 01:11:26 -0800 (PST) X-Received: by 2002:a9d:6b99:0:b0:672:89a:834b with SMTP id b25-20020a9d6b99000000b00672089a834bmr5222616otq.80.1673601086575; Fri, 13 Jan 2023 01:11:26 -0800 (PST) In-Reply-To: X-Original-Sender: claudio.divita-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:31987 Archived-At: ------=_Part_4866_91183408.1673601085704 Content-Type: multipart/alternative; boundary="----=_Part_4867_335876330.1673601085704" ------=_Part_4867_335876330.1673601085704 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable May I suggest to use this=20 filter: https://github.com/cdivita/pandoc-curly-switch ? The following syntax is supported for defining variables placeholders: - ${...}, the curly brackets syntax - !...!, the exclamation marks syntax Variable can be referenced using an object-like notation, using any of the= =20 supported syntax. The exclamation marks syntax is suggested for LaTeX=20 blocks (if you use them). >From the tests I've made it works fine also with metadata specified through= =20 the command line. Cheers, Claudio Il giorno venerd=C3=AC 13 gennaio 2023 alle 01:13:41 UTC+1 hbor...-Re5JQEeQqe8@public.gmane.org= m ha=20 scritto: > 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=20 > with --metadata=3DKEY[:VALUE] > then the placeholder is not replaced with anything and not the command=20 > line VALUE > using this example lua filter. > > Probably because if you set the metadata value on the command line it is= =20 > just a raw string, not a list of inlines as the filter and pandoc.Span=20 > expect. > > > > Is there an easy fix for this? > > Set the variables in a metadata block in the document or in a metadata=20 > file. > > > > The document is under revision control and I want to change placeholders= =20 > from the command line at the time of running pandoc.=20 > =20 > > I am pasting the example from https://pandoc.org/lua-filters.html below. > > Thanks, > Howard > ---- > local vars =3D {} > > function get_vars (meta) > for k, v in pairs(meta) do > if pandoc.utils.type(v) =3D=3D 'Inlines' then > vars["%" .. k .. "%"] =3D {table.unpack(v)} > end > end > end > > It could be expanded to wrap a raw string value in a Str and an Inlines,= =20 > and to convert a Blocks value to an Inlines with=20 > pandoc.utils.blocks_to_inlines. > > > I don't quite get your suggestion: I presume the list gets to get_vars=20 > through the argument meta and meta is iterated over in key(k)/value(v)=20 > pairs in the for-do loop. > Only when passing the value(v) type=3D=3D"Inlines" check does a placehold= er=20 > %key% and value(v) get added to the vars table. > While iterating over pairs(meta) would the for-do loop encounter the=20 > --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=20 > (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 =3D get_vars}, {Str =3D replace}} > > My take is to use a Code or CodeBlock with class .var and the variable=20 > name as text. More to type but more robust. > > > If I can get the command line KEY[VALUE] table items into vars above, I= =20 > don't think this replace function would need to change. > > Can you show some examples what you have in mind? Code or CodeBlock?=20 > > --=20 > You received this message because you are subscribed to the Google Groups= =20 > "pandoc-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an= =20 > email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit=20 > https://groups.google.com/d/msgid/pandoc-discuss/8db3a838-8431-4b75-aac1-= 94bc29fac675n%40googlegroups.com=20 > > . > --=20 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-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/= pandoc-discuss/1d02199c-86ad-4730-9458-419babd9fab3n%40googlegroups.com. ------=_Part_4867_335876330.1673601085704 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable May I suggest to use this filter:=C2=A0https://github.com/cdivita/pandoc-cu= rly-switch ?

The following syntax is supported for defi= ning variables placeholders:

  • ${...}, the curly brac= kets syntax
  • !...!, the exclamation marks syntax
Variable can be referenced using an object-like notation, using any of the= supported syntax. The exclamation marks syntax is suggested for=C2=A0LaTeX= blocks (if you use them).

From the tests I've m= ade it works fine also with metadata specified through the command line.

Cheers,

Claudio
Il giorno venerd=C3=AC 13 gennaio 2023 alle 01:13:41 UTC+1 hbor...@g= mail.com ha scritto:
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.org called:
&qu= ot;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=C2=A0--metadata=3DKEY= [:VALUE]
then the placeholder is not replaced with anything and n= ot the command line VALUE
using this example lua filter.

<= div dir=3D"auto">Probably because if you set the metadata value on the comm= and line it is just a raw string, not a list of inlines as the filter and p= andoc.Span expect.



Is there an easy fix for this?

Set the var= iables in a metadata block in the document or in a metadata file.


The document is unde= r revision control and I want to change placeholders from the command line = at the time of running pandoc.=C2=A0
=C2=A0
=

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

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

function get_vars (meta)
=C2=A0 for k, v i= n pairs(meta) do
=C2=A0 =C2=A0 if pandoc.utils.type(v) =3D=3D 'Inlin= es' then
=C2=A0 =C2=A0 =C2=A0 vars["%" .. k .. "%&quo= t;] =3D {table.unpack(v)}
=C2=A0 =C2=A0 end
=C2=A0 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 y= our suggestion: I presume the list gets to get_vars through the argument me= ta and meta is 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 %key% and value(v) get added to the vars table.
While iterating over pairs(meta) would the for-do loop encounter the --m= etadata 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 (ty= pe is raw string keyword?).



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 retur= n el
=C2=A0 end
end

return {{Meta =3D get_vars}, {Str =3D repl= ace}}

<= div dir=3D"auto">
My take is to use a Code or CodeBlock wi= th class .var and the variable name as text. More to type but more robust.<= /div>


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

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

--
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 pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/8db3a838-8= 431-4b75-aac1-94bc29fac675n%40googlegroups.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/1d02199c-86ad-4730-9458-419babd9fab3n%40googlegroups.= com.
------=_Part_4867_335876330.1673601085704-- ------=_Part_4866_91183408.1673601085704--