From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/31983 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: BPJ Newsgroups: gmane.text.pandoc Subject: Re: help with lua filter "Replacing placeholders with their metadata value" Date: Thu, 12 Jan 2023 18:35:48 +0100 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/alternative; boundary="000000000000e5158105f2148c57" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19564"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCWMVYEK54FRBAMKQGPAMGQEKTMZZHA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Thu Jan 12 18:36:05 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oi1-f187.google.com ([209.85.167.187]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pG1Uj-0004st-7r for gtp-pandoc-discuss@m.gmane-mx.org; Thu, 12 Jan 2023 18:36:05 +0100 Original-Received: by mail-oi1-f187.google.com with SMTP id f2-20020a05680814c200b0036470a5606fsf1221641oiw.12 for ; Thu, 12 Jan 2023 09:36:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673544964; cv=pass; d=google.com; s=arc-20160816; b=iPxbt4UM6gume6MZG83VF89nDQrRdyIkgvqJdID6Xho3aPvqt/0QA+XzRr+8h14V+0 zXIadQFlZoAJNoI06sdyejipbklG80tb4KJ8Sx/WEW7UCpCsBoO5W83lPK+Olp0L+Qps iZBhcssuPgOnnccyNKsg95XGqlTRA3qfpvfoemhEdHBzDWh4C336TzMV334+sG8lvZmw /V1Hqwo6JCIvGnHaE84z7uAsosip9KCRiGsClQp4iVI629GljJIM4nVgeEPcfJu3nBPO ngwlNbMK6FnhQbYQO9uk0/gHTAyr1NobMVW1EyKRS2SgFKaBNVRKyUpTiaipnT8EEUfO SSSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:sender:dkim-signature; bh=N1QeKXsVN7Vz7wTU0EiPTjpfYsXGasCgqxn4Q+V3eKI=; b=GfAOqXlEqbT0B+8H+c/q2L31os2RS/JphZYejLLfuY52dI4KWDrZtruDMXK7mwevHK Bgd6WORMDUO/bwWbyrQIfS1jmQZIbyLMq/Uy+flE3JiNeCZng7K8EMLIzGmCTfiva01r 1u4rbbfXXbE3k8JJLzD8HRX/V510/Yf0EnIaVDhioaqz5om2AVSuGm4gzKDRZT1Ycb4A nEHdiLDS0V2cK+9gIHOG/t8pBEs7u0Bx2RpDcauvzzjokXlmCavogXW9SF8n0mu0yJBO NwunWpOku0wIDsx0PedDaHB3uFu/BQ2f8aeEWFTGqQH9cjZ9CYSZD0a7YwrY2hkZ3Jx4 AIDA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.219.175 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 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:x-original-authentication-results :x-original-sender:to:subject:message-id:date:from:reply-to :in-reply-to:references:mime-version:sender:from:to:cc:subject:date :message-id:reply-to; bh=N1QeKXsVN7Vz7wTU0EiPTjpfYsXGasCgqxn4Q+V3eKI=; b=LgQL2hM4/Huw8Is2YswK0b65e5dUDRKzFqciL0yjNvXmVNwnIbWmfIcvIb0FkkBiOH AwMXRcJut5PtbSwspuMoE1zWRV4AfkY7UVK8jIEzoP5dGzwfJaAqXGkqGodnWhDCnBri awyamU8TLPemd6CQdoACUkQ0SrzHM1Lk2mUxfrwYR0EnbdT82S7EO1ZE9P/+jYbcYPfI 1rfOn5sxzgYdKnvGZ6TmjxedNAdo+NeVmIeT4DT39vqF6yhIUgxgvZPJQSl0SR7lTkfM 7+0FnltjbVKx3sxONKPo86H2IeXNmvaXdwWapmwLWbFBn04zDxPTxTi5VzQ3lVSza6jJ OXEA== 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 :x-original-authentication-results:x-original-sender:to:subject :message-id:date:from:reply-to:in-reply-to:references:mime-version :x-gm-message-state:sender:from:to:cc:subject:date:message-id :reply-to; bh=N1QeKXsVN7Vz7wTU0EiPTjpfYsXGasCgqxn4Q+V3eKI=; b=STq+4hZiZ5B5OGbZ5zzpza349brxb5QN2s9Rn+QC7eU9ltUgenhJSWE7lYES3u8S85 cK/B6yew6YyFTww7vgYMwmYFBmtTPyOKzxhQP0MHG38TxdtAg49NOkYgNWAgVLWCG5MN dbGINLEPsLCOr107TT9uyfdXGLxPRPtmXGccqVNpQQjvKKFvJ7sdEQAk19OEwNV0HXcI RWzAtYNVdgxH/n1fLFdSK87n4CcCU1DJdokQfXP0cLs5Gm3pOj7Lmv827NhqqA2DGzKo 1OiCDKK7cF19xSxBGPzg/hNC8aX+CSEj4W2pTEhY6bLcMV Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AFqh2kq/7rdDU5PXJPvdHQ1UfIisXXY3M4uAWUfGp0LlAKfdokOca+1j 11oG60E81v4SHkc3O59rrCw= X-Google-Smtp-Source: AMrXdXt4PxbbgLVbPolqj3XqgabnBgNbQ8nMLq5qipPRBb2RhuNhjl/VEdNMpKRX5mAzSgaod/zkmA== X-Received: by 2002:a54:4887:0:b0:360:e48c:a755 with SMTP id r7-20020a544887000000b00360e48ca755mr3851897oic.152.1673544963967; Thu, 12 Jan 2023 09:36:03 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6870:e142:b0:154:df53:5a8 with SMTP id z2-20020a056870e14200b00154df5305a8ls1180080oaa.8.-pod-prod-gmail; Thu, 12 Jan 2023 09:36:01 -0800 (PST) X-Received: by 2002:a05:6871:430b:b0:150:2401:5309 with SMTP id lu11-20020a056871430b00b0015024015309mr3544932oab.54.1673544961328; Thu, 12 Jan 2023 09:36:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673544961; cv=none; d=google.com; s=arc-20160816; b=sFF3zfOyqw+2IqranGz73Erh0jv2VIQEBk68IZNfh6Jf22ZL0m3+ghivPLsxHHJGJF ++bQByYagE+H624qr0ZuVoxewzPCA8pyed1VuSlbV2RSaI/6EALWbQyMzD/FinZLlKd4 0esDcqtexXJGmuqqIyuXSTEBri+pa2LTTrfhXJaqpg/KtmHTNyLEQIIa1Soz0ieBEkEI cczSQ66UpHNGswBN5zlxl9oprUcAs38q1H4zF054pJjneyFSpm4anvhb7JN3Hl7PXp83 0a/GbolTySWqvkoX3jvzsmT5k5MsYButzxB19Cc3KYj07zLShZf2UAwiDHeCMEv3HWPk 4nig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version; bh=bcxgn9qrW/syAZwjRJK7eKq3Fi54NgFpgbBgi5M4yjM=; b=gEKIgbDfjm8v5W++2XibB9gBDLKisa4KWyucQT9wx7ooSKu8aZxqHwie76ckxLq/jA wfSF3cCZbjtctgn3Uivf8dtojW5nGhBeXKeqjopvdiYWUvaJ+/O3zdSMuUQBPl98Vui7 HaZzjiCWasx2wcGkjZyjI6oT6LjEjks/G1VzReNtzCJaSdc/KKniInOZsw9wG5vThAJA 6xteouJ+WoAmVVH9OMDeE8arkOcALWySuYsYZA1t2QSgKO+voITlIb1aJmopOg+CuXu4 zFn80f4dbEtxJBY7lR2qMFWrAzfdVh2ad0i5yIpPqKEP9v7PIBpPs0dB8pgHVh4t4Xj5 SEPQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.219.175 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Original-Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com. [209.85.219.175]) by gmr-mx.google.com with ESMTPS id m28-20020a056870a11c00b0014f9cc82408si1826183oae.5.2023.01.12.09.36.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Jan 2023 09:36:01 -0800 (PST) Received-SPF: pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.219.175 as permitted sender) client-ip=209.85.219.175; Original-Received: by mail-yb1-f175.google.com with SMTP id o75so19575428yba.2 for ; Thu, 12 Jan 2023 09:36:01 -0800 (PST) X-Received: by 2002:a25:2417:0:b0:7c8:accc:5788 with SMTP id k23-20020a252417000000b007c8accc5788mr331384ybk.634.1673544960643; Thu, 12 Jan 2023 09:36:00 -0800 (PST) In-Reply-To: <8db3a838-8431-4b75-aac1-94bc29fac675n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> X-Original-Sender: melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.219.175 as permitted sender) smtp.mailfrom=melroch-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:31983 Archived-At: --000000000000e5158105f2148c57 Content-Type: text/plain; charset="UTF-8" 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. > 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 > > . > -- 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. --000000000000e5158105f2148c57 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


