From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32828 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: BPJ Newsgroups: gmane.text.pandoc Subject: Re: Modifying metadata elements with Lua filter Date: Thu, 15 Jun 2023 18:35:00 +0200 Message-ID: References: <19962c60-238b-4ef4-bad6-a8200ca9a3cen@googlegroups.com> <64f0f40b-5c49-47fa-97f5-f824735f6cebn@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000011b9d05fe2da70c" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24145"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCWMVYEK54FRBQ73VSSAMGQEL3SMPEY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Thu Jun 15 18:35:21 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-pg1-f190.google.com ([209.85.215.190]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1q9pwN-00064o-O4 for gtp-pandoc-discuss@m.gmane-mx.org; Thu, 15 Jun 2023 18:35:19 +0200 Original-Received: by mail-pg1-f190.google.com with SMTP id 41be03b00d2f7-54fb5dd787asf584246a12.0 for ; Thu, 15 Jun 2023 09:35:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686846918; cv=pass; d=google.com; s=arc-20160816; b=fXgfykutocaoE9xcQ7o8dgiqwXsoSxbVccOCdMKdKlnCG5tz0jD1FO1w3qSmxZTf0b VflUjfrONBUkAXdxudIpYxFXfxh4vOFxUZawgaPyo3h2r99iDYhxVgH5jHPb9LYPEJCX 81x8T4m4sLOp1HbooffzVccDOo3U2jH7xgoDRc0EWkfhjf9Fr0bh1IM4PewfgYP/d3h4 02v0Vse7Pp9NZrydM6LR3syZwGQ1aavuV50QY4ougaa/EDPE4e4CzlpxQ31ed7T7axMy Bv3/W1x6Z1fQ44qzLlTOOmv274ifJ6FgbUKpCh+9W+k1hXhx1JzVeyyfOuzqEHc+ayCp WxEA== 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=63cQjEsIr6LxAkMoT3HOsm8i0z7vB1IpDZtg1jmSYjQ=; b=VLFKpEU5N/bJCbNZU8w+oo4mqXkZzcXemH7umTcxjN+Mt5YFDIZietgp0DNGo+H8av niWq+BOftHZDZrojjVkKmdv5tK30Ug9Em46EpMb5Fn19HmCvQxCGv7MxwZatx1G8LnRn 56ZTDMPxIN7NrNUz/OqN3URBJpLN2lbRCENPAU4fLwdCUDml6WCM1B/HyxizkQqIPGKs uvcbTt3gL6jZU7qHH8TMvbM3FOzeIaDcXli0Pt7LUvHpKMhrnsZhFUesAwCN0aTcrSgd phFG9/kFzyWinR4a4tM9r+KcuYRbSUsRtmdDmoeWQTwBZYbh4kOjUwmZFH9fq59U5pe7 OhxA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.219.180 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20221208; t=1686846918; x=1689438918; 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=63cQjEsIr6LxAkMoT3HOsm8i0z7vB1IpDZtg1jmSYjQ=; b=kw8DQTdzkUrJd0Hz2xMOLI8Rh16d/725pgkrHhsmuhQdJ1IEGPibnaik4qQZ5kSdsA 2Tq5Z3fFxiATPfKWVqG4BsH+wdT9aG+CAhUsIQrs/GX7Y3w0M1NsM/70JK+zNtg1u9Fx tHF6GReOKtOy5tMdBAaLUlcLofxQh2EdsVErV5lO+PZoKUdF+9zeVCwkpK+lekY03n0n cHBoN43wAEq8YRjG0lpkBafy/qWXUiscIRayVySxdDy57wI4NezWXZGXwURDItIEoU7x 5dNherDwC2ZfNStHSKMd7vgPCaon63/x81kVnvpa/GvN5xvA7vRYaP3yPeaWs+ncKPrB X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686846918; x=1689438918; 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-beenthere:x-gm-message-state:sender:from:to:cc:subject:date :message-id:reply-to; bh=63cQjEsIr6LxAkMoT3HOsm8i0z7vB1IpDZtg1jmSYjQ=; b=bT/lGqWJcZ/jgjPsaYyGRVw23uC4lUOmVbtjo99yfrN8+UBOv7Y8NRn+OMXR7+SiIV fsWdFCkPjAsWBf2f1Kuv8kRZSFdshFM7pENWC9Xi9kS2GJlYWoqD71USAXpIDTuZPs5m KYrErWnnbioftd/pXeuhrSYkk6+uww9v4g6fYyBL2+ZkCk8Scd7eXoT05pLwu8m7TvGM eee+ZiAKOso0bJBfP9XxFelyFvsNOwkHbSUzW9DHx8iq5q1CqU6HQHOlY56yCqNgjo8S vwk0Jr Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AC+VfDzUZHB2puZvqhrJU3RtMOs58gpMB7KT8QTxjz0MqbvyKXkGePyX LTHbItRr6aLacO7Ou5nFX3A= X-Google-Smtp-Source: ACHHUZ5jDLsE73GKUegVs+2W1XRAiEZaqS8ViyOH0slatEqDtsg+c9QHWiz3nUwD0Dk4lnqAVit6Jw== X-Received: by 2002:a17:902:ec85:b0:1b0:f31:a386 with SMTP id x5-20020a170902ec8500b001b00f31a386mr8040496plg.26.1686846918410; Thu, 15 Jun 2023 09:35:18 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a17:903:2310:b0:1b0:5541:f3bd with SMTP id d16-20020a170903231000b001b05541f3bdls1698700plh.0.-pod-prod-00-us; Thu, 15 Jun 2023 09:35:14 -0700 (PDT) X-Received: by 2002:a17:902:ea01:b0:1af:ea40:34f2 with SMTP id s1-20020a170902ea0100b001afea4034f2mr7170972plg.11.1686846914329; Thu, 15 Jun 2023 09:35:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686846914; cv=none; d=google.com; s=arc-20160816; b=0NJ74aMB9B5OhWLwy8YppESx//cUnhDXm6KqVrqfAqWwzIr8UBVAxKcaikIDw8EWrY ILCUm7CksRpfe3qAXi9bDj5Tfdd6/b1Lx7JEksU+drUcMPVn5ZaXw14jMYnqrqk7sAT5 s17wMF9emPmi1tlh0bGkCsVi7H0VfzwsvWpP9YbS20v1sKOEH1D+a0tgpeLID5Kq+cpv Eyv6yLam/37xQywdzJ0ZlnKl8vgAKZvlZFYiktrCKDSArc/zwLD82SA3j59anmw7AJih tG+zSff2TlY31zlpa/4YYnLAOPAardeGcIqBJ+7u2JT4TpiZ0vdv0W+Y+/3g7dKuweuM ESLw== 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=C2aWjd0Fq71LPwO0jtwjxx/kqsZDqolpm3/41BHBAgo=; b=dv54xnhjDubPZVFPnWeq80m+YNPkvJNQQyllsjMqvt9duycu0U+yKluDLryn74M1od pcmhHzniqgitMrs8MUfOJmg4IyVL3+iBjQ6qyPyUqQRLO7tuhbek7snnddKlivqF3edB 3FJ22AJAgICdscEak6b3/UIqTUJu1Iu9QL++Dv5TK3WIK3j6K3jSU7ecI47YaAouyHJB YSQA/HHxXV3j8+vZNr9pMDIb7yLGkhoL9KKXfzFHIgW/Gky8Nx/l0qMWdbqJONiFvrlu hfLOH7gDl5Iythd9032JvpbkEVb/1ixhum2t1Ql1TmY9M2/A6/QAYUfWRA1wGF3MwNTM 0dTw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.219.180 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Original-Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com. [209.85.219.180]) by gmr-mx.google.com with ESMTPS id lk15-20020a17090308cf00b0018712ccd6e0si1246407plb.2.2023.06.15.09.35.14 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Jun 2023 09:35:14 -0700 (PDT) Received-SPF: pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.219.180 as permitted sender) client-ip=209.85.219.180; Original-Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-b9a6eec8611so1570876276.0 for ; Thu, 15 Jun 2023 09:35:14 -0700 (PDT) X-Received: by 2002:a25:da84:0:b0:ba9:b304:107b with SMTP id n126-20020a25da84000000b00ba9b304107bmr6656156ybf.27.1686846912403; Thu, 15 Jun 2023 09:35:12 -0700 (PDT) In-Reply-To: <64f0f40b-5c49-47fa-97f5-f824735f6cebn-/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.180 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:32828 Archived-At: --000000000000011b9d05fe2da70c Content-Type: text/plain; charset="UTF-8" It is better to not hard code the number of authors: ``````lua function Meta (meta) if 'docx' == FORMAT then if 'List' ~= pandoc.utils.type(meta.author) then -- hopefully Inlines return nil elseif 1 == #meta.author then -- only one meta.author = meta.author[1] else -- more than one -- Define once, use many times local sep = pandoc.Inlines(", ") -- DWIM -- Initialize to an empty list and use `:extend` to populate local authors = pandoc.Inlines({ }) -- Loop through any number of authors for i, author in ipairs(meta.author) do if 1 == i then -- no comma for the first authors:extend(author) else -- append ", A. U. Thor" authors:extend(sep .. author) end end -- Put them back meta.author = authors -- We have modified, so return it return meta end end return nil -- nothing modified end `````` Den tors 15 juni 2023 17:18Stephan Boltzmann skrev: > Thanks a lot for your help, which enabled me to write the following short > filter, which puts the name of all authors on the same line in 'docx' > output, while preserving the nice default layout in 'latex' output. > Debugging filters working on the yaml metadata provided a particular > challenge to me: > > function Meta (m) > if FORMAT:match 'docx' then > authors = m.author[1] .. {pandoc.Str(', ')} .. m.author[2] > m.author = pandoc.MetaInlines(authors) > end > return m > end > > It only handles two and not more authors, but in my case, that's fine. > William Lupton schrieb am Mittwoch, 14. Juni 2023 um 18:55:04 UTC+2: > >> Your metadata has this structure (hmm... perhaps some of the Inlines are >> really MetaInlines, in which case that's a problem with my logging module): >> >> (#) meta Meta { >> author: List[2] { >> [1] Inlines[3] { >> [1] Str "Author" >> [2] Space >> [3] Str "A" >> } >> [2] Inlines[3] { >> [1] Str "Author" >> [2] Space >> [3] Str "B" >> } >> } >> title: Inlines[1] { >> [1] Str "Test" >> } >> } >> >> ... so I think you want this filter (MetaInlines isn't an attribute name, >> and you have to count the space): >> >> function Meta (m) >> print(pandoc.utils.stringify(m.author[1][3])) >> end >> >> On Wed, 14 Jun 2023 at 17:47, Stephan Boltzmann >> wrote: >> >>> Hello everybody out there using Pandoc, >>> >>> For the following short document, >>> --- >>> title: Test >>> author: >>> - Author A >>> - Author B >>> --- >>> # Introduction >>> >>> I would expect the Lua filter >>> >>> function Meta (m) >>> print(pandoc.utils.stringify(m.author[1].MetaInlines[2])) >>> end >>> >>> to print out "A", but it prints nothing at all. >>> >>> What is the conceptual misunderstanding I have here? >>> >>> -- >>> 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/19962c60-238b-4ef4-bad6-a8200ca9a3cen%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/64f0f40b-5c49-47fa-97f5-f824735f6cebn%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/CADAJKhBGcd4TracBv-Xy_K4-sx_Qy688WZCcZNa1%2BcU0Yc4Daw%40mail.gmail.com. --000000000000011b9d05fe2da70c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
It is better to not hard code the number of authors:

``````lua
<= div dir=3D"auto">function Meta (meta)
=C2=A0 if '= ;docx' =3D=3D FORMAT then
=C2=A0 =C2=A0 if '= List' ~=3D pandoc.utils.type(meta.author) then
= =C2=A0 =C2=A0 =C2=A0 -- hopefully Inlines
=C2=A0 =C2= =A0 =C2=A0 return nil
=C2=A0 =C2=A0 elseif 1 =3D=3D = #meta.author then -- only one
=C2=A0 =C2=A0 =C2=A0 m= eta.author =3D meta.author[1]
=C2=A0 =C2=A0 else -- = more than one
=C2=A0 =C2=A0 =C2=A0 -- Define once, u= se many times
=C2=A0 =C2=A0 =C2=A0 local sep =3D pan= doc.Inlines(", ") -- DWIM
=C2=A0 =C2=A0 = =C2=A0 -- Initialize to an empty list and use `:extend` to populate
=C2=A0 =C2=A0 =C2=A0 local authors =3D pandoc.Inlines({ })<= /div>
=C2=A0 =C2=A0 =C2=A0 -- Loop through any number of a= uthors
=C2=A0 =C2=A0 =C2=A0 for i, author in ipairs(= meta.author) do
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if 1 =3D= =3D i then -- no comma for the first
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 authors:extend(author)
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 else -- append ", A. U. Thor"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 authors:extend(sep .. author)<= /div>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 =C2=A0 -- = Put them back
=C2=A0 =C2=A0 =C2=A0 meta.author =3D a= uthors
=C2=A0 =C2=A0 =C2=A0 -- We have modified, so = return it
=C2=A0 =C2=A0 =C2=A0 return meta
=C2=A0 =C2=A0 end
=C2=A0 end
=C2=A0 return nil -- nothing modified
= end
``````

Den tors 15 juni 2023 17:18Ste= phan Boltzmann <stephan2boltzmann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
<= /div>
Thanks a lot for your help, which = enabled me to write the following short filter, which puts the name of all = authors on the same line in 'do= cx' output, while preserving the nice default layout in 'latex' output.
De= bugging filters working on the yaml metadata provided a particular challeng= e to me:

function Meta (m)
=C2=A0 if FORMAT:match 'docx' then
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 authors =3D m.author[1] .. {pandoc.Str(', '= ;)} .. m.author[2]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 m.author =3D pandoc.MetaI= nlines(authors)
=C2=A0 end
=C2=A0 return m
end
It only handles two and not more authors, but in my case, that= 's fine.
William Lupton schrieb am Mittwoch, 14. Juni 2023 um 18:55:04 = UTC+2:
Your metadata has this structure (hmm... perhaps some of the Inlines are = really MetaInlines, in which case that's a problem with my logging modu= le):

(#) meta Meta {
=C2=A0 = author: List[2] {
=C2=A0 =C2=A0 [1] Inlines[3] {
=C2=A0 =C2=A0 =C2=A0= [1] Str "Author"
=C2=A0 =C2=A0 =C2=A0 [2] Space
=C2=A0 =C2= =A0 =C2=A0 [3] Str "A"
=C2=A0 =C2=A0 }
=C2=A0 =C2=A0 [2] In= lines[3] {
=C2=A0 =C2=A0 =C2=A0 [1] Str "Author"
=C2=A0 =C2= =A0 =C2=A0 [2] Space
=C2=A0 =C2=A0 =C2=A0 [3] Str "B"
=C2= =A0 =C2=A0 }
=C2=A0 }
=C2=A0 title: Inlines[1] {
=C2=A0 =C2=A0 [1]= Str "Test"
=C2=A0 }
}

= ... so I think you want this filter (MetaInlines isn't an attribute nam= e, and you have to count the space):

function Meta (m)
=C2=A0 =C2=A0 print(pandoc.utils.stringify= (m.author[1][3]))
end

<= /div>
On We= d, 14 Jun 2023 at 17:47, Stephan Boltzmann <stephan2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
He= llo everybody out there using Pandoc,

For the foll= owing short document,
---
title: Test
author:
=C2=A0 - Author A
=C2=A0 - Author B
---
# Introduction

I would expect the Lua filter

function Meta (m)
=C2=A0=C2=A0=C2= =A0 print(pandoc.utils.stringify(m.author[1].MetaInlines[2]))
end
=

to print out "A", but it prints nothing= at all.

What is the conceptual misunderstanding I= have here?

--
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...@googlegr= oups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-= discuss/19962c60-238b-4ef4-bad6-a8200ca9a3cen%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 pandoc-discuss+unsubscribe@goo= glegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/6= 4f0f40b-5c49-47fa-97f5-f824735f6cebn%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://group= s.google.com/d/msgid/pandoc-discuss/CADAJKhBGcd4TracBv-Xy_K4-sx_Qy688WZCcZN= a1%2BcU0Yc4Daw%40mail.gmail.com.
--000000000000011b9d05fe2da70c--