From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/30605 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: BPJ Newsgroups: gmane.text.pandoc Subject: Re: How to tell an Inlines object from a table in a Lua filter? Date: Tue, 24 May 2022 11:13:01 +0200 Message-ID: References: <84bdd685-384d-4fc4-bee5-75344028f42fn@googlegroups.com> <0a182969-9df6-4462-aae8-28f34d5b2e37n@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000008caad905dfbe5d73" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16352"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCWMVYEK54FRBJ6DWKKAMGQEQYACD3Y-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Tue May 24 11:13:16 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-ej1-f59.google.com ([209.85.218.59]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ntQbL-00047L-A8 for gtp-pandoc-discuss@m.gmane-mx.org; Tue, 24 May 2022 11:13:15 +0200 Original-Received: by mail-ej1-f59.google.com with SMTP id ks1-20020a170906f84100b006fee53b22c2sf2458472ejb.10 for ; Tue, 24 May 2022 02:13:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1653383595; cv=pass; d=google.com; s=arc-20160816; b=B3nbV3x2dBMw5gyzCFfhrkYMszUhR520fQ07Uqkah34pk8gEo63Hfwsno8R3/cot09 2ojfQnCbH/Vo+RzXb7bdxHlI4wAmyC2KUSZ0y5EHCllefGZhFThs+1nP1+rkRARigPRq VBDt/9ssOKxP8K4GMF+ljQZbegMmRy62LZGcHXMon3Y2WcKkQc+frOSpwajn+n+nqYSP T2fJ4Qp0qvXxC3gRG5IABk50WsjFC7fG0M9KsM7nbLLf9HfKHBxq7xu2I94xTTr3S5Ds sgQJuZOSsYjWXxuOWICR5K0M1zh668FTBvYii7c7yoauqSrM8yr66UiJU/tG4OXEsbaU cueg== 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=ojyh02ovpzVf5PVLGVU609yZ0mXSj7lc+/EoDhLMWdA=; b=bRzLlgD03BYIbcrnqYwiRCtuXlhIyQYzEy0zXWjnjKBPkUq/UaIf5kg7UHDTdN2B8r P4wYSUi9Ia72ZxV/mb7zknxslp7bxgqsk4dB1F0i5nItOi5qsXhbFc4GZQEJgaZgtYE6 uoFI0BYJMZca7tmEu1+iHVRtphTOM98QD/pr2Nv0V2ZRf4MjVGuzBon+OxoCJv+3nOCp nbQ6unVEXrWGAeFRfrCCvwWiRUxOewdRE7YA6087V6/xoGYqeW564kbrGAtkt6Roi5qJ tQhjyoP3vXX39JcqQL7OGUE14eD9FrcNiQpufswJKpyHpEmrIpQHQigfN5qoY7nNAoah y/fg== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.208.46 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=sender:mime-version:references:in-reply-to:reply-to:from:date :message-id:subject:to:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=ojyh02ovpzVf5PVLGVU609yZ0mXSj7lc+/EoDhLMWdA=; b=WMHyGmS368gNbWMEcUkARAckrFHwxVAsIsVzFOwcoXz4doeVrtrR3SSlCBpXCsGskT 4xDQdrHBAgbemAf5g1Bwdkaq4xCM5H8IgHF40ofIu5h0itExEeiFRPAIzdgk5+ApWKuC zSPkelLmiLuyFXLGeff2LluztyHgleasW9cxTx9LXB4CTV1ORYzzSx/pYv//0+yFZ10y Gai/UjX7Fit9HaqPb3kL5Hjx4h/FuPhG7z0SZtLvLz3lJ6egzeemRTQyVN7C0PMrW3Uj LRMhBpGfQD4L/snhgHHMehIdTM61dK22JRoMzJlo67x4L3jDSl/le1ESyXondJnbxMMQ Q/gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:mime-version:references:in-reply-to :reply-to:from:date:message-id:subject:to:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=ojyh02ovpzVf5PVLGVU609yZ0mXSj7lc+/EoDhLMWdA=; b=5hXuhb+ZNvB/U2zJaUP/X3gz951f27Ig4Z7anMgsCr5DeX42v1QerU/kNmLOUZf0dc PS67X9D/MDa8mGCAmkdgrITtxUhImQTBk3UpEf4+t0P3P5lT0OJ8FG+9dKAD7CxtN28o hGfACRCt1oes619sI+vXVqYGiDqp+teh/FoQrsDymNigGD0fCx5E5KHzCtDT/3CS1kk5 um1dAjCyKIis0/ZzG5Dm27KVkkoxgT/QsOIxxCHwBT0E/Mq1weBldoNwZvM+UYR7Ktpb QWdnjyaGGNnQzRZJguUYTptHlmDlcXM4U4vk3sDRPFPf91Loqa2AOuwd+ZpE5YcwmWAq 7erg== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM533VgXKneRwBUpCekaiOBC86G5YI8TcRusYlbIJfxWQ1aWQQ51f4 puu9RQPm3ep99Fafp4siTKc= X-Google-Smtp-Source: ABdhPJzyK/VY46QySIcIXIQ+jh50ynBP7WUw1kcy9QJG+kQaUTPRWdiWX0q1qjqeqE0nA+zr94nAqg== X-Received: by 2002:aa7:d6d0:0:b0:42a:a617:7664 with SMTP id x16-20020aa7d6d0000000b0042aa6177664mr28747067edr.161.1653383594983; Tue, 24 May 2022 02:13:14 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a17:906:70cf:b0:6fe:d027:3c1f with SMTP id g15-20020a17090670cf00b006fed0273c1fls3344596ejk.2.gmail; Tue, 24 May 2022 02:13:10 -0700 (PDT) X-Received: by 2002:a17:906:e07:b0:6fe:8f00:cb0d with SMTP id l7-20020a1709060e0700b006fe8f00cb0dmr23171066eji.332.1653383590656; Tue, 24 May 2022 02:13:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653383590; cv=none; d=google.com; s=arc-20160816; b=lgvD6QlR1t0KUnGt9yEGjeYJBPi3l2lEHmMwWnDiuJeDxtgwz104AUtS7t9dSGSrWs PcbCHqozPncE7a8L4949rIL1fmH4p+opRTL++6riq+hTi5Y+49se7r6amDHv0VTqzip/ gXdFIqQrmlLFzRFBuutinBtpKUXIZyYYsmrinC4BYYzuWLV4MEP0dpG4DErc6xzmeh25 KrhT6ATJqeCQASBmnWzAJUAGio2X9+YLDMqC+e1w/VB6tLDS1Tys3PGo45T1VcQqQTqA mgahhjNGab+UatN7LvX2jTXoI6781JkgZsHW5Bcj93u75zziW4TkoDY4f73whNvoShz4 ctYw== 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=tPNv3M50U98hJhzdpfNfgnYQNQMOFoi+4kIjJh/cwik=; b=Z3XR+3ZaTv6nmhrB8RwS+zipGpzpbRC+ivaa9HFzphfsUuxBiT6+NkfsIkIkdSv84i pzp34FJlJ27jWtvXmF/JPNPveAGL5t2Bkayk27Vlmm422gDCTCAzPnbhC7M6vytw6eB8 60p17qKfIaVzW/G6OqgWnyvFHr87/lWgxKfvyaTpItRJRhCYOtDaTcTADmcZlPfjQ6ZD Fd4/JsPYO7iJNNW9G26kKIzOxAepunvD8sYpVakvsWEfVilnm5nmQcct9m/I1pFxAZVB utLZZexsdy3J1XGiV4SWEo75C/MOOXG8CCzkQuwze31PJD3fy/K3BQZg5gZxkWlaqFMO zOrw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.208.46 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Original-Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com. [209.85.208.46]) by gmr-mx.google.com with ESMTPS id k4-20020a17090627c400b006f47118d7bbsi957193ejc.0.2022.05.24.02.13.10 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 May 2022 02:13:10 -0700 (PDT) Received-SPF: pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.208.46 as permitted sender) client-ip=209.85.208.46; Original-Received: by mail-ed1-f46.google.com with SMTP id i40so22230729eda.7 for ; Tue, 24 May 2022 02:13:10 -0700 (PDT) X-Received: by 2002:a05:6402:10cc:b0:428:90ee:2572 with SMTP id p12-20020a05640210cc00b0042890ee2572mr28198961edu.103.1653383589832; Tue, 24 May 2022 02:13:09 -0700 (PDT) In-Reply-To: <0a182969-9df6-4462-aae8-28f34d5b2e37n-/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.208.46 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:30605 Archived-At: --0000000000008caad905dfbe5d73 Content-Type: text/plain; charset="UTF-8" You can use the pandoc.utils.type() function. It will return a string 'Inlines' for an Inlines object but 'table' for a regular table. Unfortunately metadata mappings are now represented as regular tables so you may have to check whether a regular table is an array or a mapping. I usually do that with a function like this: ``````lua local function is_map (val) if 'table' == pandoc.utils.type(val) then if 0 == #val then if next(val) then return true end end end return false end `````` Den tis 24 maj 2022 08:50Shane Liesegang skrev: > I've figured out a workaround, but just wondering if there's a better way > than diving into the metatables: > > ~~~ > function fix_table_strings(t) > for k, v in pairs(t) do > if type(v) == "table" then > local metatable = getmetatable(v) > if metatable ~= nil and metatable.__name == "Inlines" then > t[k] = pandoc.utils.stringify(v) > else > fix_table_strings(t[k]) > end > end > end > end > ~~~ > > On Tuesday, May 24, 2022 at 9:30:41 AM UTC+3 Shane Liesegang wrote: > >> Is there a way to tell whether a given object is a pandoc.Inlines as >> opposed to a plain Lua table? When I call `type(obj)` on it, it just >> returns "table." I note that if I print it, it shows "Inlines:" instead of >> "table:" but is there any smarter way to determine? >> >> I see some code in the Lua filters example repository >> >> that does this kind of check, but I don't know if it's crucial to that code >> or not, if something has changed recently, etc. >> >> (My use case here is walking through my Meta object and building >> something that will get passed to different functions -- if it encounters a >> nested table of data, I need to recurse, but if it's an Inlines object, I >> want to stringify it.) >> >> -- > 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/0a182969-9df6-4462-aae8-28f34d5b2e37n%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/CADAJKhBdw0MQ1d4rf9H-jr0EpCoPSw9zCORUnAjp8cztsOnsfg%40mail.gmail.com. --0000000000008caad905dfbe5d73 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
You can use the pandoc.utils.type() function. It will ret= urn a string 'Inlines' for an Inlines object but 'table' fo= r a regular table.

Unfortunate= ly metadata mappings are now represented as regular tables so you may have = to check whether a regular table is an array or a mapping. I usually do tha= t with a function like this:

``````lua
local function is_map (val)
=C2=A0 if 'table' =3D=3D pandoc.utils.type(val) then<= /div>
=C2=A0 =C2=A0 if 0 =3D=3D #val then
=C2=A0 =C2=A0 =C2=A0 if next(val) then return true end
=C2=A0 =C2=A0 end
=C2=A0 end
=C2=A0 return false
end
``````


Den tis 24 maj 2022 08:50Shane= Liesegang <liesegang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:


<= div class=3D"gmail_quote">
On Tuesday= , May 24, 2022 at 9:30:41 AM UTC+3 Shane Liesegang wrote:
Is there a way to tell whether a g= iven object is a pandoc.Inlines as opposed to a plain Lua table? When I cal= l `type(obj)` on it, it just returns "table." I note that if I pr= int it, it shows "Inlines:" instead of "table:" but is = there any smarter way to determine?

I see some code in the Lua filters example rep= ository that does this kind of check, but I don't know if it's = crucial to that code or not, if something has changed recently, etc.

(My use case here is walking through my Meta object= and building something that will get passed to different functions -- if i= t encounters a nested table of data, I need to recurse, but if it's an = Inlines object, I want to stringify it.)=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-discuss+unsubscribe-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.org= m.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/0a182969-9= df6-4462-aae8-28f34d5b2e37n%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/CADAJKhBdw0MQ1d4rf9H-jr0EpCoPSw9zCORUnAjp= 8cztsOnsfg%40mail.gmail.com.
--0000000000008caad905dfbe5d73--