From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/31661 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gianluca Carbone Newsgroups: gmane.text.pandoc Subject: Re: Pandoc filters to produces multiple document reading lines of a CSV Date: Thu, 27 Oct 2022 01:44:34 -0700 (PDT) Message-ID: <2d6fe142-fa0f-4a9f-8715-db21e93420bbn@googlegroups.com> References: <9cf8d9c7-2789-4a28-b66e-d2c393880b3cn@googlegroups.com> <87fsfr3l71.fsf@zeitkraut.de> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_8118_1409013764.1666860274707" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26623"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBDYLVBUDZEBBB5EJ5GNAMGQE42JSCXQ-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Thu Oct 27 10:44:40 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oa1-f59.google.com ([209.85.160.59]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1onyVD-0006mM-E2 for gtp-pandoc-discuss@m.gmane-mx.org; Thu, 27 Oct 2022 10:44:39 +0200 Original-Received: by mail-oa1-f59.google.com with SMTP id 586e51a60fabf-13b781f3394sf494893fac.8 for ; Thu, 27 Oct 2022 01:44:39 -0700 (PDT) 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-sender :mime-version:subject:references:in-reply-to:message-id:to:from:date :sender:from:to:cc:subject:date:message-id:reply-to; bh=OWjE9qFtIeUI0apVs776teShxMv1bRy3NwG8Gkq0RNo=; b=q2af31cn9ThLTeAC/xMY5m036B5f0UnPQd2x2+5aJO54uPX5iZjyFni0P34lO/gCAR 1nk+8+5Ot7RMt3NgWNLBlBL5jtR4VGSWAeNoyMJ73bdkkB2i6+aa93WWb/eLinDCYehG hhxI8CzjZqSgkeyx25KDU+ycQUKCxiXMX6YKPFLYemx9yuqsy8h+Zfdx0QeywKuYyGaO QfwF05U3fjCxuiR4dBsIjAnB8wjgPSivoYjw96fuCOWwFsK040em9t+KSQTm7bz2Yvs6 OQIwwpxRHHrvg7HddSamJ12YXbHV+wSYHNrrBK5s6tVAnyUrCPzPhIO9kGMiJn8VNF5m nMPA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:x-original-sender :mime-version:subject:references:in-reply-to:message-id:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=OWjE9qFtIeUI0apVs776teShxMv1bRy3NwG8Gkq0RNo=; b=lWZOqFGszIGZG5T5lqDKu5ucVdSPzdf6EzyWY9sQBGZrhlHlJ46b1p+fMf2NpcRQWh 9lyCUAXthHwjif+8bcW2AUIisdHXHQJqC4XCJ28mbg5mCq8bW2JZ+NgPq6EiU8cJIV/N in2g/HIb0F2pJm2PfvKA9JQIbPlGJfa7vkhWz6w+dNUOAmoTfZAgzus60QF7H4VtjNdJ mOAgp9bP2s9tzyRVPAdbR3/rXy2pw+74Fk0HgZB/NDbKMDM4mvseqsKoQgeoOzCiVIga UIuj3EraUzK4b/3ZTUqwL5BPO9zC+Gr3qkjaxKNaCxjHlapLhSNYG/t2yCUmwolbPkvL Y3EQ== 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-sender:mime-version:subject:references:in-reply-to :message-id:to:from:date:x-gm-message-state:sender:from:to:cc :subject:date:message-id:reply-to; bh=OWjE9qFtIeUI0apVs776teShxMv1bRy3NwG8Gkq0RNo=; b=dGIJgsGq6Qdk4fZ9tcXtLzG7Ve3lOdW0Jxo5+IaCJMuOvnqiq0WUq5lllwdESrLMXG JE4T0d75ZMr95CDORpxbFfzVETcKH57XG/TBHv5KR2YcelpgIu6lk+v2nR6uAzfQ84jt 1iatiGUDWG9go+Z4XIezfoWsUmq3Ev6N/2J6OH2LoGUBnhvZJStqeDlZxO4roR4EpIWi dICuyVtr/oHCGXA1slKXdITu01Lp4CIzL0qfJvXYPBzqHh2zEzmnPhQT3s0VVUdjsBbi fmJDuccUx8FYn+2iiLzQ26hjQYaelswZnk1ffYUun3st7l7f6b14TXgMhPULxNRH6zKe id9Q== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: ACrzQf3HLARlHtU2Z8BlTTJhugjJeUicO6gviub+tX0goBPH20bpPXfT Qz9rVS6aut26/SZ2MOvmVy4= X-Google-Smtp-Source: AMsMyM6DHhV2dXpH2FlJqR61VZ0PGWLOt4wBkcZnC1oTPBFORvK7bo3D7qUxEiOHGe/Ld/TkFTKWCQ== X-Received: by 2002:a4a:9b0e:0:b0:478:1e84:a130 with SMTP id a14-20020a4a9b0e000000b004781e84a130mr20580786ook.23.1666860278272; Thu, 27 Oct 2022 01:44:38 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6870:7716:b0:13b:6766:edd8 with SMTP id dw22-20020a056870771600b0013b6766edd8ls4742249oab.3.-pod-prod-gmail; Thu, 27 Oct 2022 01:44:35 -0700 (PDT) X-Received: by 2002:a05:6870:5692:b0:13b:7c99:10f3 with SMTP id p18-20020a056870569200b0013b7c9910f3mr5100259oao.80.1666860275427; Thu, 27 Oct 2022 01:44:35 -0700 (PDT) In-Reply-To: <87fsfr3l71.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> X-Original-Sender: gianlucarbone96-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:31661 Archived-At: ------=_Part_8118_1409013764.1666860274707 Content-Type: multipart/alternative; boundary="----=_Part_8119_1170874265.1666860274707" ------=_Part_8119_1170874265.1666860274707 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thank you so much for your help! It solve very well my problem! Il giorno gioved=C3=AC 13 ottobre 2022 alle 15:30:36 UTC+2 Albert Krewinkel= ha=20 scritto: > 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 =3D pandoc.utils.stringify > > function Writer (doc, opts) > assert(doc.blocks[1] and doc.blocks[1].t =3D=3D 'Table', 'expected table'= ) > -- table does not have colspans, footer, etc. Convert to simple table > local tbl =3D pandoc.utils.to_simple_table(doc.blocks[1]) > local result =3D pandoc.List{} > for _, row in ipairs(tbl.rows) do > local meta =3D pandoc.Meta(doc.meta) -- clone > for i, cell in ipairs(tbl.header) do > meta[stringify(cell)] =3D row[i] > end > local rowdoc =3D 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=3Dmeta-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 > > --=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/2d6fe142-fa0f-4a9f-8715-db21e93420bbn%40googlegroups.com. ------=_Part_8119_1170874265.1666860274707 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thank you so much for your help! It solve very well my problem!

Il giorno gio= ved=C3=AC 13 ottobre 2022 alle 15:30:36 UTC+2 Albert Krewinkel ha scritto:<= br/>
Hi Gianluca,

Gianluca Carbone <gianluc= ...@gmail.com> 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 =3D pandoc.utils.stringify

function Writer (doc, opts)
assert(doc.blocks[1] and doc.blocks[1].t =3D=3D 'Table', '= ;expected table')
-- table does not have colspans, footer, etc. Convert to simple table
local tbl =3D pandoc.utils.to_simple_table(doc.blocks[1])
local result =3D pandoc.List{}
for _, row in ipairs(tbl.rows) do
local meta =3D pandoc.Meta(doc.meta) -- clone
for i, cell in ipairs(tbl.header) do
meta[stringify(cell)] =3D row[i]
end
local rowdoc =3D 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=3Dmeta-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

--=20
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124

--
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/2d6fe142-fa0f-4a9f-8715-db21e93420bbn%40googlegroups.= com.
------=_Part_8119_1170874265.1666860274707-- ------=_Part_8118_1409013764.1666860274707--