From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/31539 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Albert Krewinkel Newsgroups: gmane.text.pandoc Subject: Re: Pandoc filters to produces multiple document reading lines of a CSV Date: Thu, 13 Oct 2022 14:54:30 +0200 Message-ID: <87fsfr3l71.fsf@zeitkraut.de> References: <9cf8d9c7-2789-4a28-b66e-d2c393880b3cn@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="7823"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBCZJF7XJTILRB6FFUCNAMGQE2LHA4DY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Thu Oct 13 15:30:38 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-lf1-f56.google.com ([209.85.167.56]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oiyIG-0001lk-Oy for gtp-pandoc-discuss@m.gmane-mx.org; Thu, 13 Oct 2022 15:30:36 +0200 Original-Received: by mail-lf1-f56.google.com with SMTP id p36-20020a05651213a400b004779d806c13sf524460lfa.10 for ; Thu, 13 Oct 2022 06:30:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1665667836; cv=pass; d=google.com; s=arc-20160816; b=cUyawqw9qwyMl1L+V13qUnERGRqeSEGRZvKSlNRUcrpWqTP/fSeLVpUuKpKlqtnktf KHD6kuxWqNmZ25mJntqqij9IiSCp3OSuEDQenxlOnrDJBTLCGN2QFlXRb2ldDJPQRCri ErcTjBcOxjN23mWfsYPz8SAgf9U/ax6X5nn/8uKUIFQDXcZGkcVcXffh7YB5SrsdHEFO 9GCu8yKjU09fnHWbtwGL7RlfkdXJKefayPOPo38u5bTcQd3qFEIETd0Z4ICoc9+ADKlO RkEMA3TrmoUFs8MkYltbxjsRl8AgXiX6ruw7JV8uzHZmvh8gwvACqK/KHZ/GeZ2tXzn+ fqlQ== 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=O8F7mK+jtUstIqPZBCIxfyf6rrMIbg4AWMhgZ5jr1Oc=; b=xEfpcxPDIZqrT/16qFwcW6dNfCjwntZAldVT1Bto2pNaB+pt0UA5a10i3d559ziWQc bLtbi3na30cDrDn9lHr46l8FdcIpfcXP/R1Zn6HtRbY6e0p3X81+cKXbt2COYN+aJAhw ZLymZVLgZRK6HXTGfycW2vxT4PzxPra3urakzVtCkSuvY05sxzcFqHk5nSoaVD6hIEhu 6wTJ+bYhTy2dXd74nZx08rK8IMJwlcWH10T4y0ZCO5bL3n/jvYJPfwJI7udZVYvwjvgU hlE1oFZdhet2hoY4zKpxZ1xhMWVNX6cAz8Q9G/iBXzRyRZgTvaoqJHB0hNOMqY6w+QV5 /t0g== 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:mime-version :message-id:in-reply-to:date:subject:to:from:references:sender:from :to:cc:subject:date:message-id:reply-to; bh=O8F7mK+jtUstIqPZBCIxfyf6rrMIbg4AWMhgZ5jr1Oc=; b=UA87Vt2TI3MylFu0Z7kfdHlfPUnB2h94TtSUU18RQRRz+PROr1yKiTr2EVMuXSajtJ zgwpmO6CkUhFxshiAKnwsFnAdzys7NdUU9zsLn98KNHJOZG0hvRG5k24gouQIs2FUDJR PgBdbE0nv7tyHD2Pmt8Gzso/tITlKlXkzSL0f4T1a3/G1skAS/lVhhCnj6RHzQbHEbIF Eb/yp8ZlQRiCfRJhjo/gmiC1m4LxWrwLhXTqLprXmMPlzL4mG4sL0ZeyHZk3bDMG7D8x sdDZIRUPPLfSEl9antH5SUd2E1XuiSjb+suQl3JPSuTAuq9vAF1xnNCr13Fca6IfL47o e9Cw== 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:mime-version :message-id:in-reply-to:date:subject:to:from:references :x-gm-message-state:sender:from:to:cc:subject:date:message-id :reply-to; bh=O8F7mK+jtUstIqPZBCIxfyf6rrMIbg4AWMhgZ5jr1Oc=; b=VClctSmY5vDA5d7eWFrB5YUStZeqL8S32eQvapyFKXeQUlhx9TWD6kjU9z33pW50Jy 0J3D6FeeK+O6WWTo/EpvyT68m6yuyznSa4DvqRw0u8WCDejiNScUNxh4qDzWfd5cRafN wKpYMLvz+H3Eqs+y7S21Y6PxQZSnyThUBtcwDPD9J9tUBX33XOivFRaKvmSVg2e7YDVp 6Od8KegeOVkuzRum3lpI1FvkOqw/1q7ZsDv+dZIuJ9A6uFJqYzVpbEyUVOexfHYw5Fii 7cmFujAv6qNP7QUGqVe0SpsA80wkyM5zMIahMx1/pucs+e Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: ACrzQf2cF72hfLSQVuS6CNemn1kagDojPD8ImbSaiajumrJfBU7gW/U7 78BP1XrNfWtB1nCqjbE8nM8= X-Google-Smtp-Source: AMsMyM4rFWixf62ZNtprlehdes0xOnW1IE4iaOX+vpPJkz5EGiaKok75t4xEPKioL5LgtBwUXk+FVw== X-Received: by 2002:a2e:9d87:0:b0:26f:b92f:f798 with SMTP id c7-20020a2e9d87000000b0026fb92ff798mr4715039ljj.444.1665667836192; Thu, 13 Oct 2022 06:30:36 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6512:202e:b0:49a:b814:856d with SMTP id s14-20020a056512202e00b0049ab814856dls539900lfs.1.-pod-prod-gmail; Thu, 13 Oct 2022 06:30:31 -0700 (PDT) X-Received: by 2002:a05:6512:3241:b0:4a2:4f95:c02e with SMTP id c1-20020a056512324100b004a24f95c02emr11389832lfr.23.1665667831015; Thu, 13 Oct 2022 06:30:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665667831; cv=none; d=google.com; s=arc-20160816; b=jEbxxnUDLIPUYFMXrSW8/k9cqBhyIUDNQJjOjEQY2Gd5+Dte81bVvUXuZO+oIlB2Rv Ese9f+lJu4GhR9LlzIwOzEmTb3Y+rxle6CW07ih5bb1kzifgkWWqlvZnJbJx5QbiCz9R i/l7yG6h40NXJArPfv594P+xKSmmnYJ6FjpZEb6+QPm8Pb+tNhDyJ5sg5hdN29hWBkcU OWsVnKsoh6zFD5xL2JT77IFamgrkmg2QgErMsM0+tdewcUYuhxuLIwlQG2UWZaCxIqmi wUpmHnobLhbG//PcPPiKF0/gneV9olqgYAnr0iPawLinMscLWMArC+aGAs3CwehAEBQD gLBg== 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=7CB23xmpbhWOwdL0hA+7rCL7U6zBSP5PBFMiwzwcwmQ=; b=t2XtCqbPbGDlY7sGxTeCjBMnui52ogYm4ySKIu3/RW37A/d6ZzScIV7kxPFqGWhS9U tzH28v6JDXoLtJeFodIZcjUEhhLsIo0KzNqg69enwjF98BKKN7dWBzMMQdiIYqeDoXCn 0PVLKIXUJ0V3/JEBG5jAyKrP1OEfTjO41WULePC64uh6BRJhUrBb7+GmdpGiifKs499r 4xe7FC/ScmPUyEQV6XgtofUzTzzEutn7A1R5fWG5r7w9+T9hDiTmHO/wVLgWIdiKa342 h/ATdkiDnw4iLJBRPbsSKNHWCI5bqy+6uc4s46EElULsAj+SasYG4poCJeCV/H1obSj0 G2Ag== 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 q15-20020a2eb4af000000b0026e8558c6ddsi372624ljm.3.2022.10.13.06.30.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 06:30:30 -0700 (PDT) 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 smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (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 4Mp9Pc3n4Mz9sZG for ; Thu, 13 Oct 2022 15:30:28 +0200 (CEST) In-reply-to: <9cf8d9c7-2789-4a28-b66e-d2c393880b3cn-/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.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:31539 Archived-At: Hi Gianluca, Gianluca Carbone writes: > I want to obtain multiple documents in output (markdown documents) > which uses a specifc template already defined and working by me. > > The input file, must be a CSV file with an header for example: > // CSV file \\ > name, surname, date, location > Josh, White, 2022-10-12, Rome > Kate, Brown, 2021-09-30, London > > I want in output in this case 2 documents: > > 1. One with content filled by the values of first record of CSV > 2. One with content filled by the values of the second record of CSV > > How can I do something like this ? Not sure I understand this correctly, but I assume you have a template that contains things like ${name} ${surname}, born ${date} in ${location} and you'd like to use that with a CSV table, using the header label as variable name? If that's correct, then the following custom writer should help: ``` lua local stringify = pandoc.utils.stringify function Writer (doc, opts) assert(doc.blocks[1] and doc.blocks[1].t == 'Table', 'expected table') -- table does not have colspans, footer, etc. Convert to simple table local tbl = pandoc.utils.to_simple_table(doc.blocks[1]) local result = pandoc.List{} for _, row in ipairs(tbl.rows) do local meta = pandoc.Meta(doc.meta) -- clone for i, cell in ipairs(tbl.header) do meta[stringify(cell)] = row[i] end local rowdoc = pandoc.Pandoc({}, meta) result:insert(pandoc.write(rowdoc, 'markdown', opts)) end return table.concat(result, '\f') end ``` Save the code to a file `meta-from-table.lua` and call pandoc with pandoc --to=meta-from-table.lua ... where `...` are your other options, including the template. The output is built from all rows, with a line separator character between each record. Hope that helps, Albert -- Albert Krewinkel GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124