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...@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 = 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-/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.