Den tors 12 jan. 2023 18:00Howard Borchew <hborchew-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
<= blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px= #ccc solid;padding-left:1ex">Hello,

There is an example lua f= ilter in pandoc.org called:
"Replacing placeholders with their m= etadata value"

This does exactly what I need = but for one exception:
If I set a metadata value on the pandoc co= mmand line with=C2=A0--metadata=3DKEY[:VALUE]
then the placeholde= r is not replaced with anything and not the command line VALUE
us= ing this example lua filter.

Probably because if you set the metad= ata value on the command line it is just a raw string, not a list of inline= s as the filter and pandoc.Span expect.



Is there an easy fix fo= r this?

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

=


I am pastin= g the example from=C2=A0https://pandoc.org/lua-filters.html b= elow.

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 'Inli= nes' then
=C2=A0 =C2=A0 =C2=A0 vars["%" .. k .. "%&qu= ot;] =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 Inline= s, and to convert a Blocks value to an Inlines with pandoc.utils.blocks_to_= inlines.



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 re= turn el
=C2=A0 end
end

return {{Meta =3D get_vars}, {Str =3D r= eplace}}

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

--
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-discuss+unsubscribe-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.org= m.
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/CADAJKhCJK59eix-A_-21UfnxnuDPi6r_jZV0RNSF= 01UuFzKcbA%40mail.gmail.com.
--000000000000e5158105f2148c57--