From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32597 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "'William Lupton' via pandoc-discuss" Newsgroups: gmane.text.pandoc Subject: Re: Lua Filter: Detect Type of Inlines Date: Sat, 13 May 2023 11:56:12 +0100 Message-ID: References: <4d901ab9-179d-4274-8ce9-fdf36056905fn@googlegroups.com> <87o7mpqwfd.fsf@zeitkraut.de> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000087ba8205fb9112de" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14395"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBCS4HJ6WSAHBBWOZ7WRAMGQEA6TPNRY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sat May 13 12:56:29 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-ej1-f55.google.com ([209.85.218.55]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pxmvN-0003YA-1x for gtp-pandoc-discuss@m.gmane-mx.org; Sat, 13 May 2023 12:56:29 +0200 Original-Received: by mail-ej1-f55.google.com with SMTP id a640c23a62f3a-965d2422ae1sf1028929666b.2 for ; Sat, 13 May 2023 03:56:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683975388; cv=pass; d=google.com; s=arc-20160816; b=y6rNbDC7E9h7JE01YTFLx+jlbAWhMWnFw403Ha6AWmeFKn3h2jGfwXRFdLl2ZY2pZB EHvyv2dRtwBmwlaz/M4Qotv3qSZdVFjVQQR1/Qap1A94yohONybp0oxzNmGjJKUKL5Ci jT8kgLDsvXaMuKLaT7wZ6IeWfHBtPwVzrJIaHryLb0pJBKW0+JTclhoAZZiCnl9DcEFD j0ah4H2ezduiRSNFCagQZsJcfLV4vEV2RJYb53VKq3aCn5A/s7CiSje0nVWCpyGkysXZ 5+9iJZR7upy2o2rQWpnau3dAaJIjtu55LM462aF705jW6c4pAZYkv5FKB/GOZqA2ExJd Qu7Q== 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:reply-to:to:subject:message-id:date :from:in-reply-to:references:mime-version:dkim-signature; bh=IKq+TV3smWCwbxNhMkP8mq5Pq2O9bv9cGb5VxOnexKg=; b=XNdEGlXSVM/K0O4J22H0YDZLIJNh08XyOLkgzgnavTY/Za99o/bvF71mnntQyqg1fa UPQUk/WOSEpXWaCgJkdmRA4bAWb6mdOFbmfcqU9tmtV771q4CvS9xl1erTOUxBsCaqEm JYhkKNCFQn9v1a34kV2edBmu2r5jyWSzTCIsdyAwOy3cgOr9olu16eV2pxuU9uk80g52 KPVaPf0+lxLBfl0398s2hKMXJdhK2HCL4HXzwAFjSdIU3bXauQUhV+dhcLpwqgtIiFBr JJSvz8cFyA3YwN72MPCW7fSmnEREthtTBJcqjTq2thISazCQ6gjalrWlgbh1ImJ5M64n 5Xog== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@broadband-forum.org header.s=google header.b=VsmRdh31; spf=pass (google.com: domain of wlupton-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.org designates 2a00:1450:4864:20::52d as permitted sender) smtp.mailfrom=wlupton-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadband-forum.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20221208; t=1683975388; x=1686567388; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender:to:subject :message-id:date:from:in-reply-to:references:mime-version:from:to:cc :subject:date:message-id:reply-to; bh=IKq+TV3smWCwbxNhMkP8mq5Pq2O9bv9cGb5VxOnexKg=; b=Q5U2D875191KcAXemHLVO1nnwuTS1FXJsMmP2XrE1ZtpCbBdzfms2gwjMfoRZpetaE DffW+mgYrOIwP2aEjK5c49Tu2yYeTsYIZ0z+i6jF9JMYdykFcWkCaWsAhww5D6+iEpJe Fy87gkNxx39V89ybZ66Dxm9ew0Udk4ZaciG8HZzkM4Kuwddxlz0J5CWzjvqp/VNYEPmx F256fLyydagG1E93gIb5MCkHWl8fIC5xZMYWoAZXacgwAXJfw9I4kBJFSa5uIeCUiC+U NH++Q/FlKrcBc1/ds8pJXc3ooG512ikjmJWXYU9T+Lt/YcckABemzBVhurLTZAvRcdCl 9p X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683975388; x=1686567388; 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-authentication-results:x-original-sender:to:subject :message-id:date:from:in-reply-to:references:mime-version :x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IKq+TV3smWCwbxNhMkP8mq5Pq2O9bv9cGb5VxOnexKg=; b=lWLundLsKBB5bCYv/Yor6g9SCKo6u+cwn1SfN5GYKXQvl/eKmMjNyt+wt63cYoLnz4 gZlmNUri0n8Wz3WKTv/xoWAxNsji+Obzrj+AYvP8Mz91l3miHYyASr+46urdsY5WekqI 5Ry+kJnhoHN4bBi+ZHUdW/ALJkNfRU/aPfi5iuMWQY2J4z8dmWIOAKP+uLLyoInyfTA+ onYHnl+mp6IANznjvePqN4hu0RPjkqPxMaqjxOm3cdbY4tvnAOIXcg59ZLeHBWkZCTPs +F9dLhx8+H1C+ X-Gm-Message-State: AC+VfDy+qz2SOE7Ye0a1tUdt9g4LGmHMOr0RUB+j0EHOYnOL32yPTPnT nYVXafoSdxGbYq9K8hDhVac= X-Google-Smtp-Source: ACHHUZ5oTz/0QxKYIwYAzXVg5FkOkoSs1hQdv8PatVEsKtuaxYEubt0J6Czcy7XwGyBTKm+ZjQfAfw== X-Received: by 2002:a17:906:5a49:b0:94b:d619:e773 with SMTP id my9-20020a1709065a4900b0094bd619e773mr10892602ejc.15.1683975388737; Sat, 13 May 2023 03:56:28 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:aa7:d784:0:b0:50c:9b3f:9e75 with SMTP id s4-20020aa7d784000000b0050c9b3f9e75ls1288975edq.1.-pod-prod-03-eu; Sat, 13 May 2023 03:56:24 -0700 (PDT) X-Received: by 2002:a05:6402:685:b0:50b:d553:381e with SMTP id f5-20020a056402068500b0050bd553381emr20390246edy.9.1683975384062; Sat, 13 May 2023 03:56:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683975384; cv=none; d=google.com; s=arc-20160816; b=fefFuLSvXhOUfWh4PfFFwrdMOFECOeXl656OOGfVwq1SL+uKc7MbfTtZWuTVeIlI3S +PE6/3fcpSPg53ke0CR9uoW0cBOslaRr0804GnrAec8NFqEA4EIUO/CzXhuDMlBTy5kK NvU6ztDll5WC6cqE9wV1C2e7ZbIJtlxIBIzhMqtHvO7XdeabZF2eHzEGjwkxiAj2nKnH z8W+yKHMvzFIxkOPBo2OZ11AnnnEoDslEHg+YjZNS9tTE4Z40oZE1cs+1TV/am86l5oi TBzu1/qc1nul29fuoSSXySZda2VjGEVmWf95/0Hv8Vd3gAxi45x5RgqCChcvh1051C3f ozFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=9ckYYpTfnoa1yVPkKQzvZDvDBnV9L0sVf8Ks1VfCNwo=; b=h3aGzV6JFoe2xBFR25jU9pqVIeyeY3CPYAgIcHHM5NVb1K9Ilwy/9sOv/8tr/lhFrl cqg7jwltPw1DN3rGGPx0VRoCqMZQOkKlB9U4szLUNZfMx+amk9F9rIZLGPkyrjpaNgC+ 3fbPie1AJgnBmRu9cHf7qXg31WyAHUfQ71SD/LwC37iOlVtxT9zJjemxs7zANhJLkKuF fyFG504ub29GTbt3wGxTTq/ORjmAEq4V2BHu9KkRY9oG+H7BBzxfnJsUxV749iOPeTZ8 rgVyg9T/Omi1MsyoW4isIaWQ4anmvYDjENUVrvdsrB7/Ngp9oCSIhTDEwkHaDvng1iR8 Wgnw== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@broadband-forum.org header.s=google header.b=VsmRdh31; spf=pass (google.com: domain of wlupton-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.org designates 2a00:1450:4864:20::52d as permitted sender) smtp.mailfrom=wlupton-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadband-forum.org Original-Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com. [2a00:1450:4864:20::52d]) by gmr-mx.google.com with ESMTPS id w15-20020a05640234cf00b00506bc68cafasi608121edc.4.2023.05.13.03.56.23 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 13 May 2023 03:56:23 -0700 (PDT) Received-SPF: pass (google.com: domain of wlupton-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.org designates 2a00:1450:4864:20::52d as permitted sender) client-ip=2a00:1450:4864:20::52d; Original-Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-50bc0117683so19223316a12.1 for ; Sat, 13 May 2023 03:56:23 -0700 (PDT) X-Received: by 2002:a17:907:26c6:b0:91f:b13f:a028 with SMTP id bp6-20020a17090726c600b0091fb13fa028mr21892441ejc.34.1683975383261; Sat, 13 May 2023 03:56:23 -0700 (PDT) In-Reply-To: X-Original-Sender: wlupton-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@broadband-forum.org header.s=google header.b=VsmRdh31; spf=pass (google.com: domain of wlupton-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.org designates 2a00:1450:4864:20::52d as permitted sender) smtp.mailfrom=wlupton-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadband-forum.org X-Original-From: William Lupton 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:32597 Archived-At: --00000000000087ba8205fb9112de Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable A couple of things: 1. This seems a good moment to mention that my https://github.com/wlupton/pandoc-lua-logging has moved to https://github.com/pandoc-ext/logging (it's redirected automatically) 2. Its logging.lua module contains this wrapper around pandoc.utils.type() (sorry for the rather non-obvious ({Inline=3D1, Block=3D1})[typ] idiom ... I no longer think that this is a particularly good idea!) logging.type =3D function(value) -- this can return 'Inlines', 'Blocks', 'Inline', 'Block' etc., or -- anything that built-in type() can return, namely 'nil', 'number', -- 'string', 'boolean', 'table', 'function', 'thread', or 'userdata' local typ =3D pandoc.utils.type(value) -- it seems that it can also return strings like 'pandoc Row'; replace -- spaces with periods -- XXX I'm not sure that this is done consistently, e.g. I don't think -- it's done for pandoc.Attr or pandoc.List? typ =3D typ:gsub(' ', '.') -- map Inline and Block to the tag name -- XXX I guess it's intentional that it doesn't already do this? return ({Inline=3D1, Block=3D1})[typ] and value.tag or typ end On Sat, 13 May 2023 at 10:00, ThomasH wrote: > Great, thanks. > > On Friday, May 12, 2023 at 7:41:50=E2=80=AFPM UTC+2 Albert Krewinkel wrot= e: > >> >> ThomasH writes: >> >> > I want to detect the types of the inline elements of a paragraph. I >> > understand there is pandoc.utils.type() that basically does that, but >> > when I run >> > >> > function Para(para) >> > for i =3D 1,#para.content,1 do >> > print(tostring(pandoc.utils.type(para.content[i]))) >> > end >> > end >> > >> > all that is printed is "Inline" for all elements, not specific types >> > like Str, Span, Link or Image. How can I get at the specific types? >> >> The trick here is that we are using Haskell terminology: Inline is a >> *type*, and Str, Span, Link, etc. are *constructors* for this type. In >> Lua (and JSON) contexts, the property that identifies the name of the >> constructor of a value is called a "tag". Try this: >> >> ``` lua >> function Para(para) >> for i =3D 1,#para.content do >> print(para.content[i].tag)) >> end >> end >> ``` >> >> The `.t` property is an alias for `.tag` and can be used as well. >> >> I have plans to change the behavior of `pandoc.utils.type` and to make >> the function return two results. The first result would stay as-is, with >> the second result containing the constructor name. But I need to run >> more tests to ensure that this won't lead to performance degradation. >> >> >> -- >> Albert Krewinkel >> GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124 >> > -- > 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/f31b8b9b-f30e-45c6-91d5-= caddb494f5b0n%40googlegroups.com > > . > --=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/CAEe_xxj%2BmWtBs2%3DPF31Dh24VEApmG8ZAY%2B_GpWfBFEwCVPpMuw%40= mail.gmail.com. --00000000000087ba8205fb9112de Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
A couple of things:
  1. This seems a go= od moment to mention that my https://github.com/wlupton/pandoc-lua-logging has moved to= =C2=A0https://github.com/= pandoc-ext/logging (it's redirected automatically)

  2. = Its=C2=A0logging.lua=C2=A0module contains t= his wrapper around pandoc.utils.type() (sor= ry for the rather non-obvious=C2=A0({= Inline=3D1, Block=3D1})[typ]=C2=A0idiom ... I no longer think that t= his is a particularly good idea!)
