From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/28177 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: mb21 Newsgroups: gmane.text.pandoc Subject: Re: Modify writer or extensions inside a filter Date: Fri, 16 Apr 2021 04:41:58 -0700 (PDT) Message-ID: 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/mixed; boundary="----=_Part_3704_1521980168.1618573318682" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20008"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBDCMBBVJ5EFBBB7Q4WBQMGQERDSWARY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Apr 16 13:42:04 2021 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-ot1-f64.google.com ([209.85.210.64]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lXMrK-0004x0-5g for gtp-pandoc-discuss@m.gmane-mx.org; Fri, 16 Apr 2021 13:42:02 +0200 Original-Received: by mail-ot1-f64.google.com with SMTP id a3-20020a9d5c830000b0290286fa75df03sf4554550oti.10 for ; Fri, 16 Apr 2021 04:42:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender: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=GKuH1jGjrZ5Oi1UUzXluZe4Z1OrfrOnJ1LpoMb74CTY=; b=S/zQnLGdlKix4P/6FrI1ef2vsoOunsgvgbYPWmUZ9WERymN0HUKBNnYVSCFkME++P4 r8cLubTon5U/tPA7tWwiNzZItm0bFJY0Yw/h0PLnjNj35Smh9HFQsAnjv5gK/l2URhID 1SU/bXvijLlk/t34cEpcUuNOCtn1sAs2FMlaFCqKLcqlM7T2xl4rX4HkQupXPX2UimY9 3Tmp4fx02Yan3ekNPE+Hg1EXKGQmzUFlsRzBEQ/KskLc5Oul6yE/Rfc3NirwOMLbXUz2 05r5ixgjA5gdPJgODmG9BrEA+qXd3sdtkPd9f9BZnz2/CilxMACIwMByFJzn+gc9ZzRT ks5A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.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=GKuH1jGjrZ5Oi1UUzXluZe4Z1OrfrOnJ1LpoMb74CTY=; b=Q5IN0TWnNWadZQ+6jisOmVLlGcoEBPLl4sRTynS+LaGAH2ATwGov3o4BXHGrR7VYi4 UOBF+c5TRQCLwqy9Am7kjcSNN8PhoE2eBc4Zyzvqhll6TChumvlR3V/HmdAPTFRKxean oN8tA+pLd1dmIEdg9WJ3A0XSStVozMTWWGALj491sFuBNNZC+iVsOBt0+rywOHI6oL1Z 5yOftFoUVrpPh/uDtwoRJ46kR0HXoYYZm2pZmHgfr4o/Oi6G9bJCjsFkYASercR2cm0n X1EniaDv80Tk4PYmtDCrtl/wFBUJQfF5/8BYc+iQIRUz8GYyY9zp795rboK3ZdPkMZCJ cZQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender: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=GKuH1jGjrZ5Oi1UUzXluZe4Z1OrfrOnJ1LpoMb74CTY=; b=hlCGuhcFYyehDMjuYCB0GQ1SFn0nSbX5xcO84ygdoRhrLleFlM/NnhjXF1SEk55ynt MDbpR2FvtvGYGaQOm8TUtgFsF0UqfemXxRUcNAhQjN/CuhzANcXH+FTAyb0r7Dq7vZjm 3xYD8nwyiHuxeb+LsKuykr1ayiG5q4q+piQbYIuuuM13xBO4NtEHYTpSvP3itIiNUCOg uAkxXbuRwP2G2pwiHCNGZ+pvIVQBwhA12r3aD7f2A2SfQ/Q5+gNwE9vqczJRBcSQLEtI SytG1cBmjjq3oW+T565LMUvWeZ0RSZwG06D+l5o/139fan+qFmy3Wyn0Y1ebQRHP9zRA z80w== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM532XcOzVWKZmP1ZXjUgdxO6e/qlQXC9tboke6N9Iq1meOWv/gMIN fDFDNzpHfXtzyWh5tF6zqIY= X-Google-Smtp-Source: ABdhPJwJ2MyN9HdHXV2VB0pBSDhRJrbUa8f8mInBhYA07VuPqUVOSjl0aPrLB/dvLR5ZMC7A9FPP2g== X-Received: by 2002:a9d:6ada:: with SMTP id m26mr3400024otq.18.1618573321077; Fri, 16 Apr 2021 04:42:01 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a9d:638a:: with SMTP id w10ls2268654otk.6.gmail; Fri, 16 Apr 2021 04:41:59 -0700 (PDT) X-Received: by 2002:a9d:1a1:: with SMTP id e30mr3500482ote.283.1618573319242; Fri, 16 Apr 2021 04:41:59 -0700 (PDT) In-Reply-To: <50d9ae1b-95a0-445f-9ab2-5b1fe2cc992fn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> X-Original-Sender: mauro.bieg-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:28177 Archived-At: ------=_Part_3704_1521980168.1618573318682 Content-Type: multipart/alternative; boundary="----=_Part_3705_813857871.1618573318682" ------=_Part_3705_813857871.1618573318682 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cross-posting=20 of https://stackoverflow.com/questions/67109880/is-it-posible-to-enable-ext= ensions-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 an= =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}`), a= nd=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 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 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/c01112ea-3fd0-42c7-86ae-6e1806671b7bn%40googlegroups.com. ------=_Part_3705_813857871.1618573318682 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cross-posting of https://stackoverflow.com/questions/67109880/is-it-po= sible-to-enable-extensions-on-pandoc-filters

Why do you = prefer to set this in the filter instead of on the writer? I don't think th= ere's a way to do that... because the filter just outputs an 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 th= is


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

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

I'm trying to make a filter to transform som= e features of org-mode to GitLab-markdown (not supported by Pandoc out of t= he 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
=
=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 code:

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

this is parsed as a pandoc = AST `RawBlock` with format `latex`. I then remove the first (`\begin{equati= on}`) an last line (`\end{equation}`), and construct a pandoc `CodeBlock` w= ith atrributes `{"math"}`, so the `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 is

=C2=A0=C2=A0=C2=A0 ``` {.math}<= br>=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 do= ne setting the Writer extension `fenced_code_attributes` to false (eg. `$pa= ndoc -w markdown-fenced_code_attributes ...`), but I would much prefer this= done inside the filter.

Or is it possible to set the extensions in= side the filter?


Here is my atempted lua-filter:

``` lua<= br>function RawBlock(rb)
=C2=A0=C2=A0 if rb.format =3D=3D "latex&qu= ot; 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{e= quation}'=C2=A0 and split_text[#split_text-1] =3D=3D '\\end{equatio= n}' then
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 table.remove(sp= lit_text, #split_text-1)
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 tab= le.remove(split_text, 1)
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 tex= t =3D table.concat(split_text, "\n")
=C2=A0=C2=A0 =C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 local cb =3D pandoc.CodeBlock()
=C2=A0=C2=A0 =C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 cb.attr =3D {"",{"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
```


Kind regards,

= Angel



--
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/c01112ea-3fd0-42c7-86ae-6e1806671b7bn%40googlegroups.= com.
------=_Part_3705_813857871.1618573318682-- ------=_Part_3704_1521980168.1618573318682--