From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32833 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephan Boltzmann Newsgroups: gmane.text.pandoc Subject: Re: Modifying metadata elements with Lua filter Date: Fri, 16 Jun 2023 03:09:34 -0700 (PDT) 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/mixed; boundary="----=_Part_1902_47484506.1686910174909" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24166"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCZ25UWY24ERBYHJWCSAMGQEJSDGCVA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Jun 16 12:09:39 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oa1-f59.google.com ([209.85.160.59]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1qA6Oh-00069X-29 for gtp-pandoc-discuss@m.gmane-mx.org; Fri, 16 Jun 2023 12:09:39 +0200 Original-Received: by mail-oa1-f59.google.com with SMTP id 586e51a60fabf-1a6545aa0e0sf576535fac.3 for ; Fri, 16 Jun 2023 03:09:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20221208; t=1686910178; x=1689502178; 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=SZTg3Aw03BBPJyQXKTldQWV/jWPmFEyzTMk7wIahX3A=; b=EkaZvM9gpsTUHhtO6+2Q0wmT5JG4upbNxhtO8N97VRpQGISZGxpXVp3/p4Iw06c4FW i3oCMPKvGhSKVx7mf7nSFC+++dSyEGfLGZ2K0cNQE2z6CRJnHAHXjMT1DOGVMiiMX9JS Du9Xrywsj2RSM5cV74WW5jtE9TQpZkMepxL1NmHIAAw1RsyKt/FkUBAjmcIS1R/qkJtN Eq6o5OtaRrI3JZnM8O+SxlIevwkak31Z4zxLSN0GxcXytXezafV2KkfJaTFmr6fE6PM/ NVniG03iTwYvLsTXzcUX5dMF5AGybe7J5e4vokccaY0aLOejvuc2dee0Pu7G/N9IzHci L4Rg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686910178; x=1689502178; 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=SZTg3Aw03BBPJyQXKTldQWV/jWPmFEyzTMk7wIahX3A=; b=jn7uuV3Bfeak+7OHZ4fkt/jt54HHGo4HEYT9a6Ed3zo9I7n6JwaCDocIxRpZm0e6+9 t7QOfbG1Byx7xxQqILwxlvcd/HerGRq1x7zPlll5FLBINtwFVDDYbPIQK16gMUNXtNT4 OS4ND+9Ma6bUXYMGfbFZNfTm1UPOrMbo616bQKPNiOCyZEbd6hyTeqdn3v7IJABHahkQ l2rcHm6DGCONu0VWezguqnrm34k1Stud/TSBQaug0Fu+RfvyljXAcWX7F1vbyYvqgwcm +lptv/Fox3tLo3FQkMdhgDgLgbphQQfPSq4uAom5t44q9rHz0vsgtdg6tV6v2/EcEpUe YxOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686910178; x=1689502178; 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-beenthere:x-gm-message-state:sender:from :to:cc:subject:date:message-id:reply-to; bh=SZTg3Aw03BBPJyQXKTldQWV/jWPmFEyzTMk7wIahX3A=; b=lsugVNoYJ7dsqk1L9H+hQC9CfPoI+CLsAcVqIHvneR+Pf/mGbVvDMvrzCQUJd2wQxo /kPqUfQ/e3eFvioKN5D+0NTzyOu1mqWcQ5BT4Ch3S2YxhKjRpVNJIX8XNai15IqC8vWG NgiJJ5SDY0LfvNDtSUIrfZi/fRrYDLc2ENnkvXcQ26xeCRtfn9EyA6sEEXfmi+5E6SYZ uxDMViC+jblh8Hrkq4oAncpXBuNXXFdFSHqSwq/lI3SjuGtw9VCB2/Mkb3ZWnEU7SgG/ dkhezlH5jAevyeHsWuaeLnDrz/5H+i4KFJMYpPgaoMK3qAA/6j Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AC+VfDx1t0aCcfvtbvYCfupYX3IWjjJ9getPU6Q51sMlvzYZtLpcBkyt KwIaTHoi2xELO5ChV/db4Vw= X-Google-Smtp-Source: ACHHUZ7QAezuwvQ4N6RzVVy2JwOZVwb9lq+D/UiEFlGUbauUNAqSpveDH4tzcTfUnEfvFfg42JONcw== X-Received: by 2002:a05:6870:b147:b0:19f:8566:c210 with SMTP id a7-20020a056870b14700b0019f8566c210mr1235332oal.37.1686910178017; Fri, 16 Jun 2023 03:09:38 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6870:4b45:b0:19f:3c91:db38 with SMTP id ls5-20020a0568704b4500b0019f3c91db38ls999325oab.0.-pod-prod-08-us; Fri, 16 Jun 2023 03:09:35 -0700 (PDT) X-Received: by 2002:a05:6870:3a2e:b0:19f:ad5f:b7e8 with SMTP id du46-20020a0568703a2e00b0019fad5fb7e8mr449247oab.8.1686910175663; Fri, 16 Jun 2023 03:09:35 -0700 (PDT) In-Reply-To: X-Original-Sender: stephan2boltzmann-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:32833 Archived-At: ------=_Part_1902_47484506.1686910174909 Content-Type: multipart/alternative; boundary="----=_Part_1903_1965464144.1686910174909" ------=_Part_1903_1965464144.1686910174909 Content-Type: text/plain; charset="UTF-8" Thanks a lot for your solution. With your help and the logging module, programming Lua filters for Pandoc is starting to be fun and I came up with this solution by myself: function Meta (m) if FORMAT:match 'docx' then authors = pandoc.List:new() for i, author in ipairs(m.author) do if m.author[i] then authors = authors .. author .. {pandoc.Str(', ')} else authors = authors .. author end end m.author = pandoc.MetaInlines(authors) end return m end BPJ schrieb am Donnerstag, 15. Juni 2023 um 18:35:18 UTC+2: > 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-discus...-/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/af26503b-81f1-49eb-9f55-ac4186358c3cn%40googlegroups.com. ------=_Part_1903_1965464144.1686910174909 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks a lot for your solution.
With your help and the logging module, programming Lua= filters for Pandoc is starting to be fun and I came up with this solution = by myself:

