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

apply colformat_md on content rather than dataset #72

Merged
merged 5 commits into from
Apr 19, 2022
Merged
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 15 additions & 2 deletions R/colformat.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = "")
}
318 changes: 159 additions & 159 deletions docs/articles/format_columns.html

Large diffs are not rendered by default.

424 changes: 212 additions & 212 deletions docs/articles/group-rows.html

Large diffs are not rendered by default.

202 changes: 101 additions & 101 deletions docs/articles/transform-headers.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/news/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ articles:
format_columns: format_columns.html
group-rows: group-rows.html
transform-headers: transform-headers.html
last_built: 2022-04-18T10:41Z
last_built: 2022-04-18T11:47Z

63 changes: 63 additions & 0 deletions docs/sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>/404.html</loc>
</url>
<url>
<loc>/LICENSE-text.html</loc>
</url>
<url>
<loc>/LICENSE.html</loc>
</url>
<url>
<loc>/articles/format_columns.html</loc>
</url>
<url>
<loc>/articles/group-rows.html</loc>
</url>
<url>
<loc>/articles/index.html</loc>
</url>
<url>
<loc>/articles/transform-headers.html</loc>
</url>
<url>
<loc>/authors.html</loc>
</url>
<url>
<loc>/format_columns.html</loc>
</url>
<url>
<loc>/index.html</loc>
</url>
<url>
<loc>/news/index.html</loc>
</url>
<url>
<loc>/reference/as_flextable_methods.html</loc>
</url>
<url>
<loc>/reference/as_paragraph_md.html</loc>
</url>
<url>
<loc>/reference/colformat_md.html</loc>
</url>
<url>
<loc>/reference/footnote_options.html</loc>
</url>
<url>
<loc>/reference/index.html</loc>
</url>
<url>
<loc>/reference/reexports.html</loc>
</url>
<url>
<loc>/reference/separate_header.html</loc>
</url>
<url>
<loc>/reference/span_header.html</loc>
</url>
<url>
<loc>/reference/with_blanks.html</loc>
</url>
</urlset>