From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/30988 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Albert Krewinkel Newsgroups: gmane.text.pandoc Subject: Re: Lua filter to modify captions in tables Date: Sat, 16 Jul 2022 14:25:28 +0200 Message-ID: <87a699dy1b.fsf@zeitkraut.de> References: <0abadbc7-8cc9-4d67-92e2-fbd636f6cf3fn@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3605"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBCZJF7XJTILRB5PGZKLAMGQEFLO33XY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sat Jul 16 14:47:53 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-ed1-f57.google.com ([209.85.208.57]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oChD7-0000jE-It for gtp-pandoc-discuss@m.gmane-mx.org; Sat, 16 Jul 2022 14:47:53 +0200 Original-Received: by mail-ed1-f57.google.com with SMTP id c9-20020a05640227c900b0043ad14b1fa0sf5176625ede.1 for ; Sat, 16 Jul 2022 05:47:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657975673; cv=pass; d=google.com; s=arc-20160816; b=hh1+6Fgyj7u3NkkrYIcSU4mEZdUB8i42qxo/yWO6IqBPaS1uPnmbW6OLTxM5TOwe1Z AbWIPoT3dxiXfZd5G12UuWDnjWf5taUvnsI5yb6HxqHo1yFyTpiWrzmdd4ZASrxUcgHO W0vctljmm4vIEFoNJoSt8xa1a/xdc8kX5AOmytV0YKVgrNCve9XXOV0nRSe0mckvhPjU uymdeobWiGK4C1JP+RCBE0LnZJTaCpDOW2sZRqeHvKvbEiWYO+hE6rco5Eh3rBMOHH1T 9QLxRJAuInE9bvwKdnKKlWX2RBSJnNViXj1123t0PcBcP1prOdDwoe2wFu9fuSEdq45+ awhw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:mime-version:message-id :in-reply-to:date:subject:to:from:references:sender:dkim-signature; bh=x0I8FN6Yx6u+k7Fju+Mf9cvXZ2kvw5TiU1u+ny992WU=; b=wMYoR+uTjZW5+phh7ZH4v2/fPv++rysmbSBUfjmce5sHbqTr+u7oVF5389zSB2SpVO qPPNif8FDIrhmA3rXf4DfKUaP0oXoBFIgWne6mtPkL+R83RaJme+9eGcFZlXN+VlPuDO id8+T0tP5Am6AdZTHuMtHEgn2O02kMnAotDd4luK+EzZRfrRmDZvNSE004/EjXNZOkVg umfJwoCTLEij0YYn2RSpJg/1RgqVVNw3C6YoWcd9msqjWRKuRPWdGupj3N5wifLD3FBQ 6oRTrHnLUR+ydgrT/4g/A2Bfhm0SFnNUj+jPWgmjETbrT0y+JxBBqBw669nvXJ0Kvpvi 5ndA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.171 as permitted sender) smtp.mailfrom=albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:references:from:to:subject:date:in-reply-to:message-id :mime-version:x-original-sender:x-original-authentication-results :reply-to:precedence:mailing-list:list-id:list-post:list-help :list-archive:list-subscribe:list-unsubscribe; bh=x0I8FN6Yx6u+k7Fju+Mf9cvXZ2kvw5TiU1u+ny992WU=; b=fxNR58PmbAOUQ8nqn3f/CBuFnAyXrZ7QsMEAyKjjld53h7XJWcf8mc2D6a4ORZvp/e 7688qQEzU6YP3OUvpBXLteb6YHPEW3pEd388aklHr4mezjIRZdJgjruwhMhTR5U10Cly Auw4ZikDlnDcyTeH40eI4SX1srdpAgJF8tIs7mhS6FZjW2i+8PzGX7NWd1LuKzCYJXF3 DW3dH/OeK3B5WURg0zANGBUeogQYl/Hqqlq1XRCksWt42oHdlXtYmxl+h2cgehPWh9Hs x4wKjaWcrjf5JcTjjSGZo07yzhMJA4PjMddBNDsmUPRdfTomRhFpoXeSkRWjnwnCud1w WTBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:references:from:to:subject:date :in-reply-to:message-id:mime-version:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=x0I8FN6Yx6u+k7Fju+Mf9cvXZ2kvw5TiU1u+ny992WU=; b=j4T5i5HGsmIUUH/6H8q/679Xu8ZJ6e7XxWU+6l/utMArYTkoddVl2zQIiVDo9ms2So lYTiSvngYgN1TfO5HYgRkKv5KvQu3iitzH03ZknBmx6rQvDu40HdKO6hDXvS8WleCGxj 0qbxHSKhrP6jGloy3U+PmFaAttJ+MTYNGVbQoYGwk71iFSfvscUWGUn4AXIsXhZyKxpB oes29OT81eWklLI9gQcaWua7kouyaMnv1NuNanYCFCF306/Zzmy/Yxow4rSo6GVNX0nU nmPZGwqYJbxDnZ3lZF7KS2Km+S45oRQHsfo56xTfbnoIuonBDZKXzsd3M2bwkdX9E4f+ Oc0g== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AJIora/8XSfcVklsDAwHs2HgIphp0tDEjufXqTZfvAJx6R+5bswcUQLc kPVSQWD//tz+y3GM1IMPcAk= X-Google-Smtp-Source: AGRyM1tHojC7My+vw/Z1efeBweDOn7CHFVei23mGAfdASdlh+0CfBLgPrNlVET0Yl8w1ORmbHHGd+A== X-Received: by 2002:a17:906:93fa:b0:72b:146f:71b7 with SMTP id yl26-20020a17090693fa00b0072b146f71b7mr17810741ejb.413.1657975673183; Sat, 16 Jul 2022 05:47:53 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6402:5210:b0:43a:77a6:b0d with SMTP id s16-20020a056402521000b0043a77a60b0dls94784edd.3.-pod-prod-gmail; Sat, 16 Jul 2022 05:47:48 -0700 (PDT) X-Received: by 2002:a05:6402:241c:b0:43a:ec26:1ae5 with SMTP id t28-20020a056402241c00b0043aec261ae5mr26169355eda.189.1657975668826; Sat, 16 Jul 2022 05:47:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657975668; cv=none; d=google.com; s=arc-20160816; b=W7YQZN82CpIngeQphsJVkGrPp71iP34elAR8N86BCCm/4bOeN1qIURKfauhCbleq5g TMpNVazWgT8BALfkNn0cMZgODfFAKZyDsPcjh4/kw64lfSMylxvDN9AxuRpbZPhAX+0z /7Nkx1kIyFXcA60XbO8LakkFaT3XQn0OHwoqfRVOTCi1zYYhmA0xLI0gj2/X6tHcP9Pr Th/HZpFpDuICvid4ifn/TAe3+wWDvIhoA+Zz2xIKAC0no0kcCp7Am3ydxPOma8Gek/aB sHZv9ZHJjfBV7FhmYP0BFu/YdBMKGv8pYm9Q3ao8MlanC13zKVicAPSJESgGo9R6NsG6 Q/Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:message-id:in-reply-to:date:subject:to:from:references; bh=/ScX8SYbgSNg4SSsKx5QZ0Q1UGbtICUcpXK16ONEgqc=; b=Kpmo4jBKEpcjWqkTasQg6LNBpHwvxOd60C9uosRuTx/9UkvXspNYTZpqIt6jC3zXup +YN6GVXEBUa8D4AvKeq3COZRZ+qaxhRX3LUG7SGPFcFc1cY3Wc+pzD6/tvvqAHLY6aKD pyjGOu83bzjwmqroFkeVjc56yQNLPZopFk2rusKRTzlX4Dj0mNfgTjrbNTxEEO10NNVc 724L9nsj//+DEan+sGO+rvMrAcWviVYyFe1Qf0iw6cXowTU2xNbTNqtJr6DbpswlYwZt rUZ45rok5N9wv5ZWBNX43vZJttczDfGDrt14zkgbpSoQJEHYn+7ASnBU4gDod/T+aqY9 iOJg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.171 as permitted sender) smtp.mailfrom=albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org Original-Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org. [80.241.56.171]) by gmr-mx.google.com with ESMTPS id l6-20020a056402124600b0043a8ea6fc8dsi229453edw.4.2022.07.16.05.47.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jul 2022 05:47:48 -0700 (PDT) Received-SPF: pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.171 as permitted sender) client-ip=80.241.56.171; Original-Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4LlSgQ4xdJz9sT8 for ; Sat, 16 Jul 2022 14:47:46 +0200 (CEST) In-reply-to: <0abadbc7-8cc9-4d67-92e2-fbd636f6cf3fn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> X-Original-Sender: albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.171 as permitted sender) smtp.mailfrom=albert+pandoc-9EawChwDxG8hFhg+JK9F0w@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:30988 Archived-At: 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 ```