From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32591 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: ThomasH Newsgroups: gmane.text.pandoc Subject: Re: Lua Filter: Get to parent of current element? Date: Wed, 10 May 2023 09:59:11 -0700 (PDT) Message-ID: References: <87sfc4ql6b.fsf@zeitkraut.de> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_1234_1647105375.1683737951731" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40618"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCOJJAXZ7EPBBYM256RAMGQEDHQ4DNA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed May 10 18:59:17 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oo1-f60.google.com ([209.85.161.60]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pwn9o-000AJb-HT for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 10 May 2023 18:59:16 +0200 Original-Received: by mail-oo1-f60.google.com with SMTP id 006d021491bc7-54fb26bc1dbsf2038490eaf.3 for ; Wed, 10 May 2023 09:59:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20221208; t=1683737955; x=1686329955; 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=9O2U7+AL5u0od33TR01vOWLs3mL3kmfKAw/9Q1Dycck=; b=ZpR6P17x+owxhvCdPYlbfvuDvqMC+m1aOn79q/3vR0BcdoUAyfsedd6NvirlN+cqzV z1GganuLEdv+q8UF7TkUmG9mi8QvlWnwXYfSTeLbst2k6HyqqP8A1CUOUUD9ezqDp62y oZd23t7W6qDhd9ptxlYzNT/X8vcLws5s11kSSnPbw7xOE6m9ETQZ4bEe/F2kN957UhIf 10OwIpM8RgoCeZr3ZX52oDyKapqtv9f4Z2hG4QMBn126HlMMsl/WEe1emlbDt+sLx3ME kAPBIle1U9e+4lFa9/Vw6/vfdrzx2cy0PR9x0Z8KzEWqtHCAZlOgXV9hGphE2EC+357z jRLA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683737955; x=1686329955; 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=9O2U7+AL5u0od33TR01vOWLs3mL3kmfKAw/9Q1Dycck=; b=r2dSYbCv7zCWwCtJDeGAzCJgKrOZmJ4Igj8fenskJ2DnSfrHfT2r5rRMC8TSnGsWLd UQiv3Cf8cKi0LBNQjVu/aZSkniwjvQsVlfBiWoyoC2yQdi/5Krc51S3INyraCzPQVtIr Yg9m9nhEEvvNNBuKIwiGXqN3rxC6Vqdh6J3opYE3ucb3spzI5HWQUkKmq6qsDqMKABRK adM3vPbMIixVLkjsFy81IRSl/2uS0lsliHrZ+4tr/d+lbtM5nFw6vhmVk7xDpXw7uLZ8 5nCyRAnEE4LKqrnToZtD5p42TD6XTkOLv8wx8lpcyerRszIemcv4OWAGOb9UlUO3TfD0 29jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683737955; x=1686329955; 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=9O2U7+AL5u0od33TR01vOWLs3mL3kmfKAw/9Q1Dycck=; b=RElX43zQ/i104GBbY6bM+NT++4ZH+90NzSp0bRTHHS5ntaPBOznqgU+y1KJA8Lik5k 3aEvI9uOeTGX7jCpIf+EuGsdb0pW2R1Fu+Qc1SR6+wU3cFKiTyX19DkCcG7wkWD88SjN BnpbHgjtrC6CF5Xt2qTMY6WEUXWVk9dZSTG2Mj6qkUcMO79OtG//JuSxucaTZ6pFJG5O 3WjS62SMc0rQMKg6wGP85tL4pq+99f6gmv4fsRn2rmTrLckRjEradG8fxUh5rKbHbTai PC1K+QLu+w5NDK6T2bFnpt2jUE0c9jIh59d6FpgiD0w9acgV+n Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AC+VfDwEptgj64YkiFZpLRB/1UORWaN57zk6Lr5BR32y9CSeNXTEdqWo 1ANYaj3r8fNJsZ7Z3c/T/Fc= X-Google-Smtp-Source: ACHHUZ6u0527OHqOWUtjv94BpvxTCHPLXn7jFlbds2fnzhyQC10aco5/9B48an+vSgawvoGcHLkD2A== X-Received: by 2002:a05:6870:104f:b0:195:f8aa:2b1b with SMTP id 15-20020a056870104f00b00195f8aa2b1bmr5402630oaj.4.1683737955516; Wed, 10 May 2023 09:59:15 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6870:3c87:b0:192:d467:746e with SMTP id gl7-20020a0568703c8700b00192d467746els5017539oab.8.-pod-prod-gmail; Wed, 10 May 2023 09:59:12 -0700 (PDT) X-Received: by 2002:a05:6871:22c3:b0:196:10ee:54da with SMTP id se3-20020a05687122c300b0019610ee54damr2995727oab.11.1683737952299; Wed, 10 May 2023 09:59:12 -0700 (PDT) In-Reply-To: <87sfc4ql6b.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> X-Original-Sender: therch-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:32591 Archived-At: ------=_Part_1234_1647105375.1683737951731 Content-Type: multipart/alternative; boundary="----=_Part_1235_206006240.1683737951731" ------=_Part_1235_206006240.1683737951731 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Great, thanks both of you, I get the idea, will try that. T. On Wednesday, May 10, 2023 at 5:08:06=E2=80=AFPM UTC+2 Albert Krewinkel wro= te: > > 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 =3D '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. > > > --=20 > Albert Krewinkel > GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124 > --=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/eb2115c3-ee11-4f82-bb49-6fd423d9365fn%40googlegroups.com. ------=_Part_1235_206006240.1683737951731 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Great, thanks both of you, I get the idea, will try that.
T.

On Wednesday, May 10, 2023 at 5:08:06=E2=80=AFPM = UTC+2 Albert Krewinkel wrote:

ThomasH <the...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org= > 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 the= ir
> context in the syntax tree, e.g. handle a 'span' element d= ifferently
> 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 =3D '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 filter= s)
but it enables most of the actions that one would otherwise use the
parent element for.


--=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 pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d= /msgid/pandoc-discuss/eb2115c3-ee11-4f82-bb49-6fd423d9365fn%40googlegroups.= com.
------=_Part_1235_206006240.1683737951731-- ------=_Part_1234_1647105375.1683737951731--