The lua split function is this


```lua
function split(str,pat)
   local tbl = {}
   str:gsub(pat, function(x) tbl[#tbl+1]=x end)
   return tbl
end
```

El jueves, 15 de abril de 2021 a las 16:08:23 UTC+2, Angel Joaniquet escribió:

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.

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

    ```  math
    a + b = c
    ```

The preces I have now is

In org-mode, the math blocks are simply the latex code:

```
\begin{equation}
a + b = c
\end{equation}
```

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

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

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

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



**The question:**  
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 it possible to set the extensions inside the filter?


Here is my atempted lua-filter:

``` lua
function RawBlock(rb)
   if rb.format == "latex" then
      local text = rb.text
      split_text =  split(text, "[^\n]*")
      if split_text[1] == '\\begin{equation}'  and split_text[#split_text-1] == '\\end{equation}' then
         table.remove(split_text, #split_text-1)
         table.remove(split_text, 1)
         text = table.concat(split_text, "\n")
         local cb = pandoc.CodeBlock()
         cb.attr = {"",{"math"}}
         cb.text = text
         return cb
      end
   end
end
```


Kind regards,

Angel




-----------------------------------------------------------------------------------------------

La información contenida en este mensaje es de carácter privado y confidencial, dirigiéndose
exclusivamente al destinatario mencionado en el encabezamiento. Si usted ha recibido este mensaje por
error, le informamos que no debe revelar, copiar, distribuir o usarlo en ningún sentido ya que está
prohibido por la legislación 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ónico podrán ser tratados por Zitro SARL con el fin de responder a su consulta o atender su
solicitud, así como gestionar la relación comercial, contractual o precontractual con usted. La base
legitimadora de este tratamiento es el interés legítimo de Zitro, así como el mantenimiento de la
relación contractual o de medidas precontractuales. No se cederán datos a terceros, salvo obligación
legal. Sus datos serán conservados durante todo el plazo de duración de la relación entre usted y Zitro y,
una vez terminada la misma, durante el plazo que determine la legislación aplicable en cada momento.
Usted podrá ejercitar en todo momento los derechos reconocidos en la normativa de protección de
datos, así como contactar con Zitro a través de la siguiente dirección: info-1NcKPjY1c5x0ubjbjo6WXg@public.gmane.org.

The information contained in this message is private and confidential, speaking exclusively to the
recipient mentioned in the heading. If you have received this message by mistake, 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. The 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, and to manage the commercial, contractual or pre-contractual
relationship with you. The legitimizing basis of this processing is the legitimate interest of Zitro, and the
maintenance of the contractual relationship or pre-contractual measures. No data will be passed to
third parties unless there 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, for 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: info-1NcKPjY1c5x0ubjbjo6WXg@public.gmane.org.

--
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 email to pandoc-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.