logging.type =3D function(value)
=C2=A0 =C2=A0 -- this can return 'Inlines', &#= 39;Blocks', 'Inline', 'Block' etc., or
=C2=A0 =C2=A0= -- anything that built-in type() can return, namely 'nil', 'nu= mber',
=C2=A0 =C2=A0 -- 'string', 'boolean', 'ta= ble', 'function', 'thread', or 'userdata'
= =C2=A0 =C2=A0 local typ =3D pandoc.utils.type(value)

=C2=A0 =C2=A0 -= - it seems that it can also return strings like 'pandoc Row'; repla= ce
=C2=A0 =C2=A0 -- spaces with periods
=C2=A0 =C2=A0 -- XXX I'm = not sure that this is done consistently, e.g. I don't think
=C2=A0 = =C2=A0 -- =C2=A0 =C2=A0 it's done for pandoc.Attr or pandoc.List?
= =C2=A0 =C2=A0 typ =3D typ:gsub(' ', '.')

=C2=A0 =C2= =A0 -- map Inline and Block to the tag name
=C2=A0 =C2=A0 -- XXX I guess= it's intentional that it doesn't already do this?
=C2=A0 =C2=A0= return ({Inline=3D1, Block=3D1})[typ] and value.tag or typ
end

On Sat, 13 May 2023 at 10:00, ThomasH <therch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Great, thanks.

