From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32093 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Albert Krewinkel Newsgroups: gmane.text.pandoc Subject: Yet more fun with pandoc lua Date: Wed, 25 Jan 2023 22:18:10 +0100 Message-ID: <87tu0ejo7e.fsf@zeitkraut.de> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13097"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCZJF7XJTILRBOV7Y2PAMGQETSEKJ3Y-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed Jan 25 22:31:41 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-wm1-f63.google.com ([209.85.128.63]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pKnMr-0003Fr-EU for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 25 Jan 2023 22:31:41 +0100 Original-Received: by mail-wm1-f63.google.com with SMTP id bg24-20020a05600c3c9800b003db0ddddb6fsf11602821wmb.0 for ; Wed, 25 Jan 2023 13:31:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674682301; cv=pass; d=google.com; s=arc-20160816; b=BNwuUXgFCtIsYJYudp+tiBpqY2tbmPvjebX5+d+udOoGMb6L+WWruCRsITCvWGrQzS 0KJkI79jjsgj4j5yGg+7SyPAGpSIQstXEbGf49KnJBcsxTWtPlu8GmhdvFkfZZIE9/xr nXSurxw+6fPpGIXty9siWMnU6POWnfTCchJM+CIOMHHhOuyAcZbI29VbMv1hpQOnidqJ ydMECo2JD04nYLIqTwiTS+qLcFWv/r9zwCXKE75sv1nm42QQVVHbgsAWp4HTYCJ+GC39 AzFBc+R0tfWGj1wp53yivR25auNNYgOBcuotqFCq4gnbCdB4fDTvg8wmUEoFcGdGUUMM Nycg== 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:content-transfer-encoding :mime-version:message-id:date:subject:to:from:sender:dkim-signature; bh=AP9W7OrV1LBlnKDwh/cFQchFkFRukGBvMZVvmh/JkKQ=; b=oGC3BKZAtmo6yePE1tLxLogGvS5YrMny2EKlunA+Sblgh0EW9s8SLqnWCvRgCLljaM zuq0vEMSw9MG/HqYkpQsXq0piRZY/Ghep8p0foi6ySrIOwrtFfUMkoH2JtybTCRr1/v3 LmWiJdzNRC1Z/nVXYmKjQfUY8Ubk/4wuQ+yeprMK5tL3vopy7y5PDDMYjc+/wyRpR3wi RAqm1c57AgkQ486/i2JejC3GmyiBZioGUpOqy+YGIprUn+EBcLjTeqCK4c7wgiMqwOUQ FM8I9nCaaG5ocU68vspbD3tdhqhiLa65vpcB95oZUsgO+OAmsQ7oL3piR8Y4+v88IYqk apKg== 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.152 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=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender :content-transfer-encoding:mime-version:message-id:date:subject:to :from:sender:from:to:cc:subject:date:message-id:reply-to; bh=AP9W7OrV1LBlnKDwh/cFQchFkFRukGBvMZVvmh/JkKQ=; b=dFNs/rhE14wITnbuWYdXpKQRAIRRgBs1+s8cUhYRP0JEmXKucEW+xsi1t7mbDtaj8v H1kVxrpdVDVC60QbAJR2LTtEqmO7xxf+2ljdyQGc1C6OASGzFJD2isOfKnaoO0Q6kdNR V4buO7bA0fwQ2a2MXAdjsj6hnoGsY0K8CQby/sX7U9gbnJYGNkGIS0jk4bogZ/hLag3f fLfEtbu+oU6+pZLVL9ZmpYGyruUkE1QH066IchKrNp+oC+g83glgolOxtYNgq6vnnXGz DbvTXGyiBnRucHx604Qj06KShjPKBJs7Xkx+JkE0GI1KwLpTBaKgvVWWBf/ULy1WaPVi tVPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender :content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:sender:from:to:cc:subject:date:message-id :reply-to; bh=AP9W7OrV1LBlnKDwh/cFQchFkFRukGBvMZVvmh/JkKQ=; b=fRV1aDUCU6U5bL7fi1LbIngqe8Ekx3ik0ZFK4zVM7MpafNPN27p82pGWfnLoQj4EFh DRL1GEW8U7DvXMkCy3arfPxxNgn8vX1yICGH2Tw8Du1L/xJi7qUkrKblKyZ5clJq1Bmf 0qiaOks+qS0dokrt2ixCuQoJzx3u72k4uSUnFu6K7HwcVDOixVr0lJd/P3i+ilQKXZUT y/cfetakDCWyUE9FXda636N7FtRrtIsJOcUgyuF9VliUHxA8pe5KG0X2m4GeDMwN5Pr3 A6SOFe6U18ebTuGy2DNB+i4Uo1DdIZM+zlsegEi1qbb Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AO0yUKWxffK6TsQn7d7eE05Spq0AUS+bwZT+c5pd8xw/xb3VYRZJdqrA jRa6CoG2ssHUQ7SRVD5CdSA= X-Google-Smtp-Source: AK7set/OQf+tRZDbn4BvM6mzUpQ6Gz+rhZhV7U20sexJbi2uYAS5CbyfvnZs6ICg3lfqNRQmiZrleQ== X-Received: by 2002:a05:6000:16c3:b0:2bf:b571:1efd with SMTP id h3-20020a05600016c300b002bfb5711efdmr308554wrf.292.1674682301069; Wed, 25 Jan 2023 13:31:41 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:600c:5124:b0:3c6:c1ff:1fd with SMTP id o36-20020a05600c512400b003c6c1ff01fdls1842728wms.2.-pod-canary-gmail; Wed, 25 Jan 2023 13:31:37 -0800 (PST) X-Received: by 2002:a05:600c:34d0:b0:3db:2647:a012 with SMTP id d16-20020a05600c34d000b003db2647a012mr24444549wmq.40.1674682297196; Wed, 25 Jan 2023 13:31:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674682297; cv=none; d=google.com; s=arc-20160816; b=BoJGRK/Sd00IcYdiKSY+B+MyhqQRIC4HVw7AGOC+24PHj8eQK2lZu0TXlSJQHrcbVD Gl0v5l66qBdcgu0i1K3D//2kOjg3G+Q9sZMxiPbGt1KfxiQQ4wnkT46B4FKfKA69yj3E pf0wdOL0N4BmOQW1aEFgg/sjYQo9YVKTbwSTCAXmgoUxeAbksj3L5ZxQxTmmyyePz8On obAunU7FIB3GEDI2IsP6YsnaSuSJYgG2HxEM9a6/KuaCBQciIUDFcs3xK7/NvY41AdmQ F17UHB3HnGpwaNr54JDKF34xYyIJUeRepYkFhkY3Qe7hXU608pKraX8iSwCv2nk6DK5g YoQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from; bh=k58Z7vye7zJrBS27bK4q0APzB2bI/tkkZDpWIcUf9jI=; b=n1CvRXPsnyJIweRgjx4Pi7N9qUY4g5wVs/wxF0WzaDulM0nH77dU1zKBajAb10CSmn UP237beRm9tgeQsgyjtmpyZsI4WJDIL8UKziU6/68O9Pv1UMSF/2zOZzgDSD4txfRZZL ZQLzAHM/c13CL616MMeiJBXZA+9NUaCYZv/7PziuTR8dkD3iX56Vnshblt7TdJR2hGLv 8Mzb/bVp0Ff+4l6B6EhT9S6miWHgX0AOUDa70neCQri7iaN8RbgPDArWL19uZz6G6PDQ upJbx3hdU73rcP0i9PGWkt3oUKDAFTyaxRyWif6L6A3UDls6K+JDb4p7iFvU2vLgTe/F E5lw== 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.152 as permitted sender) smtp.mailfrom=albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org Original-Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org. [80.241.56.152]) by gmr-mx.google.com with ESMTPS id g17-20020a05600c4ed100b003c4ecff4e2bsi205862wmq.1.2023.01.25.13.31.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 13:31:37 -0800 (PST) Received-SPF: pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.152 as permitted sender) client-ip=80.241.56.152; Original-Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (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-102.mailbox.org (Postfix) with ESMTPS id 4P2H8k4m7Rz9sxl for ; Wed, 25 Jan 2023 22:31:34 +0100 (CET) X-Rspamd-Queue-Id: 4P2H8k4m7Rz9sxl 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.152 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:32093 Archived-At: #!/usr/bin/env -S pandoc lua -- This Lua script can be used as a very simple task manager. It allows -- to manage tasks in a plain Markdown file `panjour.md`. E.g., if this -- script is saved as file `panjour` and given executable permissions, -- then the following works: -- -- # Add two tasks to the file. -- ./panjour add Dabble with Lua -- ./panjour add Use some '*Markdown*' -- -- # List all tasks -- ./panjour list -- -- # Mark a task as DONE -- ./panjour done Dabble with Lua -- -- The code here is unpolished; the main goal was to try and write a -- full Lua program built on top of pandoc. local panjour_file =3D (os.getenv 'PANJOUR_FILE') or 'panjour.md' local format =3D 'markdown' warn '@on' local TaskManager =3D { done_marker =3D pandoc.Inlines{pandoc.Str '=E2=98=92', pandoc.Space()}, todo_marker =3D pandoc.Inlines{pandoc.Str '=E2=98=90', pandoc.Space()}, } function TaskManager:new(filename) local fh =3D io.open(filename, 'r+') if not doc then doc =3D pandoc.read(fh:read 'a', format) end local mgr =3D { document =3D doc, file_handle =3D fh, } setmetatable(mgr, self) self.__index =3D self return mgr end function TaskManager:add_task (task) local item =3D {pandoc.Plain(self.todo_marker .. task)} for i, blk in ipairs(self.document.blocks) do if blk.t =3D=3D 'BulletList' then blk.content:insert(item) goto done end end self.document.blocks:insert( pandoc.BulletList{item} ) ::done:: return self end function TaskManager:mark_task_as_done (task) local todo_item =3D pandoc.Blocks{pandoc.Plain(self.todo_marker..task)} local done_item =3D pandoc.Blocks{pandoc.Plain(self.done_marker..task)} local found =3D false self.document =3D self.document:walk { BulletList =3D function (ul) if not found then local li, idx =3D ul.content:find(todo_item) if idx then found =3D true ul.content[idx] =3D {pandoc.Plain(self.done_marker .. task)} elseif ul.content:find(done_item) then found =3D true warn('Item already marked as done!') end return ul end end } if not found then local msg =3D 'task not found: "%s"' error(msg:format(pandoc.utils.stringify(task))) end return self end function TaskManager:list () self:write_doc(io.stdout) end function TaskManager:write_doc (fh) local out =3D pandoc.write(self.document, format) fh =3D fh or self.file_handle fh:seek('set') fh:write(out) end function TaskManager:__gc() self.file_handle:close() end local action =3D arg[1] local task_args =3D pandoc.List{} for i=3D2, #arg do task_args:insert(arg[i]) end local task =3D pandoc.utils.blocks_to_inlines( pandoc.read(table.concat(task_args, ' '), format).blocks ) local task_manager =3D TaskManager:new(panjour_file) if action =3D=3D 'add' then task_manager:add_task(task) task_manager:write_doc() elseif action =3D=3D 'done' then task_manager:mark_task_as_done(task) task_manager:write_doc() elseif action =3D=3D 'list' then task_manager:list() else local msg =3D 'Unknown or missing action. Bailing out.\n' io.stderr:write(msg) os.exit(1) end --=20 Albert Krewinkel GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124 --=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/87tu0ejo7e.fsf%40zeitkraut.de.