Skip to content
Open
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: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

## Minor improvements and bug fixes

* Fixed duplicate text in Quarto output when `fmt_markdown()` cells contain a list without preceding text (#2140).

* Fixed LaTeX and RTF output for unformatted `Date` columns, which now show calendar dates instead of day counts since the Unix epoch (#2177). (@LeonidasZhak, #2180)

* Rows in LaTeX output tables no longer overlap when cell text contains line breaks (#2178). (#2179)
Expand Down
25 changes: 22 additions & 3 deletions R/quarto.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,31 @@ process_md_quarto <- function(text, md_engine_fn) {
)

# Tweak start and end of non_na_text
non_na_text <- paste0("<span data-qmd-base64=\"", non_na_text, "\">")
# Use block containers when Markdown contains block-level HTML; Quarto
# otherwise parses lists as inline content and duplicates their text.
block_tags <-
paste0(
"address|article|aside|blockquote|div|dl|fieldset|figure|footer|",
"h[1-6]|header|hr|main|nav|ol|p|pre|section|table|ul"
)

block_content <-
grepl(
paste0("<(", block_tags, ")([[:space:]>])"),
non_na_text_processed
)

container_tag <- ifelse(block_content, "div", "span")

non_na_text <-
paste0(
"<", container_tag, " data-qmd-base64=\"", non_na_text, "\">"
)

non_na_text <-
paste0(
non_na_text, "<span class='gt_from_md'>",
non_na_text_processed, "</span></span>"
non_na_text, "<", container_tag, " class='gt_from_md'>",
non_na_text_processed, "</", container_tag, "></", container_tag, ">"
)

text[nzchar(text, keepNA = FALSE)] <- non_na_text
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-fmt_markdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ There's a quick reference [here](https://commonmark.org/help/).
)
})

test_that("fmt_markdown() uses block containers when rendered by Quarto", {
withr::local_envvar(QUARTO_BIN_PATH = "quarto")

tab <-
tibble::tibble(
text = c("- bullet point 1\n- bullet point 2", "*inline text*")
) |>
gt() |>
fmt_markdown()

output <- (tab |> render_formats_test(context = "html"))[["text"]]

expect_match(output[[1]], "^<div data-qmd-base64=")
expect_match(output[[1]], "<div class='gt_from_md'>")
expect_match(output[[1]], "<li>bullet point 1</li>")
expect_match(output[[1]], "<li>bullet point 2</li>")
expect_match(output[[2]], "^<span data-qmd-base64=")
expect_match(output[[2]], "<span class='gt_from_md'>")
})

test_that("LaTeX formulas render correctly in HTML", {

gt_tbl <-
Expand Down
Loading