From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/26759 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Albert Krewinkel Newsgroups: gmane.text.pandoc Subject: Re: How to access Span elements with lua filter based on their content Date: Fri, 06 Nov 2020 20:31:51 +0100 Message-ID: <87tuu2s2mw.fsf@zeitkraut.de> References: <871rh7trtg.fsf@zeitkraut.de> <84ffd932-2be5-4900-b115-58220e691dcbn@googlegroups.com> 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="29938"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBCZJF7XJTILRBL6JS36QKGQEMSRZFHA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Nov 06 20:32:04 2020 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-lf1-f55.google.com ([209.85.167.55]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kb7St-0007fE-Ne for gtp-pandoc-discuss@m.gmane-mx.org; Fri, 06 Nov 2020 20:32:03 +0100 Original-Received: by mail-lf1-f55.google.com with SMTP id w79sf803429lff.8 for ; Fri, 06 Nov 2020 11:32:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1604691123; cv=pass; d=google.com; s=arc-20160816; b=xz3GSs1X5jzdzwS81PREkpDkaIZZVC0nwVtSpBL9zSJEtq25tOtMlCtDf2sjyPFqWZ MeAqfZ2cXUzrhrAUHjp7Zq3pWZ8LtyVeWufsoFluxkOWYcDfhzSvxzUgwNFuBNHE7M6v kdWEOFg/cbpT0vG4YVbTIwb6IWius6aFo4UY1DwBw5Ipv5KkRHazKvPg2tUlebrKgrHP ibIkE9LKE2uWAny+fvBHOGlEW5qC4XuuHlZOTBCtlRN+8cozfbXVL94aEVczU+eDlXAX EidjyvhESpSTXr9mqEYCHjGq7eilozWJ/iQ9Ryq/08KbIaLeiNMQtbp+L8gL2kycDdEj Devw== 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 :date:in-reply-to:subject:to:from:references:sender:dkim-signature; bh=vn5DlccZeYjElX511ivZZem8NS17urSlvkg6TSk2p64=; b=m7hZ1/P3BXXKLEQaksUG2N/l145icHOkbc/oYlsp/n38+UGobnBWsixJd9D97vyNYj SkjGDy/7AR45dQjzeRiAKWfHzI+H6avdTQtz+wMD2b5PNXwcoljQL2d9OnEr4CWQieaY hiv9y735ZDP/FTgnlqBnkIec00L7k4mF7ihQi4z98ScPEy2FqID578WBbid9KKkgCE63 hFlZ7iG/l2yK7jLp/1S/BZU4I2qTu1hD58hDxEjk/CTzo4x3vXw3YrX8x67bOIVkfDoA gMcmCB7fnck45hqrab1B02lTWOX4BUPP5GjmXxzjaosGMuKcHZIbagexueLY/UFF+Zko jx7A== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.171 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=20161025; h=sender:references:from:to:subject:in-reply-to:date:message-id :mime-version:x-original-sender:x-original-authentication-results :reply-to:precedence:mailing-list:list-id:list-post:list-help :list-archive:list-subscribe:list-unsubscribe; bh=vn5DlccZeYjElX511ivZZem8NS17urSlvkg6TSk2p64=; b=YKdbc3QISy1qfOo6KjfuMo1a1L3VexZoL7cpzSZ4PyXC6woj7fSvkrXkXn4MTC5R1m vMMB7E0GamT35y6gSyf4GV6NwgouRwdx8BtVtI+MVpuJVvPxfYOR/ebHdlgUlSp0lWrJ TCAtHzZo+4NK+KrqXvf3FMtw9c0tiD/qKJnTCWEwzBTw2RKS8E521gXsVEJMiaVeL4f9 ZujlA+oe7TA2pVDYSTHvzDcvFz0tymanloHDGD7+44Fo5UYsjj4tfzV1MS0V7k1zTn2j UinmTqqwyfi4q0nE0wpb9B0h0enhkdt4Ke0A26ze6tbfesBUNCWkzqdHTvTL7wVO7gS8 mjLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:references:from:to:subject:in-reply-to :date:message-id:mime-version:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=vn5DlccZeYjElX511ivZZem8NS17urSlvkg6TSk2p64=; b=kgZIwxDhX2a2D6ogshf4jF/a8QXQL9dpAIAA2xU9F3+Z1FrXCGJCrwCJ3Q82p9rfxx kzvrQnw9LhDuaCrKq9qA0j8FJis0Y2CUFe0u6XSYnu1XBMQPkFj/6EqspX2oN3cYE0rz I4avw39M6aeDzgouG5LwiI/UxFNf04hsCAv4ameuxKceoI3NwkCc+Os+mvZ1tNAliKc3 5I+w8rI3JxyTCiO4t+fHnPWcQn1/Q7uBZ++8LdDUoOy94MAoq48NyxMmqOt1u85mLWks a3UF4qTTS9FE22A99PUiGt51Cai59z7lW5Rco4TJuYO3lpuz3zfRtSvsQD74GT7bOGpB ZASg== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM532Mcn25IQZK1GomfU0C9APo2c4yOuZGItXMVzQfzkkhBTxfsAK+ 3io1cSWi8w34BsCtrfPKKmQ= X-Google-Smtp-Source: ABdhPJzZlXbGAJSI52UoaVyvrnEpc2SrpPUhgz7d1wPSQ3y4JDbtPAkqVwmQA0/vd7IcOo+/9FwJ+g== X-Received: by 2002:a05:6512:3694:: with SMTP id d20mr1598769lfs.135.1604691123228; Fri, 06 Nov 2020 11:32:03 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a19:586:: with SMTP id 128ls352433lff.1.gmail; Fri, 06 Nov 2020 11:31:58 -0800 (PST) X-Received: by 2002:a19:c05:: with SMTP id 5mr1564652lfm.93.1604691118240; Fri, 06 Nov 2020 11:31:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604691118; cv=none; d=google.com; s=arc-20160816; b=ni5qKfoz0kVmxgGJirXYCpyHy5GZuVDGu4DWRt6SYwmSFc7bRGG2EVWYg5cDkGASXU NGE7PNevXJvS4Oa0jezxBXOaJZxWbYMWaA8IPbVVwNX9NRAfUM2BOLRai0ZC4/+FG/TO zYWIYCITvvkLJWuMdo0DDmrl8NNtabyWz9SudGriTiXRqicK2E/zFq29nJ/5Ew3svWOT IXHDAImzC+DowKGAyq/LmgRx10wCQSa8456QvxN9/QAxiIXy5t3B6ls9W3wNcxtnSLl8 pogMSBbNOjLMWrfcpW6NGPftmhA1WOV86d4GfvvmshEWJjBMvwC4qjRby4D/BUFLIzhK I/Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:message-id:date:in-reply-to:subject:to:from:references; bh=T84UnInLYO8ti5JWVtM4NViMrgq1FqzJzuJhZiHz92c=; b=kjQF1+wu1IQ90cSzA1gW5CqjHABNqxuFJxCyRX2UZfSM0mrZ4t9VuD6Z7U0gYTbXHb uFdfPOLnZO+YsWWHXC4bNPyo54zCIOSVzhXz7nFwYScaCtKuzRtKa9TDdMjC5vdmnel8 80npEm90H89I2C3NXnyyK8QJ3HZy+6gcj5pzkFvQ5o5Ej2WX8PkWRFNWAcJsMMsIiqkv UvJij+w+GbFsRyAraWqKyhLUNCTyZWZg/SsBAhAXvv20PPNiX2G8C3Lj9URKjGwKXSSP YmygpQneXXCjCvww0CZHOaApK8O+6c82cVAs6bRkGn7WT+9tLHEIRcnU2o7Odrw0pDa0 keGA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.171 as permitted sender) smtp.mailfrom=albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org Original-Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org. [80.241.56.171]) by gmr-mx.google.com with ESMTPS id h4si58177ljl.1.2020.11.06.11.31.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2020 11:31:58 -0800 (PST) Received-SPF: pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.171 as permitted sender) client-ip=80.241.56.171; Original-Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (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-201.mailbox.org (Postfix) with ESMTPS id 4CSVrY33VmzQl1t for ; Fri, 6 Nov 2020 20:31:57 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Original-Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id gX5mjPt5mdl5 for ; Fri, 6 Nov 2020 20:31:52 +0100 (CET) In-reply-to: <84ffd932-2be5-4900-b115-58220e691dcbn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> X-Rspamd-Score: -6.66 / 15.00 / 15.00 X-Rspamd-Queue-Id: 13E211722 X-Rspamd-UID: 0b5e16 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 80.241.56.171 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:26759 Archived-At: Hey Tomas, krulis....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org writes: > thank you for your help. The filter works great! The export option has made > no difference for me, but I might be using it wrong (as it is always with > me, I am learning working with Emacs, so I am probably doing something the > way I shouldnt :D). Feel free to send me an example file and I can take a quick look. > The second part is difficult for me. Could you elaborate a little more > about how did you identified that those `'todo'` or `'TODO'` in the > TODO-Span as classes, and not attributes? That's a good question. A Span consists of two parts, the Attr and the inline contents. Attr values are triples consisting of the element's id, classes, and key-value attributes, in that order. https://pandoc.org/lua-filters.html#type-attr If we look at >> > [Header 1 ("feed-the-cat",[],[]) [Span ("",["todo","TODO"],[]) [Str >> > "TODO"],Space,Str "Feed",Space,Str "the",Space,Str "cat"]] we see that `["todo", "TODO"]` is the second element in the tuples, so these are classes. We can now check the Lua filter docs for the Span type to see how we can access the info: https://pandoc.org/lua-filters.html#type-span We find that Span elements have a `classes` field; the rest should be discoverable by clicking and scrolling through the docs. The most difficult part is to know that the triples in the native output are Attr values. I'm actually not sure if this is documented anywhere but the Haskell source. Any confusion about this is very understandable. > And the element [String "TODO"] is a one-element list in pandoc-AST, > therefore it cannot be chacked as-is? Did I got the last part correctly? Yes. Haskell lists are translated into plain Lua tables; the latter follow the usual Lua comparison rules. Pandoc AST elements are special, in that they have `__eq` metamethods which use Haskell's comparision mechanism under the hood. Hence the difference in behavior. -- Albert Krewinkel GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124