Closed hcf-n closed 11 months ago
I've looked at bit more into nr. 2 and have realized that there is no semantic information to differentiate between header and body of a latex table. Or does anybody see a way to implement it?
Try this build file:
local domfilter = require "make4ht-domfilter"
local process = domfilter {
function(dom)
for _, tbl in ipairs(dom:query_selector("tgroup")) do
local tbody_pos
local tbody
for i, el in ipairs(tbl:get_children()) do
-- find position of tbody, so we can insert thead before it
if el:get_element_name() == "tbody" then
tbody_pos = i
tbody = el
break
end
end
if tbody then
-- add thead to the table
local thead = tbl:create_element("thead")
tbl:add_child_node(thead, tbody_pos)
local rows = tbody:query_selector("row")
if #rows > 1 then
-- copy first row to thead
local first_row = rows[1]:copy_node()
rows[1]:remove_node()
thead:add_child_node(first_row)
-- remove empty row at the end
local last_row = rows[#rows]
-- if there is only one child and no text, remove it
if #last_row:get_children() < 2 and last_row:get_text():gsub("%s", "") == "" then
last_row:remove_node()
end
end
end
end
return dom
end
}
Make:match("xml$", process)
It moves the first row to a new thead
element, and removes the last empty row.
Thanks, forgot to close the issue
I'm converting a document with a lot of tables to Docbook and have encountered a couple of issues.
MWE:
Resulting XML
There seems to be an extra row at the bottom
The headers seem to be wrapped in
<tbody>
instead of<thead>
Thank you for making make4ht!