Skip to content

Commit

Permalink
fix #2567: add classes odd, even, and header back to table rows…
Browse files Browse the repository at this point in the history
… for Pandoc >= 3.2.1

may also close #2566
  • Loading branch information
yihui committed Aug 9, 2024
1 parent a9497ff commit 0d8eabd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: rmarkdown
Title: Dynamic Documents for R
Version: 2.27.1
Version: 2.27.2
Authors@R: c(
person("JJ", "Allaire", , "[email protected]", role = "aut"),
person("Yihui", "Xie", , "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0645-5666")),
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
rmarkdown 2.28
================================================================================

- Add classes `odd`, `even`, and `header` back to table rows for Pandoc >= 3.2.1, so tables can be styled properly (thanks, @therealgenna, #2567).

- `beamer_presentation` support handling latex dependencies via the new `extra_dependencies` argument and declarations within chunks (e.g., `knitr::asis_output("", meta = list(rmarkdown::latex_dependency("longtable")))`) (thanks, @cderv, @atusy, #2478).


rmarkdown 2.27
================================================================================

Expand Down
5 changes: 4 additions & 1 deletion R/html_document_base.R
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ html_document_base <- function(theme = NULL,
knitr = NULL,
pandoc = pandoc_options(
to = "html", from = NULL, args = args,
lua_filters = pkg_file_lua(c("pagebreak.lua", "latex-div.lua"))
lua_filters = pkg_file_lua(c(
"pagebreak.lua", "latex-div.lua",
if (pandoc_available("3.2.1")) "table-classes.lua"
))
),
keep_md = FALSE,
clean_supporting = FALSE,
Expand Down
20 changes: 20 additions & 0 deletions inst/rmarkdown/lua/table-classes.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--[[
Add classes 'odd' (or 'header' in table header) / 'even' to table rows
]]

local function add_odd_even (rows, odd)
odd = odd or 'odd'
for rownum, row in ipairs(rows) do
row.classes:insert((rownum % 2) == 0 and 'even' or odd)
end
return rows
end

function Table (tbl)
add_odd_even(tbl.head.rows, 'header')
for _, tblbody in ipairs(tbl.bodies) do
add_odd_even(tblbody.body)
end
add_odd_even(tbl.foot.rows)
return tbl
end

0 comments on commit 0d8eabd

Please sign in to comment.