From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/30629 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: msprev Newsgroups: gmane.text.pandoc Subject: Re: MWE for building a table using Lua Date: Sun, 29 May 2022 09:48:58 -0700 (PDT) Message-ID: References: <11978438-43d6-4943-aaac-659d51f05f43n@googlegroups.com> <82a0d0eb-877a-47ff-8632-907322c40648n@googlegroups.com> <8094d69c-8374-4662-9c5c-c099e14b19b2n@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_2418_48753443.1653842938562" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23709"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBD2ORKWKWEDBB66HZ2KAMGQEY6YHIMI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sun May 29 18:49:04 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oo1-f60.google.com ([209.85.161.60]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nvM6B-0005xU-Mv for gtp-pandoc-discuss@m.gmane-mx.org; Sun, 29 May 2022 18:49:03 +0200 Original-Received: by mail-oo1-f60.google.com with SMTP id n4-20020a4a8484000000b0035f4d798c46sf5267364oog.21 for ; Sun, 29 May 2022 09:49:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; 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=yf1MngPca49LpFMV7fweuy5C0JQ/hmbA1agpTWRCX7U=; b=C34Fa6FAhi+nQO9nmyoeVOw/HvwMQhpe7L/+lQPFH0SEnPhnvy1x9N2QZn+aYmsqum uc0a2OOuCqjuG49VznElAp/7sCkiMRoc8SDWW9qC19Gjk6qSsyjpJHIv2e2HMXAQ4715 kIZn/M/JWe5ETo69vjXKcFLq4OorTZ8t9i7fFe1UeJH0iwHskhJIy9eGgLeUlnfk0WKa 7F1VWFhUR9HJB/m9qI0Z6ovvBDG74oEGri5jbecx6WR6sdJfBt4loFhjuPVSMboW28Sb pbjrI9tpKdrLkcQzyF/I1Qq887aWcPw5ZvOFyW6A8Bj021L+TA+7FnQ/xG27TKQi3lJw 3kTw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=yf1MngPca49LpFMV7fweuy5C0JQ/hmbA1agpTWRCX7U=; b=M9/Kh8Mv7qDZRguALfJy8eerpxOuhbgnYCz0w9bKDb1bJ5LoqZUcfgbF24951bbcQa x3aXkytfqQwdTiApvEArutzrzvm653CQ04+O4TDcU6rRLei0YHolUeWLa0bWPXT2yp9o pbFycUmshyEhzU9A386BaWThaZjbKX3Kt9QCsgNDFnqeRwY/6KNSqkWxJFCkF0jpDLat bZlZKZRh3KXgJjmGwJiDzVFji6IEjNwOZeuK7St0XVQa3u9RrKZnPxwS8uOU8D8pVKI+ FX/r1liryoUshWA0i7AMi8XFZN9B6/87TBB0zxrwsSz9Eclg48V4xIRnJgCzJ/3LAnuw ieYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=yf1MngPca49LpFMV7fweuy5C0JQ/hmbA1agpTWRCX7U=; b=4yRuX5DUtIGjLLVRKji1H2LmIKyjr70hvrinqKRdbNAqco67rzeysYpAcYjiJJs3xV AU++oUcy7EcXoCD1qBkD4UL2tMi3x7pdCHGQIOGrfQEqnc27PBwVa76lsIV7AI+zI+q6 mdl6LT0ziLs4G19RJH2D2x1eXP74c/SwaoPAyI4O9FXM+g8W3e7Us1vQybPCQFvYgPLs lpAK8KUENyzqW5UHDLFLujfY3ncVxhc/HhH/vyx0N7GlV7YdCnqyn6wdTqcnq11W7HGJ 4fDVapjAa8u/jhkZeH1PK19fic4KtBS1Qr2gQ6vY4quikadaG5GDVJS5IYziIdAOaz5U t0IQ== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM533SbWkQV+rdVo/M0sSeZGJ/1obPEgrEB6w/MyxNCirIUDvesX40 kmYqu+Sz3Zpyt7/KfqRny3A= X-Google-Smtp-Source: ABdhPJzXhWZik8QreAsQpbIuEOyKe/HYso4TlZKF5MHxOjrw9oQ3Usf3mZFOo5lt+J95pVtkW2C0Ng== X-Received: by 2002:a05:6808:190c:b0:32b:545a:5af2 with SMTP id bf12-20020a056808190c00b0032b545a5af2mr8040401oib.159.1653842942591; Sun, 29 May 2022 09:49:02 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6870:d583:b0:f2:fa89:6a9 with SMTP id u3-20020a056870d58300b000f2fa8906a9ls2254256oao.6.gmail; Sun, 29 May 2022 09:48:59 -0700 (PDT) X-Received: by 2002:a05:6870:b007:b0:f3:1f62:fff4 with SMTP id y7-20020a056870b00700b000f31f62fff4mr2549085oae.164.1653842939346; Sun, 29 May 2022 09:48:59 -0700 (PDT) In-Reply-To: X-Original-Sender: msprevak-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:30629 Archived-At: ------=_Part_2418_48753443.1653842938562 Content-Type: multipart/alternative; boundary="----=_Part_2419_1750097157.1653842938562" ------=_Part_2419_1750097157.1653842938562 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks for the replies, and the hints. I'll continue to experiment to see= =20 if I can build a table in lua. On Friday, May 27, 2022 at 11:43:11 AM UTC+1 BPJ wrote: > > > Den tors 26 maj 2022 12:53K4zuki skrev: > >> hint 1 - my note about Table structure (might be inaccurate w/ 2.18): >> https://gist.github.com/K4zuki/04e1e1af2fcf06db1a6ea640aa8feadd=20 >> > > Thanks for this! My own stab at this, which may be seriously outdated, is= =20 > here: > > https://groups.google.com/g/pandoc-discuss/c/XE9YdlJNamU/m/oWZapmV5CwAJ > > I was aiming at the JSON structure because my intention was to implement= =20 > support for complex tables in Perl JSON filters, which I still use from= =20 > time to time because Perl has real Unicode support! > > As for col/row spans: doesn't the HTML reader/writer support them yet? > > > hint 2 - my implementation in a filter ( >> https://github.com/pandocker/pandocker-lua-filters/blob/master/lua/csv2t= able.lua >> ): >> 1. prepare a minimum table markdown text as a local variable >> 2. let pandoc convert the text, then extract Table object >> ```lua >> local table_template =3D [=3D=3D[ >> | table | >> |-------| >> | cell | >> >> Table: caption >> ]=3D=3D] >> >> local my_table =3D pandoc.read(table_template, "markdown").blocks[1] >> ``` >> 3. clone the object and replace the contents >> > > Nice trick =E2=80=94 once you have grokked the structure. > > > >> 2022=E5=B9=B45=E6=9C=8826=E6=97=A5=E6=9C=A8=E6=9B=9C=E6=97=A5 18:06:06 U= TC+9 Bastien Dumont: >> >>> The constructors don't take tables as their argument, but discrete=20 >>> values. I have not found the definition of the constructors in the offi= cial=20 >>> documentation, but you can look into this filter to see how they work:= =20 >>> https://github.com/pandoc/lua-filters/blob/master/list-table/list-table= .lua=20 >>> >>> Le Thursday 26 May 2022 =C3=A0 01:53:39AM, msprev a =C3=A9crit :=20 >>> > This creates the following structure -- all ok, except the table body= ,=20 >>> which is=20 >>> > empty ('[]'), and I cannot get it to appear. Any suggestions on what= =20 >>> I'm doing=20 >>> > wrong would be gratefully received.=20 >>> >=20 >>> > ```=20 >>> > Table=20 >>> > ( "" , [] , [] )=20 >>> > (Caption Nothing [])=20 >>> > [ ( AlignLeft , ColWidthDefault )=20 >>> > , ( AlignDefault , ColWidthDefault )=20 >>> > ]=20 >>> > (TableHead ( "" , [] , [] ) [])=20 >>> > []=20 >>> > (TableFoot ( "" , [] , [] ) [])=20 >>> > ```=20 >>> > On Wednesday, May 25, 2022 at 12:48:06 PM UTC+1 msprev wrote:=20 >>> >=20 >>> > I've been struggling to get my head around handling tables with Lua i= n=20 >>> > pandoc 2.18. I'm trying to write a minimal working example to create = a=20 >>> > table as I can't seem to find one online. The code below does create = a=20 >>> > table, but with any empty table body and I can't figure out how to ge= t=20 >>> the=20 >>> > body to appear. Can anyone help tell me what has gone wrong here?=20 >>> >=20 >>> > BTW, I tried to call the pandoc.TableBody() constructor, but that=20 >>> throws an=20 >>> > error as it doesn't seem to be defined ("attempt to call a nil value= =20 >>> (field=20 >>> > 'TableBody')")=20 >>> >=20 >>> > ```=20 >>> > local caption =3D {long =3D {}}=20 >>> > local colspecs =3D {{pandoc.AlignLeft, pandoc.ColWidthDefault},=20 >>> > {pandoc.AlignDefault, pandoc.ColWidthDefault}}=20 >>> > local head =3D pandoc.TableHead()=20 >>> > local cell1contents =3D { pandoc.Plain({pandoc.Str("cell1")}) }=20 >>> > local cell2contents =3D { pandoc.Plain({pandoc.Str("cell2")}) }=20 >>> > local cell1 =3D { alignment=3Dpandoc.AlignDefault, contents=3Dcell1co= ntents,=20 >>> > col_span=3D1, row_span=3D1 }=20 >>> > local cell2 =3D { alignment=3Dpandoc.AlignDefault, contents=3Dcell2co= ntents,=20 >>> > col_span=3D1, row_span=3D1 }=20 >>> > local row1 =3D { cells=3D{pandoc.Cell(cell1), pandoc.Cell(cell2)} }= =20 >>> > local rows =3D { pandoc.Row(row1) }=20 >>> > local bodies =3D { body=3Drows, head=3D{}, row_head_columns=3D0 }=20 >>> > local foot =3D pandoc.TableFoot()=20 >>> > local mytable =3D pandoc.Table(caption, colspecs, head, bodies, foot)= =20 >>> > table.insert(doc.blocks, mytable)=20 >>> > ```=20 >>> >=20 >>> > --=20 >>> > You received this message because you are subscribed to the Google=20 >>> Groups=20 >>> > "pandoc-discuss" group.=20 >>> > To unsubscribe from this group and stop receiving emails from it, sen= d=20 >>> an email=20 >>> > to [1]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org=20 >>> > To view this discussion on the web visit [2] >>> https://groups.google.com/d/msgid/=20 >>> > pandoc-discuss/82a0d0eb-877a-47ff-8632-907322c40648n% >>> 40googlegroups.com.=20 >>> >=20 >>> > References:=20 >>> >=20 >>> > [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org=20 >>> > [2]=20 >>> https://groups.google.com/d/msgid/pandoc-discuss/82a0d0eb-877a-47ff-863= 2-907322c40648n%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter= =20 >>> >>> --=20 >> You received this message because you are subscribed to the Google Group= s=20 >> "pandoc-discuss" group. >> > To unsubscribe from this group and stop receiving emails from it, send an= =20 >> email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit=20 >> https://groups.google.com/d/msgid/pandoc-discuss/8094d69c-8374-4662-9c5c= -c099e14b19b2n%40googlegroups.com=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/e812ee52-ecc7-42ae-a8a7-2ed0a01087f6n%40googlegroups.com. ------=_Part_2419_1750097157.1653842938562 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks for the replies, and the hints. I'll continue to experiment to see i= f I can build a table in lua.

On Friday, May 27, 2022 at 11:43:11 AM UTC+1 BP= J wrote:


Den tors 26 maj 2022 12:53K4zuki <k.yamamot...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
hint 1 - my note about Table structure (might be i= naccurate w/ 2.18):

Thanks for this! My own stab at this, whic= h may be seriously outdated, is here:

https://groups.= google.com/g/pandoc-discuss/c/XE9YdlJNamU/m/oWZapmV5CwAJ

I was aiming at the JSON structure= because my intention was to implement support for complex tables in Perl J= SON filters, which I still use from time to time because Perl has real Unic= ode support!

As for col/= row spans: doesn't the HTML reader/writer support them yet?
=


<= div dir=3D"auto">
= 1. prepare a minimum table markdown text as a local variable
2. = let pandoc convert the text, then extract Table object
```lua
local table_template =3D [=3D=3D[
| table |
|-------|
| cel= l |

Table: caption
]=3D=3D]

local my_table =3D pandoc.rea= d(table_template, "markdown").blocks[1]
```
3. clone the object and replace the contents

Ni= ce trick =E2=80=94 once you have grokked the structure.


<= div dir=3D"auto">

2022=E5=B9=B45=E6=9C=8826=E6=97=A5=E6=9C=A8=E6=9B= =9C=E6=97=A5 18:06:06 UTC+9 Bastien Dumont:
The constructors don't take tables as their argum= ent, but discrete values. I have not found the definition of the constructo= rs in the official documentation, but you can look into this filter to see = how they work: https://github.com/pandoc/lua-filters/blob/master/list-table/list-table.= lua

Le Thursday 26 May 2022 =C3=A0 01:53:39AM, msprev a =C3=A9crit :
> This creates the following structure -- all ok, except the table b= ody, which is
> empty ('[]'), and I cannot get it to appear. Any suggestio= ns on what I'm doing
> wrong would be gratefully received.
>=20
> ```
> Table
> ( "" , [] , [] )
> (Caption Nothing [])
> [ ( AlignLeft , ColWidthDefault )
> , ( AlignDefault , ColWidthDefault )
> ]
> (TableHead ( "" , [] , [] ) [])
> []
> (TableFoot ( "" , [] , [] ) [])
> ```
> On Wednesday, May 25, 2022 at 12:48:06 PM UTC+1 msprev wrote:
>=20
> I've been struggling to get my head around handling tables= with Lua in
> pandoc 2.18. I'm trying to write a minimal working example= to create a
> table as I can't seem to find one online. The code below d= oes create a
> table, but with any empty table body and I can't figure ou= t how to get the
> body to appear. Can anyone help tell me what has gone wrong he= re?
>=20
> BTW, I tried to call the pandoc.TableBody() constructor, but t= hat throws an
> error as it doesn't seem to be defined ("attempt to c= all a nil value (field
> 'TableBody')")
>=20
> ```
> local caption =3D {long =3D {}}
> local colspecs =3D {{pandoc.AlignLeft, pandoc.ColWidthDefault}= ,
> {pandoc.AlignDefault, pandoc.ColWidthDefault}}
> local head =3D pandoc.TableHead()
> local cell1contents =3D { pandoc.Plain({pandoc.Str("cell1= ")}) }
> local cell2contents =3D { pandoc.Plain({pandoc.Str("cell2= ")}) }
> local cell1 =3D { alignment=3Dpandoc.AlignDefault, contents=3D= cell1contents,
> col_span=3D1, row_span=3D1 }
> local cell2 =3D { alignment=3Dpandoc.AlignDefault, contents=3D= cell2contents,
> col_span=3D1, row_span=3D1 }
> local row1 =3D { cells=3D{pandoc.Cell(cell1), pandoc.Cell(cell= 2)} }
> local rows =3D { pandoc.Row(row1) }
> local bodies =3D { body=3Drows, head=3D{}, row_head_columns=3D= 0 }
> local foot =3D pandoc.TableFoot()
> local mytable =3D pandoc.Table(caption, colspecs, head, bodies= , foot)
> table.insert(doc.blocks, mytable)
> ```
>=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 email
> to [1]pandoc-discus...@googlegroups= .com.
> To view this discussion on the web visit [2]https://groups.google.com/d/msgid/
> pandoc-discuss/82a0d0eb-877a-47ff-8632-907322c40648n%40googlegroups.com.
>=20
> References:
>=20
> [1] mailto:pandoc-discus...@googleg= roups.com
> [2] htt= ps://groups.google.com/d/msgid/pandoc-discuss/82a0d0eb-877a-47ff-8632-90732= 2c40648n%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter

--
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 pandoc-discus= ...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/8= 094d69c-8374-4662-9c5c-c099e14b19b2n%40googlegroups.com.

--
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/e812ee52-ecc7-42ae-a8a7-2ed0a01087f6n%40googlegroups.= com.
------=_Part_2419_1750097157.1653842938562-- ------=_Part_2418_48753443.1653842938562--