From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32590 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Albert Krewinkel Newsgroups: gmane.text.pandoc Subject: Re: Lua Filter: Get to parent of current element? Date: Wed, 10 May 2023 16:57:19 +0200 Message-ID: <87sfc4ql6b.fsf@zeitkraut.de> References: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22144"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBCZJF7XJTILRBUXG52RAMGQETCVE4WY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed May 10 17:08:08 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-lf1-f59.google.com ([209.85.167.59]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pwlQE-0005X7-UD for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 10 May 2023 17:08:06 +0200 Original-Received: by mail-lf1-f59.google.com with SMTP id 2adb3069b0e04-4edbdd8268bsf4034439e87.2 for ; Wed, 10 May 2023 08:08:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683731286; cv=pass; d=google.com; s=arc-20160816; b=HzZUm6e4Oz8Mf93W1feWpwl3Ou7TZGCNJUTx2+ApxI/gGZkvbixQ3vVIR5QqHtjKS5 V7N84SSlOh96Wsx+5xIBVHvb91xg0YZUNr48/z+gN0T4c8LOwJ5bD5fKFNoDNO7ge6g1 PcsAsjvgjPRaAsZLD3D6U4SG3cWckBZGjwWee5s4vziJMZc9MfndrpvGypzLtOejuogV tGWIujUmCgo1Otvbqkjmek9KfdV7kBdhFkzyPfg9yftn77wCSWRsil6Qan7odiQH37Dl 7DzwiRAhgSyJtAGJFMGTs/QHDk3P2jUpHjl1TKs4ePLIF6NVWxFKppNWw7e4tP9uEokj g9Kw== 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:mime-version:message-id :in-reply-to:date:subject:to:from:references:sender:dkim-signature; bh=EviBWsAUxhF1jVrTRD83lYio3ruYPmlIRe5s6oi2l6w=; b=Igzh+tspCAiC7EaWbCXfrwfMRaSMGfszPxlFFsdEMx7Y8Fe7Y5vk4zrTL3KkePIfvv H6rSebxTcHEm0UYqFQ2kmCOjsJYWyBCXjQuuoeGHsOJFV0jBHOcY0w/F1kWx1mdyxTC5 n/c4NEA4hgioiuz9UGovCVI9zYUvaY8Mp4564IceVZAnumRHJmlZR/0cfMEf7VfLJAWQ tGG82nJ58xRzyv72AGh5QiTWIPEfLAjumQ6Grs/u4beWA9A7kn+ywbWw8PbNfWssn7X3 TJpjjM7y6haW6Hvwn1BxpJNwdKL00deBpEnq9oA2O7ldIv3Uy8+ioSORfQD7xchI+fbr 7AaA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 2001:67c:2050:0:465::102 as permitted sender) smtp.mailfrom=albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20221208; t=1683731286; x=1686323286; 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:mime-version :message-id:in-reply-to:date:subject:to:from:references:sender:from :to:cc:subject:date:message-id:reply-to; bh=EviBWsAUxhF1jVrTRD83lYio3ruYPmlIRe5s6oi2l6w=; b=AgDv1OrQZsP0HzBSMg4JcdDMf6XFJkDo8LZLM0REH6RfhtcHm8caMhpvZO/lGdAqis 5gw9IIBoxOWKSw3rPODQO42ATkT2RACrRArn9AcpTqL7vtysne9QkrXT+oimDcIAviqL sjKYAfo7wP36yEChlxBF18u98oq3XtyYYoFYr5EJdDm9vtgr+Ih54mPqE2YKV/wI4REm 9lZMnBR8VEIaQuuOO/ByDxblbN/wkaztWTaZwysvod3qiFSNSGZV7BP6rdEnw6wJ92Wb AiHfEe3PFzZdn80DdbyTeD2UuYtaOd+jGjdEMR2SDqZ9EAFTasYXAuH8lYb4BgkhBCno X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683731286; x=1686323286; 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:mime-version :message-id:in-reply-to:date:subject:to:from:references:x-beenthere :x-gm-message-state:sender:from:to:cc:subject:date:message-id :reply-to; bh=EviBWsAUxhF1jVrTRD83lYio3ruYPmlIRe5s6oi2l6w=; b=AeUpRVWIZ1hJIG8Hcsma2Hdc3wOS0OM27I6LEaE5gzITPV8UifrUsBUhIj5uchMBff kPYsKdpOUHzNPNlVZ39NfZIoDy85Sd7qFnaSlXRuzvm3Hzp4SL3EFdo8yBP+SRQQLz3n FA4/ajbA/Jc63402C2/8yrjtoyxYmiEZjKicbBYmD47sgMCx3aM8wjmjYUjePMEfqsGR 0QIBhGKC85kGTmTRcThWv/93MvzrPd+vUBGYGyyKdTkTjl0ASrLQfPBLMCS2GGEWlR2a gGxagk Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AC+VfDyFwVp19F96K5D1Kt1QiFkzByXAupsqNQoA5UgsZI5NvcSxzTbs A3N/zDCfw2HwMWhXm+iqGuc= X-Google-Smtp-Source: ACHHUZ5NnDUxnB8zK+RBanksxK1/VVLFEtqhI/zc3+cK+hRhpORDOJadwg2xuXPX45SiYImoV0xHSA== X-Received: by 2002:a05:6512:218e:b0:4f2:5ea7:a534 with SMTP id b14-20020a056512218e00b004f25ea7a534mr985259lft.4.1683731286444; Wed, 10 May 2023 08:08:06 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a2e:9945:0:b0:2ad:a1e5:c894 with SMTP id r5-20020a2e9945000000b002ada1e5c894ls833061ljj.1.-pod-prod-06-eu; Wed, 10 May 2023 08:08:01 -0700 (PDT) X-Received: by 2002:ac2:5e83:0:b0:4e8:4412:1d95 with SMTP id b3-20020ac25e83000000b004e844121d95mr1604413lfq.29.1683731280975; Wed, 10 May 2023 08:08:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683731280; cv=none; d=google.com; s=arc-20160816; b=VcofsaavKAR/7ndfR4CYenBSCpMEU4DTUFflzirWlLWx2ivcRSOf6FQBCLZ8B7DGAq c6SLb7GqswqLkUGVD5caX+NyfVoNNTXdrXJBUdD9SwZp6o+Z2y9zAgbDMAbj1yMELDQl q5RSkeo9ch/BQSKDFG9EwhlWySUOUsbW/EWQBvDGonHjXjgwPZacdfUsQYd8WdXKyE/B 5kAae7QoU/CnDL6mjM75WwVXQO6j+Qjncbg0Zb4Ika3/zegJOIuDKl1jW3YiyxnK9HCc VXGK8je1V1hfydR3obkYrGx7SxZ+Bs7LlPkNLcKcYA9qNoU+TCcizZGIMYBRYvyq4Vsl DNdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:message-id:in-reply-to:date:subject:to:from:references; bh=P7QPO6w+bm7J2rLM/7gub8DHT5dIAUnBtUB7VsETCXw=; b=LBRHwG9oq9++dHDxEBmO4HTUCkVw1U3sU1QSIBv7Q2TeQJ+70f4zyp6YWxLgTdS+ac 2i0cTiOwEM6ANKhQSMptUyu34NVLkkGbafjCUGIFubLSGEMBEyWNtQ1sPFUKsBMKKVsR O363aEsEzJEQsHyMmhNknxzd21arUmOoMUyWJmdF7+cVimVSS2RaxZQPWzA9o2B+I804 OmaVPGQgGZCxFAqZb3kc7P476sD8Gqc8EyJHI0HKI51651cXhclo/oybFRxUcQkJv1Vk Q3jrbEaQY8+91rPA8G3PE/98sCoEUloaj0QRmd5Vcfl1sEG1WXFg2hsKA4o3H9TcyLiP ZLUA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 2001:67c:2050:0:465::102 as permitted sender) smtp.mailfrom=albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org Original-Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org. [2001:67c:2050:0:465::102]) by gmr-mx.google.com with ESMTPS id i3-20020a056512318300b004f1371664bfsi357482lfe.8.2023.05.10.08.08.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 08:08:00 -0700 (PDT) Received-SPF: pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 2001:67c:2050:0:465::102 as permitted sender) client-ip=2001:67c:2050:0:465::102; Original-Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4QGdgf2hx7z9slm for ; Wed, 10 May 2023 17:07:58 +0200 (CEST) In-reply-to: X-Rspamd-Queue-Id: 4QGdgf2hx7z9slm X-Original-Sender: albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 2001:67c:2050:0:465::102 as permitted sender) smtp.mailfrom=albert+pandoc-9EawChwDxG8hFhg+JK9F0w@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:32590 Archived-At: ThomasH writes: > is there a way to get to the parent in the Pandoc AST from the > current element in a Lua filter? > I would like to distinguish treatment of elements depending on their > context in the syntax tree, e.g. handle a 'span' element differently > if it is a child of a 'cell' element in a table. This is currently not supported in Lua; panflute (Python) filters do enable that though. What Lua does support though is to change the order in which elements are traversed, as well as the option to stop processing of a subtree. See https://pandoc.org/lua-filters.html#traversal-order E.g., to handle all Spans in a table differently you'd use traverse = 'topdown' function Table (tbl) return tbl:walk(my_filter_for_table_spans), false end function Span (span) -- default span processing return span end It's a bit of a brain-twister (and can be slower than normal filters) but it enables most of the actions that one would otherwise use the parent element for. -- Albert Krewinkel GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124