Files
MeanField/reports/pandoc_tables.lua

29 lines
1.1 KiB
Lua
Raw Permalink Normal View History

-- LaTeX longtables repeat their heading on a new PDF page. Pandoc also exposes
-- that repeated heading as the first body row; Markdown needs it only once.
local function row_signature(row)
local cells = {}
for _, cell in ipairs(row.cells) do
cells[#cells + 1] = pandoc.write(pandoc.Pandoc(cell.contents), 'native')
end
return table.concat(cells, '\n--cell--\n')
end
function Table(value)
if #value.head.rows ~= 1 or #value.bodies == 0 then return value end
local rows = value.bodies[1].body
if #rows > 0 and row_signature(rows[1]) == row_signature(value.head.rows[1]) then
table.remove(rows, 1)
end
return value
end
-- GFM headings cannot carry LaTeX's explicit section labels. Preserve those
-- anchors so Pandoc's generated contents links still resolve in the Markdown.
function Header(value)
if value.identifier:find(':', 1, true) then
local id = value.identifier:gsub('&', '&amp;'):gsub('"', '&quot;'):gsub('<', '&lt;'):gsub('>', '&gt;')
return {pandoc.RawBlock('html', '<a id="' .. id .. '"></a>'), value}
end
return value
end