From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/29947 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Tom=C3=A1=C5=A1_Kruli=C5=A1?= Newsgroups: gmane.text.pandoc Subject: Re: How to manipulate with Block elements with Lua filters Date: Tue, 11 Jan 2022 06:07:32 -0800 (PST) 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/mixed; boundary="----=_Part_826_691275134.1641910052282" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22550"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBC32RZ7W74FRBJM662HAMGQEBM7ME7I-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Tue Jan 11 15:07:36 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oo1-f55.google.com ([209.85.161.55]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1n7HoF-0005gS-Il for gtp-pandoc-discuss@m.gmane-mx.org; Tue, 11 Jan 2022 15:07:35 +0100 Original-Received: by mail-oo1-f55.google.com with SMTP id r25-20020a4ae5d9000000b002c9ad00c5a5sf10791656oov.22 for ; Tue, 11 Jan 2022 06:07:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:date:from:to:message-id:in-reply-to:references:subject :mime-version:x-original-sender:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=nRDBC9bZ8JqoS+R2C8cCyJPWygnWoiOWoT2vpwyGoPo=; b=nkB+UlF7FB9DA6D1/0YlC35V4o5XbZFOFbIQ7ALPt6Wr02u+Afzd2vYq4zLCh31bUC w/YHbY1moq68JZSvET/BAlpjBmsGSZ96tv/i5wZ4azM5yfTKuu1flpwjVj1s+jwjWWkz vHrPuTGoT5Emrst6nVF22dDu5OGi+pNXJ0VFFoAuwFTIWzyHzT51s8PAP+zN3V91oac2 lUGDjVUR+0Adt+MFP219h7U/YpGW4i7KaN+KT8cq3fZo5ATSLZuKiGRb6OTngfkBvXvJ 3mkcSiP4zo2b1z0vF2NhaMnW4AoIH1TqrkPyEzfgRb1zdRD1mGobwndo0anxPe5skQlG 6BuA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=integromat-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:message-id:in-reply-to:references:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=nRDBC9bZ8JqoS+R2C8cCyJPWygnWoiOWoT2vpwyGoPo=; b=ejHHYhfzGoypNMbwso3m1okN5WxRYc97zBj7bV2jz1QeqwbM0UCgzPzv0/GLHXqI9J AZeI+PwTBKgXLw8P8rSS3BNRgYqcWp3vQYquJzX49GOuNnXpTuo6op9GsQNMm+Xo7Pun 7lzi4TxJMMQnStHJ5hl/mvuwURtOkxsgq2b4Eu/0ol9/8fp3KZatWXPRUpe1NYBg5KLr hDdSxtk34Yckw2gHUDeF0JCjnIRPBMicPTHP2lAjCqQCAu7vH6qr00zKudYxLa8BWEC9 C9dCtSnnTTXDHfDmbIMM1bX8E2Qcqy0C3NAuRF9rmyHw6fcxKxbX3gmjbRqIp/+yEyiD IQhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:date:from:to:message-id:in-reply-to :references:subject:mime-version:x-original-sender:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=nRDBC9bZ8JqoS+R2C8cCyJPWygnWoiOWoT2vpwyGoPo=; b=umooQzMkhNHz8Oain8xUvJtpNqjdOMATBeV/0IIoASZDyAyIlJ6gP3Ayx0N93MOmZX WFtEFS90VOl5BP/IcUcc+gzu38VIXh6e6xgTlwMWNI1BaOKupMUVPahKGTGmngTkxVmV RynOeRhSavL4QJQmVvoVnRctEJH8aVzkx8T6ntnxh13YKxpMTajt4JjmvlxRH65nel0M S0iu+vmxjnt2DfwpckYfO85RdsVrF2HSdqEnsvXwFkMDgvWQmzPIfnolBZz9ynyEOgg0 26O0a3UCfdkyLbWW5YIg+WAEiKhnI3Y/HQ+WUZy5wD0PCDI5Qdjl406U59Bp6zJPBrk5 RymA== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM533BMbPHxVEQbieNu8tuJSSO4ueEioTmGXYvHV4CPZJoBuhcPzU/ PXThqTghN/REpKumltho6wE= X-Google-Smtp-Source: ABdhPJw5t3Wim+x2JZEEpXfCbepVxv+XtXMhs+3nPWGIeA3EqwMvSUKn0WwQWUVkynUbMbK618uUaQ== X-Received: by 2002:a9d:2ab:: with SMTP id 40mr3491296otl.208.1641910054530; Tue, 11 Jan 2022 06:07:34 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6830:3116:: with SMTP id b22ls3638376ots.3.gmail; Tue, 11 Jan 2022 06:07:33 -0800 (PST) X-Received: by 2002:a9d:65cb:: with SMTP id z11mr3423861oth.241.1641910052880; Tue, 11 Jan 2022 06:07:32 -0800 (PST) In-Reply-To: X-Original-Sender: tomas.krulis-hR4I4Euo7CWBik42HM7KXg@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:29947 Archived-At: ------=_Part_826_691275134.1641910052282 Content-Type: multipart/alternative; boundary="----=_Part_827_1447023256.1641910052283" ------=_Part_827_1447023256.1641910052283 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Oh, so the `div` content is a `table` in lua terms? That didn't occured to= =20 me, even though it probably should ... I actually managed to replace it not= =20 as a `RawInline`, but `RawBlock`, like so: ```.{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.RawBlock('html', '' .. content.. '') else return elem end ``` But thank you for your solution, for me it was very educational! Another thing that I struggle with is to wrap my head around `walk_block`= =20 function. From the examples in the pandoc official page it is not much=20 clearer to me. I think I now understand that they are used to=20 iterate/filter over the contents of the block that is being walked over.=20 But if the block element contains only String elements (paragraph with=20 simple text), then also Str-filter functions are applied to it? Maybe my confusion can be voiced like this: When should I use=20 `pandoc.walk_block` function to get what I want and cannot use something=20 else? Explained not only with code, but also with commentary ... Dne pond=C4=9Bl=C3=AD 10. ledna 2022 v 19:46:37 UTC+1 u=C5=BEivatel BPJ nap= sal: > It is neither possible nor needed to convert the whole block to HTML=20 > 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=20 >> with Pandoc `block` elements. Currently, I am trying to replace `> class=3D'replace-me'>` tag with `` tag in similar (highly simplifi= ed)=20 >> HTML file: >> >> ```.{html} >> >> >>

