public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: Gianluca Carbone <gianlucarbone96-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: Pandoc filters to produces multiple document reading lines of a CSV
Date: Thu, 27 Oct 2022 01:44:34 -0700 (PDT)	[thread overview]
Message-ID: <2d6fe142-fa0f-4a9f-8715-db21e93420bbn@googlegroups.com> (raw)
In-Reply-To: <87fsfr3l71.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>


[-- Attachment #1.1: Type: text/plain, Size: 2640 bytes --]

Thank you so much for your help! It solve very well my problem!

Il giorno giovedì 13 ottobre 2022 alle 15:30:36 UTC+2 Albert Krewinkel ha 
scritto:

> Hi Gianluca,
>
> Gianluca Carbone <gianluc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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
>

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

[-- Attachment #1.2: Type: text/html, Size: 3429 bytes --]

      parent reply	other threads:[~2022-10-27  8:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-13 10:36 Gianluca Carbone
     [not found] ` <9cf8d9c7-2789-4a28-b66e-d2c393880b3cn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-10-13 12:54   ` Albert Krewinkel
     [not found]     ` <87fsfr3l71.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2022-10-27  8:44       ` Gianluca Carbone [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2d6fe142-fa0f-4a9f-8715-db21e93420bbn@googlegroups.com \
    --to=gianlucarbone96-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).