Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect Quarto and protect MathJax . #844

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: kableExtra
Type: Package
Title: Construct Complex Table with 'kable' and Pipe Syntax
Version: 1.4.0.4
Version: 1.4.0.5
Authors@R: c(
person('Hao', 'Zhu', email = '[email protected]', role = c('aut', 'cre'),
comment = c(ORCID = '0000-0002-3386-6076')),
Expand Down
14 changes: 14 additions & 0 deletions R/kbl.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ kbl <- function(x, format, digits = getOption("digits"),
table.envir = table.envir, ...
)
} else if (format == "html") {
if (inQuarto()) {
for (i in seq_len(ncol(x))) {
col <- x[, i]
if (is.character(col)) {
hasMath <- grep("\\$.*\\$", col)
if (length(hasMath)) {
if (escape)
warning("Should use `escape = FALSE` in Quarto with math")
col[hasMath] <- make_data_qmd(col[hasMath])
x[, i] <- col
}
}
}
}
out <- knitr::kable(
x = x, format = format, digits = digits,
row.names = row.names, col.names = col.names, align = align,
Expand Down
12 changes: 12 additions & 0 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,15 @@ md_table_parser <- function(md_table) {
toprule_regexp <- "(\\\\toprule(\\[[^]]*])?)"
midrule_regexp <- "(\\\\midrule(\\[[^]]*])?)"
bottomrule_regexp <- "(\\\\bottomrule(\\[[^]]*])?)"

# Detect if we are running in Quarto

inQuarto <- function()
!is.null(knitr::opts_knit$get("quarto.version"))

# Modify math so Quarto handles it properly
# Written by Christophe Dervieux in issue #746

make_data_qmd <- function(content) {
sprintf('<span data-qmd="%s">%s</span>', content, content)
}
7 changes: 6 additions & 1 deletion inst/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
kableExtra 1.4.0.4
kableExtra 1.4.0.5
--------------------------------------------------------------------------------

New Features:

* Now attempts to handle MathJax in Quarto documents.
This requires you to call `kbl(escape = FALSE)` (#746).

Bug Fixes:

* Fixed a bug in `collapse_rows()`, which failed on tables
Expand Down
Loading