From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32879 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ioan Muntean Newsgroups: gmane.text.pandoc Subject: Re: How to manipulate with Block elements with Lua filters Date: Mon, 26 Jun 2023 12:12:02 -0700 (PDT) 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_1844_675115777.1687806722358" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5212"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBDFZBUNSQQLBBBGG46SAMGQE7XQOIVY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mon Jun 26 21:12:07 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oa1-f57.google.com ([209.85.160.57]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1qDrd9-0001Bo-KD for gtp-pandoc-discuss@m.gmane-mx.org; Mon, 26 Jun 2023 21:12:07 +0200 Original-Received: by mail-oa1-f57.google.com with SMTP id 586e51a60fabf-1ad0bdd63e2sf3492697fac.0 for ; Mon, 26 Jun 2023 12:12:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20221208; t=1687806726; x=1690398726; 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=TfUxWULzb41Mf5FJrgVG3CcBS35Ci0JPtKpJHBmgP9E=; b=OrHam3TFgHvpozaG9l4fAvcyNC6pjxiSMLxwOPf39nlHxecS6cczr1LrrG2EwPe7nV PAiSIK6BGdDdV4SfadlQ9ZopAA8ZNWRz2lGN05vELXlJKbNrV1iOY2hFL8OIWAW4geii /Iyjw44qnBberbwyNe+dS3AZyvsFsY+Q5Xn8XKLd4K1gVYJru0xiCCKllQOSWCBCK+Hb 9Y91SHBNgW9H+DHX/eeKREulp3PVWVb72x4eTrly4YZqhGql7xDRdYoe8QBf4C9WWVww 0etVb5iJy0c1Jj5xCGrutSC6WXATXpmyMZ6HcopdSb3vFUnwwSZ9E62zgCFLsNvkBHtd WbgA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687806726; x=1690398726; 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=TfUxWULzb41Mf5FJrgVG3CcBS35Ci0JPtKpJHBmgP9E=; b=RGFU+hzJjFPsrEx6QHUpys+neqAakySKbFP1miRCKXNQjwZVZjB2ZmMiqTwFTUkvKR 4YtDkI6o4UVuMXsBSusD0BCrWLcvBC6yUoke8z2NneCWEYlvmD3q89oPzCekexlDP+ii wbAB2Nl4zAa3WZQkJ2cOBe24JOWaaj0hys6E3TIic595Bi/KoWq+Wep5GAU3xWQ/+Bg+ /muACimHJl+dbS380ovL/+zmAYS5ZgEatTmXfuIq+lpxZnwSJS6+deS/jqMb1DJ8YOW0 /5MkGWtEDUtypfdnvB4O9HGjS2AJwu+D2N3NqxuAcrQ2DLxnKK9UGVGiS6rqi31QzBJW yHhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687806726; x=1690398726; 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=TfUxWULzb41Mf5FJrgVG3CcBS35Ci0JPtKpJHBmgP9E=; b=kiSXudXKWeQ8GTQIZgb77MFxZLmxHTHqK8NPHzMOdyfWQNOKXl6BkMdkIY+iPiDhYc bub9Lby8a4L0AWu2xR5snMC/iXYAn574Xq+KE2LmC8NhtlbUuzeSvE2r9jfP3Kr3RjXq NMBtynAjtEnPhK1RnL/GP0LFKikQ9N7tuGhs3W/obA+UXjSVUWiX1e8cZ7yrIzcFc8Ah NSu8TbuT/lGX1zXPAuLTWgAWiTp9BEOu1NORJyKXGLuMah1YbtYcFZUYuN1DsnAcR457 qpHU+XoYc9h0zTIJ4j0uHWABCLrQtb0QDP4HNsuLrnuFJDFVPu Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AC+VfDzjfP8N8xzfxSgwzzojFiMPEPW4i0a5BpIlM9HkIGgKnFRNDEVp 6amHfj/5JrSez9X7ddKlrY71LQ== X-Google-Smtp-Source: ACHHUZ5ZD/RPf3acFKcWVoibvJ0BcpJcPwYZvC6FahEwBxdFbV+sc0FEeHWQ4zgMCaJohUmQmPwRRA== X-Received: by 2002:a05:6870:a601:b0:1b0:37a:97cf with SMTP id e1-20020a056870a60100b001b0037a97cfmr8565300oam.43.1687806726399; Mon, 26 Jun 2023 12:12:06 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a4a:b810:0:b0:563:492f:3513 with SMTP id g16-20020a4ab810000000b00563492f3513ls189761oop.0.-pod-prod-00-us; Mon, 26 Jun 2023 12:12:03 -0700 (PDT) X-Received: by 2002:a05:6808:2195:b0:3a1:ee4f:77ce with SMTP id be21-20020a056808219500b003a1ee4f77cemr330754oib.1.1687806723277; Mon, 26 Jun 2023 12:12:03 -0700 (PDT) In-Reply-To: X-Original-Sender: imuntean-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:32879 Archived-At: ------=_Part_1844_675115777.1687806722358 Content-Type: multipart/alternative; boundary="----=_Part_1845_1299187853.1687806722358" ------=_Part_1845_1299187853.1687806722358 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Dear BPJ I read this post and thank you for illuminating some aspects of walking a= =20 DIV element in pandoc. My story is different but I tried to achieve=20 something simpler. I have a docx document and I want to convert it to Latex to include some=20 special styles. . I adapted your code and all works well except that I get= =20 extra lines between the environment definition and content. Here is my adapted code: function Div(divclaims) local preclaims =3D pandoc.RawInline('latex', '\\begin{claims}') local postclaims =3D pandoc.RawInline('latex', '\\end{claims}') local preissues =3D pandoc.RawInline('latex', '\\begin{issues}') local postissues =3D pandoc.RawInline('latex', '\\end{issues}') divbe=3Dtostring(divclaims.t) styletobe=3Dtostring(divclaims.attr) =20 if (string.find(styletobe, "Claims") or string.find(styletobe, "Issues"))= =20 then=20 if (string.find(styletobe, "Claims")) then pre=3Dpreclaims post=3Dpostclaim= s=20 print("Claim found") end if (string.find(styletobe, "Issues")) then pre=3Dpreissues post=3Dpostissue= s=20 print("Issue found") end local content =3D divclaims.content table.insert(content, 1, pre) table.insert(content, post) =20 return content end return nil end The Latex looks cool, except that the table.insert adds some empty lines : \begin{issues} text with formatting.... \end{issues} That baffles the Latex interpreter . My question is: how can I modify the= =20 code such that my latex output will have no extra empty lines? \begin{issues} text text \end{issues} Thank you in advance! Ioan M. On Monday, January 10, 2022 at 12:46:37=E2=80=AFPM UTC-6 BPJ wrote: > 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/ae032a8d-4d0a-4608-b479-61965cee2793n%40googlegroups.com. ------=_Part_1845_1299187853.1687806722358 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Dear BPJ
I read this post and thank you for illuminating some aspects o= f walking a DIV element in pandoc. My story is different but I tried to ach= ieve something simpler.
I have a docx document and I want to conv= ert it to Latex to include some special styles. . I adapted your code and= =C2=A0 all works well except that=C2=A0I get extra lines between the enviro= nment definition and content.
Here is my adapted code:
=
function Div(divclaims)

local preclaims =3D pan= doc.RawInline('latex', '\\begin{claims}')
local postclaims =3D pandoc.= RawInline('latex', '\\end{claims}')
local preissues =3D pandoc.RawInli= ne('latex', '\\begin{issues}')
local postissues =3D pandoc.RawInline('= latex', '\\end{issues}')

=C2=A0 divbe=3Dtostring(divclaims.t)
styletobe=3Dtostring(divclaims.attr)
=C2=A0
=C2=A0 if= (string.find(styletobe, "Claims") or string.find(styletobe, "Issues")) =C2= =A0then
if (string.find(st= yletobe, "Claims")) then pre=3Dpreclaims post=3Dpostclaims print("Claim fou= nd") end
if (string.find(st= yletobe, "Issues")) then pre=3Dpreissues post=3Dpostissues print("Issue fou= nd") end

local conten= t =3D divclaims.content
table.insert(content, 1, pre= )
table.insert(content, po= st)


=C2=A0 =C2= =A0
return content
=C2= =A0 end
=C2=A0 return nil
end


The Latex looks cool, except that the table= .insert adds some empty lines :

\begin{issues}
text with formatting....

\end{issues}

That baffles the Latex interpreter . My question is: how can I modify= the code such that my latex output will have no extra empty lines?

\begin{issues} text text=C2=A0\end{issues}

<= /div>
Thank you in advance!
Ioan M.



On Monday, January 10, 2022 at 12:46:37=E2=80=AFPM UTC-6 BPJ wro= te:
It is neither possible nor needed to convert th= e 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 resou= rces saving!
local pre =3D pandoc.RawBlock('html= ', '<note>')
local post =3D pandoc= .RawBlock('html', '</note>')
<= br>
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 ret= urn 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....@in= tegromat.com> skrev:
Hello,

I would like to ask how= you should, in general, detect and manipulate with Pandoc `block` elements= . Currently, I am trying to replace `<div class=3D'replace-me'&g= t;` tag with `<note>` tag in similar (highly simplified) HTML file:

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

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

`= ``.{lua}
=C2=A0 if elem.t =3D=3D 'Div' and elem.classes[1= ] =3D=3D "replace-me" then
=C2=A0 =C2=A0 content =3D pandoc.ut= ils.stringify(elem.content)
=C2=A0 =C2=A0 return pandoc.RawInline('h= tml', '<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 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 able 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-discus= ...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/5= 90abdf0-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/ae032a8d-4d0a-4608-b479-61965cee2793n%40googlegroups.= com.
------=_Part_1845_1299187853.1687806722358-- ------=_Part_1844_675115777.1687806722358--