* Pandoc filters to produces multiple document reading lines of a CSV @ 2022-10-13 10:36 Gianluca Carbone [not found] ` <9cf8d9c7-2789-4a28-b66e-d2c393880b3cn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 3+ messages in thread From: Gianluca Carbone @ 2022-10-13 10:36 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 1121 bytes --] Hello guys! I'm new with the tool, and I try to understand how filters works. I tried to install some community filters but any satisfy my needs. 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 ? Thank you so much for your help! -- 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/9cf8d9c7-2789-4a28-b66e-d2c393880b3cn%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 1534 bytes --] ^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <9cf8d9c7-2789-4a28-b66e-d2c393880b3cn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: Pandoc filters to produces multiple document reading lines of a CSV [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> 0 siblings, 1 reply; 3+ messages in thread From: Albert Krewinkel @ 2022-10-13 12:54 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw Hi Gianluca, Gianluca Carbone <gianlucarbone96-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 ^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <87fsfr3l71.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>]
* Re: Pandoc filters to produces multiple document reading lines of a CSV [not found] ` <87fsfr3l71.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> @ 2022-10-27 8:44 ` Gianluca Carbone 0 siblings, 0 replies; 3+ messages in thread From: Gianluca Carbone @ 2022-10-27 8:44 UTC (permalink / raw) To: pandoc-discuss [-- 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 --] ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-10-27 8:44 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-10-13 10:36 Pandoc filters to produces multiple document reading lines of a CSV 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 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).