'Create structured document using pandoc from cvs file

I want to create a document with pandoc (or similar utility) using GitLabs CI/CD Pipeline, which takes a cvs file as input.

Every Column should be formatted as heading or paragraph. As example, the first column should be a heading (h1), the second column should be a paragraph, the third column should be a subheading (h2) and so on.

Is that possible, either with pandoc itself or with another step using Markdown, reStructuredText in combination with a shell script?



Solution 1:[1]

Pandoc's Lua subsystem is probably your best choice for this. The CSV can be parsed by pandoc and read into a table. That table can then be modified via a Lua filter.

function Table (full_table)
  -- our table won't have colspans, rowspans or the like, so
  -- we can use a "SimpleTable", which is much easier to use.
  local tbl = pandoc.utils.to_simple_table(full_table)
  
  local result = pandoc.Blocks()  -- The resulting block elements
  for i, row in ipairs(tbl.rows) do
    result:extend(row[1])         -- Adds the first cell to the result
                                  -- without modifications.

    -- Create an 'h1' heading from the contents of the second cell.
    result:insert(pandoc.Header(1, pandoc.utils.blocks_to_inlines(row[2])

    -- ... you get the idea
  end

  return result
end

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tarleb