From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/28171 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "'Angel Joaniquet' via pandoc-discuss" Newsgroups: gmane.text.pandoc Subject: Modify writer or extensions inside a filter Date: Thu, 15 Apr 2021 07:08:23 -0700 (PDT) Message-ID: <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_1427_2141669234.1618495703076" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10738"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCUYX56H3IEBBV4R4GBQMGQE7HKCFDI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Thu Apr 15 16:08:26 2021 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oi1-f189.google.com ([209.85.167.189]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lX2fS-0002cY-5J for gtp-pandoc-discuss@m.gmane-mx.org; Thu, 15 Apr 2021 16:08:26 +0200 Original-Received: by mail-oi1-f189.google.com with SMTP id w4-20020a0568081404b0290102a1fd05b2sf7790250oiv.6 for ; Thu, 15 Apr 2021 07:08:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=date:from:to:message-id:subject:mime-version:x-original-sender :reply-to:precedence:mailing-list:list-id:list-post:list-help :list-archive:list-subscribe:list-unsubscribe; bh=Yv2MmTr1UzLkeDdckpD7/patNIbcKiXtXhUr/sTdBHw=; b=h5moZ6fsF+29OgWTXwKyzPyvdGMkKwtvgNXQKqxDEoVZ3uD9EkLIFulqFzR0xEeV3o Fb+tGHqrnlw1EMXap+ma1LcXzikpTTrwwdp17SbkHK9jhmgYDMDGZ1xb3NdzMuZqi7rL qloRIjyvJ+DwVQiSJYQE47yB3puvcS/KvyBJ8Z8FrSLZXWZ7U3ZFj09ghzj6rn3RHL6n nqFeHevtOIshkI//CI7cNvqBUd/ZkQoFDP9pxmv60t7oMBmZXxRAP9N+aKkUrgGCWFrJ 9t8aeRb2E9sMnr7dNllj/vK3ioJ8FOl4fmg2h1XRpNLOxlVPOom7HJsoKf2zMsQMDJ4e E1Wg== 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: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=Yv2MmTr1UzLkeDdckpD7/patNIbcKiXtXhUr/sTdBHw=; b=ffokuzmdPE1wDpckG8JjLqPTb1s2OZxkEQV5gk2S3RowyJjFtt75/bvsDx/S13De2I Ul2t5A+BmFC86D2G+4BNF+DvHJzqDHgrPUsD7LKelF+XqrSyYLcII9osJyS02t6C2fJo TxnI1y0MHvJ8C2p8VO6HyinZuDbCWiShq4piQRVTrKQSVvQ1bMuyZ/lBjoLfq0xT+cq9 a6ocarUBFUC+wdWyAlORZQOjoipxxj7g/ocg33mQZYumyofbYZ7RG/xwmX7hYrBwGXtL yAkux5XHAr2XqSaczbjmdEIcfKClXFdzjw2IzXBXonC4Skj00xqj72uBMSjccsJdoZrU JkCg== X-Gm-Message-State: AOAM53155cPEpWNkP5opVsz+ADzs1wOAF1pG64hbEo6jyseKQdidz7co 68EwFNNXTYoyzZBxVMJFMn0= X-Google-Smtp-Source: ABdhPJxRHfDP0gti4vzQ9DxjQdoORgTcElnthmAvYb5GlLS3AINFGkcJaH/X9AQHEuAKWicuYF9h8Q== X-Received: by 2002:aca:5741:: with SMTP id l62mr2764754oib.156.1618495705175; Thu, 15 Apr 2021 07:08:25 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a4a:9732:: with SMTP id u47ls322823ooi.5.gmail; Thu, 15 Apr 2021 07:08:23 -0700 (PDT) X-Received: by 2002:a4a:e749:: with SMTP id n9mr2797170oov.89.1618495703589; Thu, 15 Apr 2021 07:08:23 -0700 (PDT) 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:28171 Archived-At: ------=_Part_1427_2141669234.1618495703076 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 result= =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/509d7700-5cb3-4382-9276-c4b2e2a0c3e5n%40googlegroups.com. ------=_Part_1427_2141669234.1618495703076 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I'm trying to make a filter to transform some features of org-mode to G= itLab-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 giving the markdown format for the math blocks (enclosed b= y `$$...$$`), it should write the blocks as

    ```&= nbsp; math
    a + b =3D c
    ```
=
The preces I have now is

In org-mode, the math blocks are simpl= y the latex code:

```
\begin{equation}
a + b =3D c
\end{equ= ation}
```

this is parsed as a pandoc AST `RawBlock` with format = `latex`. I then remove the first (`\begin{equation}`) an last line (`\end{e= quation}`), and construct a pandoc `CodeBlock` with atrributes `{"math"}`, = so the `CodeBlock` object displays in AST as

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

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

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


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


I am aware that this c= an be done setting the Writer extension `fenced_code_attributes` to false (= eg. `$pandoc -w markdown-fenced_code_attributes ...`), but I would much pre= fer this done inside the filter.

Or is it possible to set the exten= sions 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
 &n= bsp;    split_text =3D  split(text, "[^\n]*")
 =      if split_text[1] =3D=3D '\\begin{equation}'  = and 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_tex= t, "\n")
         local cb =3D pandoc= .CodeBlock()
         cb.attr =3D {""= ,{"math"}}
         cb.text =3D text<= br>         return cb
  &nb= sp;   end
   end
end
```


Kind regar= ds,

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/509d7700-5cb3-4382-9276-c4b2e2a0c3e5n%40googlegroups.= com.
------=_Part_1427_2141669234.1618495703076--