From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/28178 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "'Angel Joaniquet' via pandoc-discuss" Newsgroups: gmane.text.pandoc Subject: Re: Modify writer or extensions inside a filter Date: Fri, 16 Apr 2021 05:00:30 -0700 (PDT) Message-ID: <03f7ab59-6b1a-451e-8528-4b164d439dc4n@googlegroups.com> References: <509d7700-5cb3-4382-9276-c4b2e2a0c3e5n@googlegroups.com> <50d9ae1b-95a0-445f-9ab2-5b1fe2cc992fn@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1_1964858770.1618574430714" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22605"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCUYX56H3IEBBX7Y4WBQMGQE6PGWB6A-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Apr 16 14:00:34 2021 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oi1-f191.google.com ([209.85.167.191]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lXN9F-0005k3-V3 for gtp-pandoc-discuss@m.gmane-mx.org; Fri, 16 Apr 2021 14:00:34 +0200 Original-Received: by mail-oi1-f191.google.com with SMTP id j190-20020acaebc70000b0290159ccfd006esf9227653oih.5 for ; Fri, 16 Apr 2021 05:00:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; 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=orWgau00QeG5uRuvw4ycZxddrBe0TZOXpOS+KYLMIRg=; b=hM915GF5qRZcw+vDxN0aNAM/TKjGG6ytjYvBTY6BFIJcdQiOac1fvTbJLphTXU8v9a KETxqrXh6hkXX0AR70XhjE34B9XjOrD9gR6J3qdtPH/Pmrg1nkrmv8LLWmzpLjrNv6Wa EiiJNYNx/pouTYnXKs0eJ0b9/dNroy/b6LhOn0tDAmw7sKGBntYiP5GpW6/J/zHcJ7uV FVNcKnMpqmE5T7/bZNKbwh5dtPDUsVEOAodMTTmHMzsJwEgqN+t7ZxE6aUZFY0l3R3E6 Lm6w9DQkVuxLF42DxnPfMlMUoOxsZfB/jVhOKWrlAdbzikGHiShLpMz8VwYrNyfeCOqm BrfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=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=orWgau00QeG5uRuvw4ycZxddrBe0TZOXpOS+KYLMIRg=; b=d2ONVBvKJ4qyM3DZ0hBKOywbdjAVKrjvbyiwix3Gcx6+PNK6LbLaCryL9sJPKeEsIq uacHMcwJ5vSvtfyYYc+MIbPJ208oZeBoqKOcqoGguX8ihqlhhohw7zPFR67fyHrFGm29 gM1f6yUXTwx64kVt3ZEhKKwLTFWQKPLkQO7t0UF5Qhsuxk3r7nXPglxVxyt/FbNyqO8N rjGzBo0jN5pBFOgNe2Os17P+83l9ZlsY8WWd9yCytdnFc39KbgKsIC4EjTGNVrSzvUZK SpzrKEyiYtU/OyzNr84Fuk5yYG5xNyqz7qLvJ0go3s7dCjettBpBOVAyRHuDYeG9HCQ5 2Dhw== X-Gm-Message-State: AOAM533TXZBi+XIWhfqWZCDEBKsq4kaADNAGrMusvSuxn3HtNTVHRHQ/ r4DjUwyJ1nJPcMW6iumBkFY= X-Google-Smtp-Source: ABdhPJxYb9/Zik7ZzdyD1grUid30HvSJoayIl+QFMUTmm/beydw85e/x5G8rPXFddhjt60dkR0K9kA== X-Received: by 2002:aca:3151:: with SMTP id x78mr6194047oix.145.1618574433033; Fri, 16 Apr 2021 05:00:33 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6830:23a1:: with SMTP id m1ls2275614ots.8.gmail; Fri, 16 Apr 2021 05:00:31 -0700 (PDT) X-Received: by 2002:a9d:3423:: with SMTP id v32mr3501456otb.168.1618574431342; Fri, 16 Apr 2021 05:00:31 -0700 (PDT) In-Reply-To: X-Original-Sender: angel.joaniquet-1NcKPjY1c5x0ubjbjo6WXg@public.gmane.org X-Original-From: Angel Joaniquet 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:28178 Archived-At: ------=_Part_1_1964858770.1618574430714 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cross-posting of =20 https://stackoverflow.com/questions/67109880/is-it-posible-to-enable-extens= ions-on-pandoc-filters#comment118648930_67109880 The reason is that I want to have all in one file, to diminish the=20 cognitive load El viernes, 16 de abril de 2021 a las 13:41:58 UTC+2, mb21 escribi=C3=B3: > cross-posting of=20 > https://stackoverflow.com/questions/67109880/is-it-posible-to-enable-exte= nsions-on-pandoc-filters > > Why do you prefer to set this in the filter instead of on the writer? I= =20 > don't think there's a way to do that... because the filter just outputs a= n=20 > AST again, and what you're trying to change is happening in the writer... > > On Thursday, April 15, 2021 at 4:20:32 PM UTC+2 Angel Joaniquet wrote: > >> The lua split function is this >> >> >> ```lua >> function split(str,pat) >> local tbl =3D {} >> str:gsub(pat, function(x) tbl[#tbl+1]=3Dx end) >> return tbl >> end >> ``` >> >> El jueves, 15 de abril de 2021 a las 16:08:23 UTC+2, Angel Joaniquet=20 >> escribi=C3=B3: >> >>> >>> I'm trying to make a filter to transform some features of org-mode to= =20 >>> GitLab-markdown (not supported by Pandoc out of the box), in particular= ,=20 >>> the math blocks. >>> >>> The filter should work when transforming to `markdown`, but instead of= =20 >>> giving the markdown format for the math blocks (enclosed by `$$...$$`),= it=20 >>> should write the blocks as=20 >>> >>> ``` math >>> a + b =3D c >>> ```=20 >>> >>> The preces I have now is=20 >>> >>> In org-mode, the math blocks are simply the latex code: >>> >>> ``` >>> \begin{equation} >>> a + b =3D c >>> \end{equation} >>> ``` >>> >>> this is parsed as a pandoc AST `RawBlock` with format `latex`. I then= =20 >>> remove the first (`\begin{equation}`) an last line (`\end{equation}`), = and=20 >>> construct a pandoc `CodeBlock` with atrributes `{"math"}`, so the=20 >>> `CodeBlock` object displays in AST as >>> >>> ``` >>> CodeBlock ("",["math"],[]) "a + b =3D c\n" >>> ``` >>> >>> and then I let Pandoc create the markdown document, and the written=20 >>> result is=20 >>> >>> ``` {.math} >>> a + b =3D c >>> ```=20 >>> >>> >>> >>> **The question:** =20 >>> I want the bare `math`, not `{.math}` written, without the use of CLI= =20 >>> options.=20 >>> >>> >>> I am aware that this can be done setting the Writer extension=20 >>> `fenced_code_attributes` to false (eg. `$pandoc -w=20 >>> markdown-fenced_code_attributes ...`), but I would much prefer this don= e=20 >>> inside the filter.=20 >>> >>> Or is it possible to set the extensions inside the filter? >>> >>> >>> Here is my atempted lua-filter: >>> >>> ``` lua >>> function RawBlock(rb) >>> if rb.format =3D=3D "latex" then >>> local text =3D rb.text >>> split_text =3D split(text, "[^\n]*") >>> if split_text[1] =3D=3D '\\begin{equation}' and=20 >>> split_text[#split_text-1] =3D=3D '\\end{equation}' then >>> table.remove(split_text, #split_text-1) >>> table.remove(split_text, 1) >>> text =3D table.concat(split_text, "\n") >>> local cb =3D pandoc.CodeBlock() >>> cb.attr =3D {"",{"math"}} >>> cb.text =3D text >>> return cb >>> end >>> end >>> end >>> ``` >>> >>> >>> Kind regards,=20 >>> >>> Angel >>> >>> >>> >>> --=20 ---------------------------------------------------------------------------= -------------------- La informaci=C3=B3n contenida en este mensaje es de car=C3=A1cter privado y= =20 confidencial, dirigi=C3=A9ndose exclusivamente al destinatario mencionado en el=20 encabezamiento. Si usted ha recibido este mensaje por error, le informamos=20 que no debe revelar, copiar, distribuir o usarlo en ning=C3=BAn sentido ya = que=20 est=C3=A1 prohibido por la legislaci=C3=B3n vigente. Rogamos lo comunique al=20 remitente y borre dicho mensaje y cualquier documento adjunto que pudiera=20 contener. Los datos personales que usted facilite por correo electr=C3=B3nico=20 podr=C3=A1n ser tratados por Zitro SARL con el fin de responder a su consul= ta o=20 atender su solicitud, as=C3=AD como gestionar la relaci=C3=B3n comercial, contractual= =20 o precontractual con usted. La base legitimadora de este tratamiento es el=20 inter=C3=A9s leg=C3=ADtimo de Zitro, as=C3=AD como el mantenimiento de la relaci=C3=B3n=20 contractual o de medidas precontractuales. No se ceder=C3=A1n datos a terce= ros,=20 salvo obligaci=C3=B3n legal. Sus datos ser=C3=A1n conservados durante todo el plazo=20 de duraci=C3=B3n de la relaci=C3=B3n entre usted y Zitro y, una vez terminada la=20 misma, durante el plazo que determine la legislaci=C3=B3n aplicable en cada= =20 momento. Usted podr=C3=A1 ejercitar en todo momento los derechos reconocidos en=20 la normativa de protecci=C3=B3n de datos, as=C3=AD como contactar con Zitro a trav=C3=A9s=20 de la siguiente direcci=C3=B3n:=C2=A0info-1NcKPjY1c5x0ubjbjo6WXg@public.gmane.org=20 . The information contained in this message is=20 private and confidential, speaking exclusively to the recipient mentioned=20 in the heading. If you have received this message by mistake, we inform you= =20 that you should not disclose, copy, distribute or use it in any way because=20 it is prohibited by current law. Please notify the sender and delete the=20 message and any attachment that might contain. The personal data you=20 provide by email may be processed by Zitro SARL for the purpose of=20 responding to your query or attending to your request, and to manage the=20 commercial, contractual or pre-contractual relationship with you. The=20 legitimizing basis of this processing is the legitimate interest of Zitro,= =20 and the maintenance of the contractual relationship or pre-contractual=20 measures. No data will be passed to third parties unless there is a legal=20 obligation to do so. Your data will be retained throughout the term of your=20 relationship with Zitro and, once that is terminated, for the term legally= =20 required at any specific time. You may exercise your rights, as recognized=20 in data protection legislation, at any time, and you may contact Zitro at=20 the following email address:=C2=A0info-1NcKPjY1c5x0ubjbjo6WXg@public.gmane.org=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/03f7ab59-6b1a-451e-8528-4b164d439dc4n%40googlegroups.com. ------=_Part_1_1964858770.1618574430714 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cross-posting of  https://stackoverflow.com/questions/67109880/is-it-p= osible-to-enable-extensions-on-pandoc-filters#comment118648930_67109880
=
The reason is that I want to have all in one file, to diminish th= e cognitive load


El viernes, 16 de abril de 2021 a las 13:41:58 UT= C+2, mb21 escribi=C3=B3:
cross-posting of https://stack= overflow.com/questions/67109880/is-it-posible-to-enable-extensions-on-pando= c-filters

Why do you prefer to set this in the filte= r instead of on the writer? I don't think there's a way to do that... becau= se the filter just outputs an AST again, and what you're trying to change i= s happening in the writer...

On Thursday, April 15, 2021 at 4:20:32 PM = UTC+2 Angel Joaniquet wrote:
The lua split function is this


```lua
function split(s= tr,pat)
   local tbl =3D {}
   str:gsub(pat, func= tion(x) tbl[#tbl+1]=3Dx end)
   return tbl
end
```
El juev= es, 15 de abril de 2021 a las 16:08:23 UTC+2, Angel Joaniquet escribi=C3=B3= :

I'm trying to ma= ke a filter to transform some features of org-mode to GitLab-markdown (not = supported by Pandoc out of the box), in particular, the math blocks.
The filter should work when transforming to `markdown`, but instead of giv= ing the markdown format for the math blocks (enclosed by `$$...$$`), it sho= uld write the blocks as

    ```  math
 =    a + b =3D c
    ```

The preces I hav= e now is

In org-mode, the math blocks are simply the latex code:
```
\begin{equation}
a + b =3D c
\end{equation}
```
this is parsed as a pandoc AST `RawBlock` with format `latex`. I then remo= ve the first (`\begin{equation}`) an last line (`\end{equation}`), and cons= truct a pandoc `CodeBlock` with atrributes `{"math"}`, so the `CodeBlock` o= bject displays in AST as

```
CodeBlock ("",["math"],[]) "a + b = =3D c\n"
```

and then I let Pandoc create the markdown document, = and the written result is

    ``` {.math}
 &= nbsp;  a + b =3D c
    ```



**The que= stion:**  
I want the bare `math`, not `{.math}` written, without t= he use of CLI options.


I am aware that this can be done setting= the Writer extension `fenced_code_attributes` to false (eg. `$pandoc -w ma= rkdown-fenced_code_attributes ...`), but I would much prefer this done insi= de the filter.

Or is it possible to set the extensions inside the f= ilter?


Here is my atempted lua-filter:

``` lua
functio= n RawBlock(rb)
   if rb.format =3D=3D "latex" then
 &n= bsp;    local text =3D rb.text
    &n= bsp; split_text =3D  split(text, "[^\n]*")
    =   if split_text[1] =3D=3D '\\begin{equation}'  and split_text[#sp= lit_text-1] =3D=3D '\\end{equation}' then
      = ;   table.remove(split_text, #split_text-1)
    = ;     table.remove(split_text, 1)
    = ;     text =3D table.concat(split_text, "\n")
 =         local cb =3D pandoc.CodeBlock()
&n= bsp;        cb.attr =3D {"",{"math"}}
&nbs= p;        cb.text =3D text
   &n= bsp;     return cb
      en= d
   end
end
```


Kind regards,

Angel<= br>



--------------------------------------------------------------= ---------------------------------

La informaci=C3=B3n contenida en este mensaje es de car=C3= =A1cter privado y confidencial, dirigi=C3=A9ndose
exclusivamente al dest= inatario mencionado en el encabezamiento. Si usted ha recibido este mensaje= por
error, le informamos que no debe revelar, copiar, distribuir o usar= lo en ning=C3=BAn sentido ya que est=C3=A1
prohibido por la legislaci=C3= =B3n vigente. Rogamos lo comunique al remitente y borre dicho mensaje y
= cualquier documento adjunto que pudiera contener. Los datos personales que = usted facilite por correo
electr=C3=B3nico podr=C3=A1n ser tratados por = Zitro SARL con el fin de responder a su consulta o atender su
solicitud,= as=C3=AD como gestionar la relaci=C3=B3n comercial, contractual o precontr= actual con usted. La base
legitimadora de este tratamiento es el inter= =C3=A9s leg=C3=ADtimo de Zitro, as=C3=AD como el mantenimiento de la
rel= aci=C3=B3n contractual o de medidas precontractuales. No se ceder=C3=A1n da= tos a terceros, salvo obligaci=C3=B3n
legal. Sus datos ser=C3=A1n conser= vados durante todo el plazo de duraci=C3=B3n de la relaci=C3=B3n entre uste= d y Zitro y,
una vez terminada la misma, durante el plazo que determine = la legislaci=C3=B3n aplicable en cada momento.
Usted podr=C3=A1 ejercita= r en todo momento los derechos reconocidos en la normativa de protecci=C3= =B3n de
datos, as=C3=AD como contactar con Zitro a trav=C3=A9s de la sig= uiente direcci=C3=B3n:=C2=A0info-1NcKPjY1c5x0ubjbjo6WXg@public.gmane.org.

The information contained = in this message is private and confidential, speaking exclusively to therecipient mentioned in the heading. If you have received this message by m= istake, we inform you that
you should not disclose, copy, distribute or = use it in any way because it is prohibited by current law.
Please notify= the sender and delete the message and any attachment that might contain. T= he personal
data you provide by email may be processed by Zitro SARL for= the purpose of responding to your query
or attending to your request, a= nd to manage the commercial, contractual or pre-contractual
relationship= with you. The legitimizing basis of this processing is the legitimate inte= rest of Zitro, and the
maintenance of the contractual relationship or pr= e-contractual measures. No data will be passed to
third parties unless t= here is a legal obligation to do so. Your data will be retained throughout = the term of
your relationship with Zitro and, once that is terminated, f= or the term legally required at any specific
time. You may exercise your= rights, as recognized in data protection legislation, at any time, and you=
may contact Zitro at the following email address:=C2=A0info-1NcKPjY1c5x0ubjbjo6WXg@public.gmane.org.

--
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/03f7ab59-6b1a-451e-8528-4b164d439dc4n%40googlegroups.= com.
------=_Part_1_1964858770.1618574430714--