1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
Fix invalid html in longtable captions
https://puszcza.gnu.org.ua/bugs/?315
https://bugs.gentoo.org/963668
commit 771081cac0d63632e67730e530eb8937271a68d9
Author: Michal Hoftich <michal.h21@gmail.com>
Date: Wed Oct 1 14:56:02 2025 +0200
added tablecaption dom filter
--- /dev/null
+++ b/texmf-dist/scripts/make4ht/domfilters/make4ht-tablecaption.lua
@@ -0,0 +1,25 @@
+local function get_parent_table(caption)
+ -- recursively find the parent table of a caption element, as it can be inside <tr> and <td>
+ local parent = caption:get_parent()
+ if parent and parent:get_element_name() == "table" then
+ return parent
+ elseif parent then
+ return get_parent_table(parent)
+ else
+ return nil
+ end
+end
+
+return function(dom)
+ -- the caption element must be a first element in table, it cannot be contained inside tr
+ for _, caption in ipairs(dom:query_selector("table caption")) do
+ local table = get_parent_table(caption)
+ if table then
+ -- insert caption as the first child of table
+ table:add_child_node(caption:copy_node(),1)
+ -- remove the original caption
+ caption:remove_node()
+ end
+ end
+ return dom
+end
--- a/texmf-dist/scripts/make4ht/extensions/make4ht-ext-common_domfilters.lua
+++ b/texmf-dist/scripts/make4ht/extensions/make4ht-ext-common_domfilters.lua
@@ -26,7 +26,7 @@ function M.modify_build(make)
make:match("4om$", process, {charclasses= charclasses})
count = 2
else
- local process = filter({"fixinlines", "idcolons", "joincharacters", "mathmlfixes", "tablerows","booktabs", "sectionid", "itemparagraphs"}, "commondomfilters")
+ local process = filter({"fixinlines", "idcolons", "joincharacters", "tablecaption", "mathmlfixes", "tablerows","booktabs", "sectionid", "itemparagraphs"}, "commondomfilters")
make:match("html?$", process)
count = 1
end
|