From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/29938 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: BPJ Newsgroups: gmane.text.pandoc Subject: Re: How to manipulate with Block elements with Lua filters Date: Mon, 10 Jan 2022 19:46:20 +0100 Message-ID: References: <590abdf0-6bc5-4f37-a978-a46ad5cff5a8n@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000060966b05d53ec124" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32967"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCWMVYEK54FRBCX66GHAMGQEXA5CAZI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mon Jan 10 19:46:37 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-ed1-f64.google.com ([209.85.208.64]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1n6zgi-0008MM-RQ for gtp-pandoc-discuss@m.gmane-mx.org; Mon, 10 Jan 2022 19:46:36 +0100 Original-Received: by mail-ed1-f64.google.com with SMTP id s7-20020a056402520700b003f841380832sf10978852edd.5 for ; Mon, 10 Jan 2022 10:46:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1641840396; cv=pass; d=google.com; s=arc-20160816; b=O8OpsASKKbRO1jDV0ZJ9/BKMe4paNYiIMGrmOiOGTVcxKlKqB7rJNb7Dh8p/p+TiS4 AIvCnsJ45r/CiZqLrbap8LSzx8ryvGBmYvrqJqIvyiaw8NS8oJK2MoaEgqSu/7Iwasjy pkbminnlImIb+lfD9yHiKmzlC3MxrFk4I+hWupOpwpSI5cb+hWR1S584khHGfL80SoPa mnoFkKacZB2NoGYteNsNiaEaghQ2nN6lJQyvesJqld1fi5UkvQUH603UnxKb+E9MD1j+ 3+11Ou0F0lBe2Swrr+I7Ds5wBsMPLr6l6aZDXqjsnEXNy52dCOx1dPdEAnfOWi52GMdW jLyA== 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:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:sender:dkim-signature; bh=Tmkjk0RiAVNE/KO5D94YoN7s8IBdQrRHt24QIjkTqnE=; b=XtJH3/gId2tvOuhWKXHjbcmVHJ37oddYesJz7W5/jZrPyAcwLQOHfm0TFU1HNPdq8h 7MZYkw7+iJUWvc8z9dFGKKlrzDHXrrpedHTPve6M2eawOf0X5La8qMrhSfhcaMD+v2ED Z+7AfRfHgvAKslHJ0MA3hmQVzibXieTEd+wKyF7f0E4qkXt5avkh60aY7+cm8yXrhe2T 1YwJoeFtSDaIqeojT8qTcLxX1zW6zlA+dJ7QbEK0qM5t+Cc96bJyoBzrdrLpKjd851SK UTK2xShtPinKldHnSuyW3R/RLIdDo+Rx6LFrQjFl5re5n+NNwLIe1XLWECnMjc0ETsIQ QJtw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.167.45 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:mime-version:references:in-reply-to:reply-to:from:date :message-id:subject:to:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=Tmkjk0RiAVNE/KO5D94YoN7s8IBdQrRHt24QIjkTqnE=; b=YsgG08gvqwZoLW4PmWusahOA7XACxiIEPbs+9RDyZ60tbo4/JNWjR8d7k7oIi+C4+J OyXArQb/Eb+P9SQUYjZlsogbFczgL4vN9aEM7lmWlUD2jwzQ1pMpTLLT6phXl8cXHcuy PkrrORTr/CJT3vDufFMU9Zn8ezUfakjT/coBZA6WQjVB7ptUnWLkLksg+zNpDxiifM3z XLrlH0LvnJ8AaYPkyxH7I6Z08Ky+siHwv11ieEZ0n9RJo1+LtrAsxktGzISwpkmrfZ2E 94bWTwqIfD+65qlEjpAkYiou3h9Aco14SNuWQS7zQtYUNllc8opsqZnDfOoEv4itpv6Z VrlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:mime-version:references:in-reply-to :reply-to:from:date:message-id:subject:to:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=Tmkjk0RiAVNE/KO5D94YoN7s8IBdQrRHt24QIjkTqnE=; b=Dd1wIWkRL9W/iEnpk/vXfqawakG2AFsfYdHsV4FGtOMT1akwGSBgjTeP6ijYLotMVQ ABFwOK8M1fnmc5B5y7IM0WCzZAeQKchnpXslNrD377/iKsSvRWFcnNPIXU3dBbIhF6yG ejdP1S+4pnFFLahoBDGa3n4cmtSeLy+tMxvXUY83p4TnA6zrmdeZe1Gr7brwIJLhq3V4 o8E/tFZ0w9tlFGKTXmQwlY/gk4ONRmTqHNpCl2EBAYjCDiew/+NNhlG97DUiHUQqh4CI iSbLXL9ypSXP0nL2W3r2vzu0Ju0sA6TDcqtFux6J5DTXEXh4FzKFsRa7dEgdNQX5xLMY LCqA== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM530CSv7+0h24ThahJRkWnjZv+7Meo2aMZYxOAu+SpRi3JnKgfENG QLisLwnxG5DFco9R7/cUZ8U= X-Google-Smtp-Source: ABdhPJxFE3z9UrY/+opo+/2eJwFKdubfeCxUBQD/XQVP1LoXsI6GlKLwn5SmZyD9pPb6gPTkuyPwKA== X-Received: by 2002:a17:906:87c9:: with SMTP id zb9mr828765ejb.49.1641840395944; Mon, 10 Jan 2022 10:46:35 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6402:5190:: with SMTP id q16ls2367892edd.3.gmail; Mon, 10 Jan 2022 10:46:33 -0800 (PST) X-Received: by 2002:a50:ec90:: with SMTP id e16mr944320edr.355.1641840393264; Mon, 10 Jan 2022 10:46:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641840393; cv=none; d=google.com; s=arc-20160816; b=nGz5uvIDG31LQTv+By7vBW8JP3EBTWNsRNoxmTbUeq4QxeJa4umAO6u6gWfIWdoOxK rcrF2hS91V3q4+IszAEewZIZZXjpbLE0eDOfmAj+ADa/ju4VmLTEQ8K0qk+5zSjoz9q3 Rb0et9XCqgXN8kJc7svP5/uKJ3aUHk1BU62LxweFaM+7P/A6+6PqQ4EOQZqfxWDUjR07 NHBUF7pSxChE5Nlh0Ta7ALwxYo3F84J/D5ufmk6YuXcj4+XCvWpSPgQtTNNprOX8XvAz Sx908oXSpXIKdaEmBQUtYtFuwuZRWKW+DmSaWwpsCajhs6/dcxsqttgmqyJx1/10gGu1 o0gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version; bh=QlW6/P3slLvQJ8hoBNBsI44rSj0omtoS5My/Z9tK2lg=; b=YqeILQSm414qRzABKnh6slhiDQDL6vaFSWo4gFt5QWfYNfUjR/sYdnW9LoU8emDXM+ /cgVlacWWL1/Ph/ZtaNsKgdKFtK+5qR0lwWEh6X10fmxm9FqjGi3C5xzbCZBiiyw5Sux 3CiGyxeYisA3x0pXTbnyMnQttBm/EyNS6iMdnnTMC5ZWVep1y4bl/yz6Pw9g+C6d6Sim JhMzJmStxCTVIioQmauYl3Oi31xAC3eK2+TR4IypW0lJ3KIzSeiYQJP0fREDzyaGK+Ir 19iI3PXI2lBGXSlpLKbPsEd2PACUtQF4tDMJIrcDchSLtve60x1EZNdFvr50Wc713hvd yNdQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.167.45 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Original-Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com. [209.85.167.45]) by gmr-mx.google.com with ESMTPS id wn17si231754ejb.1.2022.01.10.10.46.33 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 Jan 2022 10:46:33 -0800 (PST) Received-SPF: pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.167.45 as permitted sender) client-ip=209.85.167.45; Original-Received: by mail-lf1-f45.google.com with SMTP id j11so47687210lfg.3 for ; Mon, 10 Jan 2022 10:46:33 -0800 (PST) X-Received: by 2002:ac2:4a78:: with SMTP id q24mr734543lfp.464.1641840392573; Mon, 10 Jan 2022 10:46:32 -0800 (PST) In-Reply-To: <590abdf0-6bc5-4f37-a978-a46ad5cff5a8n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> X-Original-Sender: melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.167.45 as permitted sender) smtp.mailfrom=melroch-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:29938 Archived-At: --00000000000060966b05d53ec124 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable It is neither possible nor needed to convert the whole block to HTML within the filter; rather you should just inject the start and end tags: ``````lua -- Create these only once, for speed and resources saving! local pre =3D pandoc.RawBlock('html', '') local post =3D pandoc.RawBlock('html', '') function Div (div) -- The order of the classes shouldn't matter! if div.classes:includes('replace-me') then local content =3D div.content table.insert(content, 1, pre) table.insert(content, post) return content end return nil end `````` Den m=C3=A5n 10 jan. 2022 15:33Tom=C3=A1=C5=A1 Kruli=C5=A1 skrev: > Hello, > > I would like to ask how you should, in general, detect and manipulate wit= h > Pandoc `block` elements. Currently, I am trying to replace `
class=3D'replace-me'>` tag with `` tag in similar (highly simplifie= d) > HTML file: > > ```.{html} > > >

