Skip to content

Commit 83bb6bd

Browse files
committed
add back odd, even, header classes from older pandoc in normalize processing
1 parent c70aa1f commit 83bb6bd

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/resources/filters/main.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import("./quarto-finalize/typst.lua")
9898

9999
import("./normalize/flags.lua")
100100
import("./normalize/normalize.lua")
101+
import("./normalize/pandoc-tables.lua")
101102
import("./normalize/parsehtml.lua")
102103
import("./normalize/extractquartodom.lua")
103104
import("./normalize/astpipeline.lua")

src/resources/filters/normalize/astpipeline.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ function quarto_ast_pipeline()
2222
}
2323
end
2424
return {
25+
-- identify pandoc table
26+
{ name = "normalize-pandoc-table", filter = pandoc_tables() },
27+
2528
{ name = "normalize-table-merge-raw-html", filter = table_merge_raw_html() },
2629

2730
-- this filter can't be combined with others because it's top-down processing.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- pandoc-tables.lua
2+
-- Copyright (C) 2024 Posit Software, PBC
3+
4+
-- Add back classes 'odd', (or 'header' in table header) / 'even' to table rows
5+
-- They were removed in pandoc 3.2.1 but are useful for styling pandoc processed tables
6+
-- Quarto detects .odd class
7+
function pandoc_tables()
8+
local function add_odd_even (rows, odd)
9+
odd = odd or 'odd'
10+
for rownum, row in ipairs(rows) do
11+
row.classes:insert((rownum % 2) == 0 and 'even' or odd)
12+
end
13+
return rows
14+
end
15+
16+
return {
17+
Table = function (tbl)
18+
add_odd_even(tbl.head.rows, 'header')
19+
for _, tblbody in ipairs(tbl.bodies) do
20+
add_odd_even(tblbody.body)
21+
end
22+
add_odd_even(tbl.foot.rows)
23+
return tbl
24+
end
25+
}
26+
end

0 commit comments

Comments
 (0)