From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/28172 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: Thu, 15 Apr 2021 07:20:32 -0700 (PDT) Message-ID: <50d9ae1b-95a0-445f-9ab2-5b1fe2cc992fn@googlegroups.com> References: <509d7700-5cb3-4382-9276-c4b2e2a0c3e5n@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_2741_723074881.1618496432696" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26290"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCUYX56H3IEBBMMX4GBQMGQEDTCOPTY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Thu Apr 15 16:20:35 2021 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oi1-f184.google.com ([209.85.167.184]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lX2rD-0006g8-HN for gtp-pandoc-discuss@m.gmane-mx.org; Thu, 15 Apr 2021 16:20:35 +0200 Original-Received: by mail-oi1-f184.google.com with SMTP id c11-20020a544e8b0000b029013d55eb5c1asf7802100oiy.8 for ; Thu, 15 Apr 2021 07:20:35 -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=oSjFIMKfJcv2ig/80hhAwoPdVeuiIs2d9t1tS2BEN+A=; b=YSVCuVmKHHY7Hd/akY9fSZ2FRDaxG0giDGc1n6ql7a608wfFcls71X/ctL2fduD1NM xYYjpcqSqpVoZAqPuvF4tfwy8BD7GT6nAPnqHuFPCoV/R03ev+L5diQmJv7B07z2vX4V sgzCA94gDV5jOHbsi7mELx/kwek8x2ej0671kJUzBKDZusTcMJfkUWKEesCHcn5hXv/e 9FTOOOl589kRienc7RkYX6X2oopdPn7P9JLcSkAudIYhJYjML/M9xAu1IMuYR07o6BZE B4HFPMWfY5k7JpTX6WXukTW/zaWEKXI0SLWQPq44BJtC/RN7ZpNsiwM52gDQYYHQy4AU mzUw== 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=oSjFIMKfJcv2ig/80hhAwoPdVeuiIs2d9t1tS2BEN+A=; b=GAsLIWRz2bsyZQJJgk3P90J7zqKU8uDxCk75vpfY6rbPD2pdYGMr+g4eP764pAm+xR OTzYxc1ObVdHOQmTws6bTa2/tRnVWmshlGcFTXmcxGvDfxm1KQaqZXnopTvjWDmciFyk KOLq24nc2kS9T7ycD09b/MbJ+Ow3+z6wrm3KPtwtzCwXY9SwPEORst3sS9K/3+l3AhAC lgDvY9ROSJ1Pwizw3LxOoXdgTfpuAiWSSxARDKCBfB1F66L5bKQeUlPzph9mePqXAwjF rDIGqg/dXY5nwWtQioRkVKzpJYqSJFSC6lv9aZzqvHdigle1/QdoZJS8AJWAmr0FgpA1 SPNA== X-Gm-Message-State: AOAM531azJ9yqP308g2/qiHzA2YLrczBZI3/BCPN/xEEFNHGfJ1GjjKG /EgrROmTmEh4ExZj3K2MELI= X-Google-Smtp-Source: ABdhPJwLwzeovjd5c13yzA+DR56OR4zGLRE4KFTFq6I/I34VZtac9hzaah5L7xd80dhZqKLVUw2NNQ== X-Received: by 2002:a05:6808:28b:: with SMTP id z11mr2855022oic.3.1618496434620; Thu, 15 Apr 2021 07:20:34 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a54:4514:: with SMTP id l20ls721993oil.5.gmail; Thu, 15 Apr 2021 07:20:33 -0700 (PDT) X-Received: by 2002:aca:ad52:: with SMTP id w79mr2709894oie.148.1618496433242; Thu, 15 Apr 2021 07:20:33 -0700 (PDT) In-Reply-To: <509d7700-5cb3-4382-9276-c4b2e2a0c3e5n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 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:28172 Archived-At: ------=_Part_2741_723074881.1618496432696 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 `$$...$$`), i= t=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}`), an= d=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 resul= t=20 > 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 done= =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/50d9ae1b-95a0-445f-9ab2-5b1fe2cc992fn%40googlegroups.com. ------=_Part_2741_723074881.1618496432696 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 escribi=C3=B3:
<= /div>

I'm trying= to make 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.<= br>
The filter should work when transforming to `markdown`, but instead = of giving the markdown format for the math blocks (enclosed by `$$...$$`), = it should write the blocks as

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

The preces= I have now is

In org-mode, the math blocks are simply the latex co= de:

```
\begin{equation}
a + b =3D c
\end{equation}
```<= br>
this is parsed as a pandoc AST `RawBlock` with format `latex`. I the= n remove the first (`\begin{equation}`) an last line (`\end{equation}`), an= d construct a pandoc `CodeBlock` with atrributes `{"math"}`, so t= he `CodeBlock` object displays in AST as

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

and then= I let Pandoc create the markdown document, and the written result is
<= br>=C2=A0=C2=A0=C2=A0 ``` {.math}
=C2=A0=C2=A0=C2=A0 a + b =3D c
=C2= =A0=C2=A0=C2=A0 ```



**The question:** =C2=A0
I want the = bare `math`, not `{.math}` written, without the use of CLI options.

I am aware that this can be done setting the Writer extension `fenced_= code_attributes` to false (eg. `$pandoc -w markdown-fenced_code_attributes = ...`), but I would much prefer this done inside the filter.

Or is i= t possible to set the extensions inside the filter?


Here is my a= tempted lua-filter:

``` lua
function RawBlock(rb)
=C2=A0=C2=A0= if rb.format =3D=3D "latex" then
=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 local text =3D rb.text
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 split_text =3D= =C2=A0 split(text, "[^\n]*")
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if= split_text[1] =3D=3D '\\begin{equation}'=C2=A0 and split_text[#spl= it_text-1] =3D=3D '\\end{equation}' then
=C2=A0=C2=A0 =C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 table.remove(split_text, #split_text-1)
=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 table.remove(split_text, 1)
=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 text =3D table.concat(split_text, "= \n")
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 local cb =3D pando= c.CodeBlock()
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cb.attr =3D {&= quot;",{"math"}}
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 cb.text =3D text
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return = cb
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 end
=C2=A0=C2=A0 end
end
```<= br>

Kind regards,

Angel




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

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/50d9ae1b-95a0-445f-9ab2-5b1fe2cc992fn%40googlegroups.= com.
------=_Part_2741_723074881.1618496432696--