Files
business-suite/bin/html.lua
T

26 lines
1.2 KiB
Lua
Raw Normal View History

-- Copyright (c) 2026 Marc Wäckerlin. SPDX-License-Identifier: MIT
-- HTML structures that GitHub renders and the LaTeX writer otherwise drops.
-- A raw HTML table remains one table in the Markdown source, including merged
-- cells. Reading that block as HTML gives pandoc a native Table with row and
-- column spans, which every output writer can then render.
function RawBlock(block)
if block.format ~= 'html' or not block.text:match('^%s*<table[%s>]') then
return nil
end
-- The reader runs in an empty sandbox: an `<iframe>` or a picture in the
-- table would otherwise make the build open its address and paste what came
-- back into the PDF.
return pandoc.read(block.text, 'html', nil, {}).blocks
end
-- An empty anchor inside a Markdown table is a stable destination in the web
-- rendering. In LaTeX raw HTML is omitted, so turn it into the equivalent
-- native Span and let pandoc write the label.
function RawInline(inline)
if inline.format ~= 'html' then return nil end
local id = inline.text:match('^%s*<a%s+id=["\']([^"\']+)["\']%s*>%s*$')
if id then return pandoc.Span({}, pandoc.Attr(id)) end
if inline.text:match('^%s*</a>%s*$') then return {} end
return nil
end