From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32588 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Bastien DUMONT Newsgroups: gmane.text.pandoc Subject: Re: Lua Filter: Get to parent of current element? Date: Wed, 10 May 2023 13:27:52 +0000 Message-ID: References: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10690"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBDCINCES2QJRBW5X52RAMGQEUVHVEAI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed May 10 15:27:59 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-wr1-f60.google.com ([209.85.221.60]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pwjrL-0002XD-Cn for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 10 May 2023 15:27:59 +0200 Original-Received: by mail-wr1-f60.google.com with SMTP id ffacd0b85a97d-306489b7585sf2505686f8f.3 for ; Wed, 10 May 2023 06:27:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683725279; cv=pass; d=google.com; s=arc-20160816; b=GCGgJhK26Zwavb6aGXaB2Z6ff+G9/leIwJ3WAJEtje+RuufTa98lit/fK3X3RDvsej FK6Hnr0Jkb8nMqo+fNJqQ1o13E1TixFcyMYdfeYERRrNvC6IV7ZgvVN60zc7N5ze6Ymq ID8nvF6J5iGci+yoZptSeFLNKtQjoCU7dBhahGSJah1LZxH1G36WjRRqzGTDh+CidUje UNORmxj7f4lgeocMEjc+li27Qg9SPXSf/5YZOVHMSsK5XjHJ3BjzVO+yilZKLOuD4Klb JbY1gUwAqYXXGgzUIs95jdict6zBRJNS9HCjZOzGn0qSWJQkEvamtIppVLHkL+W/NVl9 vntQ== 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:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:to:from:date:sender:dkim-signature; bh=xvy0SF9ju2i/SrH1ZX/iGLAlELExBj5r8I3nkdBZwTo=; b=yu4hGFyqnlwpoejyloUQmzPvAcU+QjlH8VE1muR3G8Zf32IjszPA1Smcan8qeV8dhc RmofIqxC+gbtUA4ANTEu6EZdu2fkHq5FdXWTjVAX0Fxiw9XSEQSrvavvLRf6J3j7h5Y9 Gya5BF9R/ZBO34yL85pjN9BY+n+0f87Z6U5RhGKGxwGARt0OayfrIP6tpDZhE3lS6zyj UaOvzRh6mvUS73H6aoEkV1QvAPgE4VdWHH56qfcqe1+02uFxhoBKAraeNCx5HRvCuSHC fIAh3b+QrxkV5AhwmQ0qEkwUVi6KLWuRDlXTaWniiFfzv174M2YXvXr0N+KwWHJf4CSn zFxQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=SbPvH3Ec; spf=pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.65 as permitted sender) smtp.mailfrom=bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20221208; t=1683725279; x=1686317279; 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:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:to:from:date:sender:from:to:cc :subject:date:message-id:reply-to; bh=xvy0SF9ju2i/SrH1ZX/iGLAlELExBj5r8I3nkdBZwTo=; b=clZDmDdW55VyTmMfxkJkKaySk5JTsZU87pMgXRpmDF+YBxLxQCM8/Y+DXF0f7APqUN jMMcn1k6YncPrZUYeVNoVAitCwkYi9YrELVEEUoY4BADO83OuqlmfPkQ3VN3XYe6Lzd5 J8cyu0dv8JcjqzQ1lqTI/Fd6fCzB4CyVLbvlwI0lEf2bPE416Yv/zcvDx2PySqnT5dTu mwJeZbQGcAdI3mDcmfv6A4oVcg270rq2ZcINe2KrPExmQDklAwFpdVjrXLKs2qfYdnf0 7lhLCdaT5K4hScEwK X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683725279; x=1686317279; 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:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:to:from:date:x-beenthere :x-gm-message-state:sender:from:to:cc:subject:date:message-id :reply-to; bh=xvy0SF9ju2i/SrH1ZX/iGLAlELExBj5r8I3nkdBZwTo=; b=XxSB0RzIZ0OCkBkoY//ikyTzHgJu5FxqS/8oqYtf3ZMMwTQtOGhacZyPohy0EoXPPo sDFyTDZX1QY0PewRM6HYkujcWPaXrw7YbHFOiAjVeJO9yresCqr03/kG7BUwmsr07Qr7 vEvBgaq6MVbfC0Hsc6yJfZRcP+haxLuUFUXRNCWRVhGgEX4TaHLMMpfe4BC+Fw171lGB A0hPns8fqPTOZerGcfNHdVxfDxSM Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AC+VfDzBWsxntTmxDAAvfrcGbRwoCgH9R9j3ezhZVt2kJGvGpmDrRtZG 6QavncSbj9KeK9M/VU0cG3U= X-Google-Smtp-Source: ACHHUZ6pAf4l2vsRxZCd+x0jM7U/LNcU6yG30wQbtKMmQfJqIlObOvSXNh51O8ONb2WUOsBzlPZX5g== X-Received: by 2002:a5d:494e:0:b0:307:8356:57ac with SMTP id r14-20020a5d494e000000b00307835657acmr1952596wrs.10.1683725279057; Wed, 10 May 2023 06:27:59 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:600c:35c1:b0:3f1:758c:dd3a with SMTP id r1-20020a05600c35c100b003f1758cdd3als981wmq.1.-pod-canary-gmail; Wed, 10 May 2023 06:27:54 -0700 (PDT) X-Received: by 2002:a05:600c:208:b0:3f4:2572:2259 with SMTP id 8-20020a05600c020800b003f425722259mr6532428wmi.28.1683725274249; Wed, 10 May 2023 06:27:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683725274; cv=none; d=google.com; s=arc-20160816; b=XmZVDd+4N16u0sqcY31zIFPYs8LfV4UZpl0uZUpcaEMe8f4OEI16XYalTgx2wJyqc6 6g2c5MqOHbNkIadh9/Vv3ey06N1JicxdqHYdG5BBpYtkM9kzLd/NnwjEq/8LDjdzV31C 5x4og5D5G8UrouKCLF7COIc5WTh1jf4ys+d5HBlpS/DsnqLuFcb1vIGnaQpRbytsMS7m uuHg4wZiMtFcK6FOTo4Uo401aw6x9lXuVZOotrmUTSfqQyo9xyi4DxeIEryhv+6kWGtC b1TZJPqGil7guNk/6QaNlWHfp797ccwD12qEdSxTlHT5CI8Dv2FyT6bL5d2ORax4cpoE RIHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:to:from:date :dkim-signature; bh=3cj2L1LNaq9xTBdXC/9gtxuFzXQpBaMB+a7N/Pr/NgI=; b=j6LCHnEn4sIBGrc1xe9Fp040VyloDbsrNn7pQXUu9NOfG/FozbaegZKVF1W3cLZv/Q xOrc2rzzOl4REMpIAQ187xaxsuKY3+WLUQQAMMYlI+IaKCnSydKkvQVqdAbo+15TcT/u +xE7JE4mu/CseYpdyRZXeMO9EMa3X6k6zNwhXDthDczH7qrmvbF9Q9lliQp/oRHu2mhE 1iksgXMVUcBVerhzwyT+b3qR0OEh5GRQ7Ap/eOHL4rAf8KTZquvtyhHSlrA8hIdYVKi5 6UH6lEd+L+kjGg3LwgmRcFUAgznVSkKC1Bfj2bXRHm+03aTjUxQWAClhBQILrV466Nip HGKg== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=SbPvH3Ec; spf=pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.65 as permitted sender) smtp.mailfrom=bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net Original-Received: from mout01.posteo.de (mout01.posteo.de. [185.67.36.65]) by gmr-mx.google.com with ESMTPS id bh24-20020a05600c3d1800b003f1951366f0si412586wmb.3.2023.05.10.06.27.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 06:27:54 -0700 (PDT) Received-SPF: pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.65 as permitted sender) client-ip=185.67.36.65; Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id C33F12407C5 for ; Wed, 10 May 2023 15:27:53 +0200 (CEST) Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4QGbS92x29z9rxB for ; Wed, 10 May 2023 15:27:53 +0200 (CEST) Content-Disposition: inline In-Reply-To: X-Original-Sender: bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=SbPvH3Ec; spf=pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.65 as permitted sender) smtp.mailfrom=bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net 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:32588 Archived-At: You cannot get directly the parent of an element, but you can use a particu= lar filter on the content of an element. Here is an example that emphasize = spans with class 'to-emphasize' in a BlockQuote in a particular way: ``` local spans_in_quote =3D { Span =3D function(span) if span.classes:includes('to-emphasize') then local _, pos =3D span.classes:find('to-emphasize') span.classes:remove(pos) return pandoc.Underline(span) end end } local function Span(span) if span.classes:includes('to-emphasize') then return pandoc.Emph(span) end end local function BlockQuote(quote) return quote:walk(spans_in_quote) end return { { BlockQuote =3D BlockQuote }, { Span =3D Span } } ``` The function BlockQuote is applied first and calls the filter spans_in_quot= e on the content of the BlockQuote. This filter transforms the Spans with t= he class 'to-emphasize' and remove that class so that it is not processed a= gain by the Span function. After the BlockQuote function returns, the Span = function is called on all Spans (including those inside the BlockQuote, tha= t's why I removed the class 'to-emphasize'!). Exemple of use: pandoc -L test.lua <<< ' Normal [text]{.to-emphasize}. > [Text]{.to-emphasize} in a quotation. '

Normal text.

Text in a quotation.

Le Wednesday 10 May 2023 =C3=A0 06:02:18AM, ThomasH a =C3=A9crit : > Hi, >=20 > is there a way to get to the parent in the Pandoc AST from the current el= ement > in a Lua filter? > I would like to distinguish treatment of elements depending on their cont= ext in > the syntax tree, e.g. handle a 'span' element differently if it is a chil= d of a > 'cell' element in a table. >=20 > Thanks, T. >=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= email > to [1]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit [2]https://groups.google.com/d/m= sgid/ > pandoc-discuss/b4305519-9dbf-4254-a3d7-7b9e1dab9d6en%40googlegroups.com. >=20 > References: >=20 > [1] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [2] https://groups.google.com/d/msgid/pandoc-discuss/b4305519-9dbf-4254-a= 3d7-7b9e1dab9d6en%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter --=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/ZFub2OlhnMQdR4zM%40localhost.