First line.

>>
This should carry on to convert= ed=20 >> document.
>>

End.

>> >> >> ``` >> >> I have tried to detect the `
` tag, use `walk_block` to get the=20 >> `
` content and put it in `` tag, I also found a code using=20 >> `:walk` method. Lastly, I tried to convert `
` content to simple str= ing=20 >> 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=20 >> general with `pandoc_walk` or `:walk` (are they the same?) and how to de= al=20 >> with my specific situation? >> Thank you very much for any help, I ope that afterwards I will be able t= o=20 >> help myself a little bit more :) >> Regards Tomas >> >> --=20 >> You received this message because you are subscribed to the Google Group= s=20 >> "pandoc-discuss" group. >> To unsubscribe from this group and stop receiving emails from it, send a= n=20 >> email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit=20 >> https://groups.google.com/d/msgid/pandoc-discuss/590abdf0-6bc5-4f37-a978= -a46ad5cff5a8n%40googlegroups.com=20 >> >> . >> > --=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/aea85ef4-af50-46e5-8e21-d677801cb971n%40googlegroups.com. ------=_Part_827_1447023256.1641910052283 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Oh, so the `div` content is a `table` in lua terms? That didn't occured to = me, even though it probably should ... I actually managed to replace it not= as a `RawInline`, but `RawBlock`, like so:

 ```.{l= ua}
  if elem.t =3D=3D 'Div' and elem.classes[1] =3D=3D "replace-m= e" then
    content =3D pandoc.utils.stringify(elem.content)    return pandoc.RawBlock('html', '<note>' .. content.. = '</note>')
  else
    return elem
  end<= br>
```

But thank you for your sol= ution, for me it was very educational!
Another thing that I strug= gle with is to wrap my head around `walk_block` function. From the examples= in the pandoc official page it is not much clearer to me. I think I now un= derstand that they are used to iterate/filter over the contents of the bloc= k that is being walked over. But if the block element contains only String = elements (paragraph with simple text), then also Str-filter functions are a= pplied to it?
Maybe my confusion can be voiced like this: When sh= ould I use `pandoc.walk_block` function to get what I want and cannot use s= omething else? Explained not only with code, but also with commentary ...
Dne p= ond=C4=9Bl=C3=AD 10. ledna 2022=C2=A0v=C2=A019:46:37 UTC+1 u=C5=BEivatel BP= J napsal:
It is neither possible nor needed to conve= rt 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', '<note>')
local post =3D p= andoc.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
``````<= /div>

=
Den m=C3=A5n 10 jan. 2022 15:33Tom=C3= =A1=C5=A1 Kruli=C5=A1 <tomas.= ...@integromat.com> skrev:
Hello,

I would like to a= sk how you should, in general, detect and manipulate with Pandoc `block` el= ements. Currently, I am trying to replace `<div class=3D'replace-me&= #39;>` tag with `<note>` tag in similar (highly simplified) HTML f= ile:

```.{html}
<html>
&= lt;body>
<p> First line. </p>
<div cl= ass=3D"replace-me another-class"> This should carry on to conv= erted document. </div>
<p>End.</p>
&l= t;/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 `<div>` content to s= imple string and concatenate that in `RawInline` type:

=
```.{lua}
=C2=A0 if elem.t =3D=3D 'Div' and elem.cla= sses[1] =3D=3D "replace-me" then
=C2=A0 =C2=A0 content =3D pan= doc.utils.stringify(elem.content)
=C2=A0 =C2=A0 return pandoc.RawInline(= 'html', '<note>' .. content.. '</note>'= )
=C2=A0 else
=C2=A0 =C2=A0 return elem
=C2=A0 end
`= ``

But none of that is working. I would like to as= k you, how to work in general with `pandoc_walk` or `:walk` (are they the s= ame?) and how to deal with my specific situation?
Thank you very = much for any help, I ope that afterwards I will be able to help myself a li= ttle 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-discus= ...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-dis= cuss/590abdf0-6bc5-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://groups.google.com/d= /msgid/pandoc-discuss/aea85ef4-af50-46e5-8e21-d677801cb971n%40googlegroups.= com.
------=_Part_827_1447023256.1641910052283-- ------=_Part_826_691275134.1641910052282--