diff --git a/NEWS.md b/NEWS.md index a0bef17..a1b9371 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # ftExtra 0.3.0.9999 * `as_paragraph_md` supports empty string, `""`, as an input (#68). +* `colformat_md` applies on actual content of flextable rather than input dataset (#72). * Improved support for the underline syntax in Pandoc's Markdown (#73). # ftExtra 0.3.0 diff --git a/R/colformat.R b/R/colformat.R index d96cf1e..3150c27 100644 --- a/R/colformat.R +++ b/R/colformat.R @@ -48,13 +48,15 @@ colformat_md <- function(x, } dataset <- x[[part]]$dataset - col <- names(tidyselect::eval_select(rlang::expr(c(!!.j)), dataset)) + content <- x[[part]][["content"]][["content"]][["data"]] + nm <- colnames(content) + col <- tidyselect::eval_select(rlang::expr(c(!!.j)), dataset[nm]) if (length(col) == 0) { return(x) } - texts <- unlist(dataset[col], use.names = FALSE) + texts <- purrr::map_chr(content[, col], paragraph2txt) # Must evaluate outside add_footnotes due to lazy evaluation of arguments ft <- flextable::compose(x, @@ -80,3 +82,14 @@ colformat_md <- function(x, where <- function(...) { tidyselect::vars_select_helpers$where(...) } + +paragraph2txt <- function(x) { + if (all(is.na(x$txt))) return(NA_character_) + + txt <- x[["txt"]] + img <- x[["img_data"]] + has_img <- !purrr::map_lgl(img, is.null) & !is.na(img) + txt[has_img] <- sprintf("![](%s)", img[has_img]) + + paste(txt[!is.na(txt)], collapse = "") +} diff --git a/docs/articles/format_columns.html b/docs/articles/format_columns.html index bc932f6..66857ab 100644 --- a/docs/articles/format_columns.html +++ b/docs/articles/format_columns.html @@ -126,7 +126,7 @@
Oxide |
Oxide |
SiO2 |
Al2O3 |
SiO2 |
Al2O3 |
grouped_iris %>% as_flextable(hide_grouplabel = TRUE)
Sepal.Length |
-Sepal.Width |
-Petal.Length |
-Petal.Width |
+Sepal.Length |
+Sepal.Width |
+Petal.Length |
+Petal.Width |
setosa | |||||||
setosa | |||||||
5.1 |
-3.5 |
-1.4 |
-0.2 |
+5.1 |
+3.5 |
+1.4 |
+0.2 |
4.9 |
-3.0 |
-1.4 |
-0.2 |
+4.9 |
+3.0 |
+1.4 |
+0.2 |
versicolor | |||||||
versicolor | |||||||
7.0 |
-3.2 |
-4.7 |
-1.4 |
+7.0 |
+3.2 |
+4.7 |
+1.4 |
6.4 |
-3.2 |
-4.5 |
-1.5 |
+6.4 |
+3.2 |
+4.5 |
+1.5 |
virginica | |||||||
virginica | |||||||
6.3 |
-3.3 |
-6.0 |
-2.5 |
+6.3 |
+3.3 |
+6.0 |
+2.5 |
5.8 |
-2.7 |
-5.1 |
-1.9 |
+5.8 |
+2.7 |
+5.1 |
+1.9 |