First line.

>
This should carry on to converte= d > document.
>

End.

> > > ``` > > I have tried to detect the `
` tag, use `walk_block` to get the > `
` content and put it in `` tag, I also found a code using > `:walk` method. Lastly, I tried to convert `
` content to simple stri= ng > and concatenate that in `RawInline` type: > > ```.{lua} > if elem.t =3D=3D 'Div' and elem.classes[1] =3D=3D "replace-me" then > content =3D pandoc.utils.stringify(elem.content) > return pandoc.RawInline('html', '' .. content.. '') > else > return elem > end > ``` > > But none of that is working. I would like to ask you, how to work in > general with `pandoc_walk` or `:walk` (are they the same?) and how to dea= l > with my specific situation? > Thank you very much for any help, I ope that afterwards I will be able to > help myself a little bit more :) > Regards Tomas > > -- > 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/590abdf0-6bc5-4f37-a978-= a46ad5cff5a8n%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/CADAJKhAzeK-kPd7yHWbtGX%3D363VvcgFUj8gt_vEMUXfGkBd%2Bug%40ma= il.gmail.com. --00000000000060966b05d53ec124 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
It is neither possible nor needed to co= nvert the whole block to HTML within the filter; rather you should just inj= ect the start and end tags:

``````lua
-- Create these only once, for speed a= nd resources saving!
local pre =3D pandoc.RawBlock(&= #39;html', '<note>')
local post = =3D pandoc.RawBlock('html', '</note>')

function Div (div)
=C2=A0 -- The order of the classes shouldn't matter!
=C2=A0 if div.classes:includes('replace-me') then
=C2=A0 =C2=A0 local content =3D div.content
=C2=A0 =C2=A0 table.insert(content, 1, pre)
=C2=A0 =C2=A0 table.insert(content, post)
=C2=A0 = =C2=A0 return content
=C2=A0 end
=C2=A0 return nil
end
```= ```

Den m=C3=A5n 10 jan. 2022 15:33Tom=C3=A1=C5=A1 Kruli=C5=A1 <tomas.krulis-hR4I4Euo7CWBik42HM7KXg@public.gmane.org= > skrev:
Hello,

I would like to ask how you should, in general, detect and manipulate wi= th Pandoc `block` elements. Currently, I am trying to replace `<div clas= s=3D'replace-me'>` tag with `<note>` tag in similar (highl= y simplified) HTML file:

```.{html}
<= html>
<body>
<p> First line. </p><= /div>
<div class=3D"replace-me another-class"> This sho= uld carry on to converted document. </div>
<p>End.<= ;/p>
</body>
</html>
```
=

I have tried to detect the `<div>` tag, use `walk= _block` to get the `<div>` content and put it in `<note>` tag, = I also found a code using `:walk` method. Lastly, I tried to convert `<d= iv>` content to simple string and concatenate that in `RawInline` type:<= /div>

```.{lua}
=C2=A0 if elem.t =3D=3D 'D= iv' and elem.classes[1] =3D=3D "replace-me" then
=C2=A0 = =C2=A0 content =3D pandoc.utils.stringify(elem.content)
=C2=A0 =C2=A0 re= turn pandoc.RawInline('html', '<note>' .. content.. &= #39;</note>')
=C2=A0 else
=C2=A0 =C2=A0 return elem
=C2= =A0 end
```

But none of that is work= ing. I would like to ask you, how to work in general with `pandoc_walk` or = `:walk` (are they the same?) and how to deal with my specific situation?
Thank you very much for any help, I ope that afterwards I will be a= ble to help myself a little bit more :)
Regards Tomas

--
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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.org= m.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/590abdf0-6= bc5-4f37-a978-a46ad5cff5a8n%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://gro= ups.google.com/d/msgid/pandoc-discuss/CADAJKhAzeK-kPd7yHWbtGX%3D363VvcgFUj8= gt_vEMUXfGkBd%2Bug%40mail.gmail.com.
--00000000000060966b05d53ec124--