From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/30989 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Abhishek Ulayil Newsgroups: gmane.text.pandoc Subject: Re: Lua filter to modify captions in tables Date: Sat, 16 Jul 2022 06:19:29 -0700 (PDT) Message-ID: <83057d17-1bda-4ec8-a96f-9567f975033en@googlegroups.com> References: <0abadbc7-8cc9-4d67-92e2-fbd636f6cf3fn@googlegroups.com> <87a699dy1b.fsf@zeitkraut.de> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_2514_898933820.1657977569572" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31092"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBDQIR5HZ7MFBBYXVZKLAMGQETEG3IRQ-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sat Jul 16 15:19:34 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-yb1-f186.google.com ([209.85.219.186]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oChhm-0007xf-HE for gtp-pandoc-discuss@m.gmane-mx.org; Sat, 16 Jul 2022 15:19:34 +0200 Original-Received: by mail-yb1-f186.google.com with SMTP id u15-20020a25ab0f000000b0066e49f6c461sf5715617ybi.2 for ; Sat, 16 Jul 2022 06:19:34 -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=AoLIVBUnOixd+RmDmOYFI2L+9a/OTiGT9/wtsCHX164=; b=Vg9nlDiMFvSDWpFvpvTQGG8d4meWbzqiJ37F6Lu0PMKj9ZU7zWNKkYSP2GI950uWM7 lGfHk0Vgi0/crkQ5e9It7TJihPVCljCw/ZtiTeKZaT0D1KDYm+MTv4fBUx1rAn4FLeCY 2bb6o7NsDK3UYguK8VPFtKudTCgPS5Lm2eEKY1RQi3okoXMUGjv2QaE0xVEpIKAvcrKK 12OpyX7QXFbNKc8Df3njskqWc7JpVjEZdx29xdpdO56Yzsk0dlVGbu6/rqQlK7DPTdFz NjVtFh8wrx1mwc50Yvl3+0AjMI5r7CQrkMDSkN8h1zK/io6dR2bub7R/8TpM/voAcPle gN4g== 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=AoLIVBUnOixd+RmDmOYFI2L+9a/OTiGT9/wtsCHX164=; b=CsqfypIL3xCzMA8A03eskBNkXWGOt70l24F8lCj85hWNl19XI5DFsFPq91wjrJhH9F I2T7mBAJV15uPv0d3R4frLqPZp7ll90dlc8XVR8lnFdXttxTddtv6yOF8H+OoxVYacNC XLRHDU3jUbH/HCxEZ9KUAn9vr2kzgJTvb8hKOdp7kuTiZoygph1Z2Ko8/lS9S7WcswyG jrdwk1rHQQ0u0Z/WIIhm594PHHuu0GKRPFVVhvj3uX1BgTi3ni3ceh5U1QlV60wZtnJ+ zTUbiirs4W1b6LwlR/IW+MXyr8qkH8/RrAmcSn/qNeIUopSCSVZVhAqECzfrH0pt+4wm e5/Q== 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=AoLIVBUnOixd+RmDmOYFI2L+9a/OTiGT9/wtsCHX164=; b=vPlqQ+0qb4cU5T5taIaVCM1air0MfdofpBIPL791nidqFU+dk63LdAlPeVBwfDRsTU xvk8grDrY4FYYKOlBqE7xflI+sMTG4OgyA2DNl0oyH55mhqWtPR2GwaGoDUABDc73DFl T+Yk8sIl39N6lehew+wkH8fSMMb2evFM/qgZWAsvcbD0Z0sbafSS2WkEfhN49RkXpl9Z W3W97TqSEq00zZTR7B2lxUWaWqILY+48va5INagXu3h/9aRjVAS4uXqPKhIFsmE7Hn/p eC2SpTfEYxivvKyXm0mv4fqOL4Peu9NiibULnHgam96w2Myxd6dhEemmX4O7DNrW1RW0 35lA== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AJIora+GbXD47GkPgZ18UIBcw/evy4K3qU8k1NJsd3HzWlv7nAut2zyq QdRZVq1eP7rvoJx1twG1hUU= X-Google-Smtp-Source: AGRyM1soKTo9T3/bn9akuboLFFrPqpw6+gi25vfDtkCzp2rJ8hSVQP1GeLbMx8DawcX3FKW+l85oVA== X-Received: by 2002:a5b:849:0:b0:66e:a027:3c with SMTP id v9-20020a5b0849000000b0066ea027003cmr17719439ybq.208.1657977573464; Sat, 16 Jul 2022 06:19:33 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a25:37d8:0:b0:66f:5acc:d67f with SMTP id e207-20020a2537d8000000b0066f5accd67fls9055709yba.11.gmail; Sat, 16 Jul 2022 06:19:30 -0700 (PDT) X-Received: by 2002:a05:6902:244:b0:66f:8383:b51c with SMTP id k4-20020a056902024400b0066f8383b51cmr19074239ybs.471.1657977570246; Sat, 16 Jul 2022 06:19:30 -0700 (PDT) In-Reply-To: <87a699dy1b.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> X-Original-Sender: Abhiman2000-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:30989 Archived-At: ------=_Part_2514_898933820.1657977569572 Content-Type: multipart/alternative; boundary="----=_Part_2515_1480598052.1657977569572" ------=_Part_2515_1480598052.1657977569572 Content-Type: text/plain; charset="UTF-8" Thanks albert, The filter works as intended, with your permission may I include it in my github repo containing lua filters : https://github.com/Abhi-1U/tex-lua-filters On Saturday, 16 July 2022 at 18:17:53 UTC+5:30 Albert Krewinkel wrote: > > Abhishek Ulayil writes: > > > I was working on a lua filter to change the Table caption to add > > numbering > > > > ``` > > tables = 0 > > function Table(el) > > tables = tables + 1 > > local caption = "Table " .. tostring(tables) .. ": " .. > > pandoc.utils.stringify(el.caption) > > print(caption) > > > > el.caption = caption --facing problem here > > return el > > end > > ``` > > > > I am facing a problem to set the caption back to the element, > > > > what will be the correct way to set the caption. > > Captions consist of two parts, the normal (long) caption and a shorter > (short) description that can be used in a list of tables, for example. > The problematic line should be changed to > > el.caption.long = caption > > As you noticed, it's not very user-friendly though, and we should > definitely improve that. > > You'll probably want to keep the markup in the caption. I'm attaching a > version that's a bit longer, but will preserve the caption's markup. > > HTH! > > > ``` > tables = 0 > function Table(el) > tables = tables + 1 > local label = pandoc.Inlines("Table " .. tostring(tables)) > local caption = el.caption.long > if not caption[1] then > -- Table has no caption, just add the label > caption = pandoc.Blocks{label} > elseif caption[1].tag == 'Plain' or caption[1].tag == 'Para' then > -- Prepend label to paragraph > label:extend{pandoc.Str ':', pandoc.Space()} > caption[1].content = label .. caption[1].content > else > -- Add label as plain block element > label:extend{pandoc.Str ':', pandoc.Space()} > caption:insert(1, pandoc.Plain(label)) > end > > el.caption.long = caption > return el > end > ``` > -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/83057d17-1bda-4ec8-a96f-9567f975033en%40googlegroups.com. ------=_Part_2515_1480598052.1657977569572 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks albert,
 The filter works as intended, with your permission= may I include it in my github repo containing lua filters : https://g= ithub.com/Abhi-1U/tex-lua-filters

<= div dir=3D"auto" class=3D"gmail_attr">On Saturday, 16 July 2022 at 18:17:53= UTC+5:30 Albert Krewinkel wrote:

Abhishek Ulayil <abhim...= @gmail.com> writes:

> I was working on a lua filter to change the Table caption to add
> numbering
>
> ```
> tables =3D 0
> function Table(el)
> tables =3D tables + 1
> local caption =3D "Table " .. tostring(tables) .. &q= uot;: " ..
> pandoc.utils.stringify(el.caption)
> print(caption)
>
> el.caption =3D caption --facing problem here
> return el
> end
> ```
>
> I am facing a problem to set the caption back to the element,
>
> what will be the correct way to set the caption.

Captions consist of two parts, the normal (long) caption and a shorter
(short) description that can be used in a list of tables, for example.
The problematic line should be changed to

el.caption.long =3D caption

As you noticed, it's not very user-friendly though, and we should
definitely improve that.

You'll probably want to keep the markup in the caption. I'm att= aching a
version that's a bit longer, but will preserve the caption's ma= rkup.

HTH!


```
tables =3D 0
function Table(el)
tables =3D tables + 1
local label =3D pandoc.Inlines("Table " .. tostring(tables)= )
local caption =3D el.caption.long
if not caption[1] then
-- Table has no caption, just add the label
caption =3D pandoc.Blocks{label}
elseif caption[1].tag =3D=3D 'Plain' or caption[1].tag =3D=3D= 'Para' then
-- Prepend label to paragraph
label:extend{pandoc.Str ':', pandoc.Space()}
caption[1].content =3D label .. caption[1].content
else
-- Add label as plain block element
label:extend{pandoc.Str ':', pandoc.Space()}
caption:insert(1, pandoc.Plain(label))
end

el.caption.long =3D caption
return el
end
```

--
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/83057d17-1bda-4ec8-a96f-9567f975033en%40googlegroups.= com.
------=_Part_2515_1480598052.1657977569572-- ------=_Part_2514_898933820.1657977569572--