function Meta (m)
=C2=A0 if FORMAT:match 'docx' then
=C2=A0 = =C2=A0 authors =3D pandoc.List:new()
=C2=A0 =C2=A0 for i, author in ip= airs(m.author) do
=C2=A0 =C2=A0 =C2=A0 if m.author[i] then
=C2=A0= =C2=A0 =C2=A0 =C2=A0 authors =3D authors .. author .. {pandoc.Str(', ')}=C2=A0 =C2=A0 =C2=A0 else
=C2=A0 =C2=A0 =C2=A0 =C2=A0 authors =3D = authors .. author
=C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 end
=C2=A0 =C2=A0 m.author =3D pandoc.MetaInlines(authors)
=C2=A0 end
=C2=A0 return m
end


BPJ schrieb am Donners= tag, 15. Juni 2023 um 18:35:18 UTC+2:
It is better to not hard code th= e number of authors:

``````lua=
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 meta.author =3D meta.author[1]
=C2=A0 =C2=A0 else -- more than one
=C2=A0 =C2=A0 = =C2=A0 -- Define once, use many times
=C2=A0 =C2=A0 = =C2=A0 local sep =3D pandoc.Inlines(", ") -- DWIM
=C2=A0 =C2=A0 =C2=A0 -- Initialize to an empty list and use `:ext= end` to populate
=C2=A0 =C2=A0 =C2=A0 local authors = =3D pandoc.Inlines({ })
=C2=A0 =C2=A0 =C2=A0 -- Loop= through any number of authors
=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)
<= div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 else -- append ", A. U. T= hor"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 authors= :extend(sep .. author)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 e= nd
=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 authors
=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 modifie= d
end
``````

Den tors 15 juni 2023 17:18Stephan Boltzmann = <stephan2...@gmail= .com> skrev:
Thanks a lot for your help, which enabled me to writ= e the following short filter, which puts the name of all authors on the sam= e line in 'docx' out= put, while preserving the nice default layout in 'latex' output.
Debugging filters wo= rking on the yaml metadata provided a particular challenge 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.MetaInlines(authors)=C2=A0 end
=C2=A0 return m
end

It on= ly handles two and not more authors, but in my case, that's fine.
Willi= am Lupton schrieb am Mittwoch, 14. Juni 2023 um 18:55:04 UTC+2:
Your metadata ha= s this structure (hmm... perhaps some of the Inlines are really MetaInlines= , in which case that's a problem with my logging module):

(#) meta Meta {
=C2=A0 author: List[2] {<= br>=C2=A0 =C2=A0 [1] Inlines[3] {
=C2=A0 =C2=A0 =C2=A0 [1] Str "Aut= hor"
=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] Inlines[3] {
=C2= =A0 =C2=A0 =C2=A0 [1] Str "Author"
=C2=A0 =C2=A0 =C2=A0 [2] Sp= ace
=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&quo= t;
=C2=A0 }
}

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

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

On Wed, 14 Jun 2023 at 1= 7:47, Stephan Boltzmann <steph= an2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">
Hello everybody out t= here using Pandoc,

For the following short documen= t,
---=
title: Test<= /span>
author= :
=C2= =A0 - Author A
=C2=A0 - Author B
---
# Introduction

I wou= ld expect the Lua filter

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

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

<= /div>
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/pando= c-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 pa= ndoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.

--
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/af26503b-81f1-49eb-9f55-ac4186358c3cn%40googlegroups.= com.
------=_Part_1903_1965464144.1686910174909-- ------=_Part_1902_47484506.1686910174909--