On Friday, May 12, 2023 at 7:41:50= =E2=80=AFPM UTC+2 Albert Krewinkel wrote:

ThomasH <the...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> I want to detect the types of the inline elements of a paragraph. = I
> understand there is pandoc.utils.type() that basically does that, = but
> when I run
>
> function Para(para)
> =C2=A0 =C2=A0 for i =3D 1,#para.content,1 do
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 print(tostring(pandoc.utils.type(para.= content[i])))
> =C2=A0 =C2=A0 end
> end
>
> all that is printed is "Inline" for all elements, not sp= ecific types
> like Str, Span, Link or Image. How can I get at the specific types= ?

The trick here is that we are using Haskell terminology: Inline is a
*type*, and Str, Span, Link, etc. are *constructors* for this type. In
Lua (and JSON) contexts, the property that identifies the name of the
constructor of a value is called a "tag". Try this:

``` lua
function Para(para)
for i =3D 1,#para.content do
print(para.content[i].tag))
end
end
```

The `.t` property is an alias for `.tag` and can be used as well.

I have plans to change the behavior of `pandoc.utils.type` and to make
the function return two results. The first result would stay as-is, wit= h
the second result containing the constructor name. But I need to run
more tests to ensure that this won't lead to performance degradatio= n.


--=20
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124

--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https= ://groups.google.com/d/msgid/pandoc-discuss/f31b8b9b-f30e-45c6-91d5-caddb49= 4f5b0n%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://g= roups.google.com/d/msgid/pandoc-discuss/CAEe_xxj%2BmWtBs2%3DPF31Dh24VEApmG8= ZAY%2B_GpWfBFEwCVPpMuw%40mail.gmail.com.
--00000000000087ba8205fb9112de--