-
Notifications
You must be signed in to change notification settings - Fork 213
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
Improve access to option values + use htmltools to create some css code #1868
Changes from 6 commits
e86b842
373bc8c
f708fbe
6f36168
7cb3805
43a714f
5e85e17
bfd0eb3
ca945b8
830fb90
b16093f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -71,25 +71,24 @@ footnote_mark_to_html <- function( | |||||
font_weight <- "normal" | ||||||
} | ||||||
|
||||||
paste0( | ||||||
"<span ", | ||||||
htmltools::tags$span( | ||||||
if (is_sup) { | ||||||
paste0("class=\"", sup_class, "\" ") | ||||||
htmltools::tags$sup(mark, .noWS = "before") | ||||||
} else { | ||||||
NULL | ||||||
mark | ||||||
}, | ||||||
"style=\"", | ||||||
"white-space:nowrap;", | ||||||
"font-style:", font_style, ";", | ||||||
"font-weight:", font_weight, ";", | ||||||
"line-height: 0;", | ||||||
"\">", | ||||||
if (is_sup) { | ||||||
paste0("<sup>", mark, "</sup>") | ||||||
class = if (is_sup) { | ||||||
sup_class | ||||||
} else { | ||||||
mark | ||||||
NULL | ||||||
}, | ||||||
"</span>" | ||||||
style = htmltools::css( | ||||||
`white-space` = "nowrap", | ||||||
`font-style` = font_style, | ||||||
`font-weight` = font_weight, | ||||||
`line-height` = 0 | ||||||
), | ||||||
.noWS = "before-end" | ||||||
) | ||||||
} | ||||||
|
||||||
|
@@ -237,45 +236,29 @@ coalesce_marks <- function( | |||||
locname, | ||||||
delimiter = "," | ||||||
) { | ||||||
filtered_tbl <- dplyr::filter(fn_tbl, locname == !!locname) | ||||||
dplyr::summarize(filtered_tbl, fs_id_c = paste(fs_id, collapse = delimiter)) | ||||||
fs_ids <- vctrs::vec_slice(fn_tbl$fs_id, fn_tbl$locname == locname) | ||||||
paste(fs_ids, collapse = delimiter) | ||||||
} | ||||||
|
||||||
# Get the attributes for the table tag | ||||||
get_table_defs <- function(data) { | ||||||
|
||||||
boxh <- dt_boxhead_get(data = data) | ||||||
|
||||||
# Get the `table-layout` value, which is set in `_options` | ||||||
table_style <- | ||||||
paste0( | ||||||
"table-layout: ", | ||||||
dt_options_get_value( | ||||||
data = data, | ||||||
option = "table_layout" | ||||||
), | ||||||
";" | ||||||
) | ||||||
|
||||||
# In the case that column widths are not set for any columns, | ||||||
# there should not be a `<colgroup>` tag requirement | ||||||
if (length(unlist(boxh$column_width)) < 1) { | ||||||
return(list(table_style = NULL, table_colgroups = NULL)) | ||||||
} | ||||||
|
||||||
# Get the `table-layout` value, which is set in `_options` | ||||||
table_layout <- dt_options_get_value(data = data, option = "table_layout") | ||||||
|
||||||
# Get the table's width (which or may not have been set) | ||||||
table_width <- | ||||||
dt_options_get_value( | ||||||
data = data, | ||||||
option = "table_width" | ||||||
) | ||||||
table_width <- dt_options_get_value(data = data, option = "table_width") | ||||||
|
||||||
# Determine whether the row group is placed in the stub | ||||||
row_group_as_column <- | ||||||
dt_options_get_value( | ||||||
data = data, | ||||||
option = "row_group_as_column" | ||||||
) | ||||||
row_group_as_column <- dt_options_get_value(data = data, option = "row_group_as_column") | ||||||
|
||||||
types <- c("default", "stub", if (row_group_as_column) "row_group" else NULL) | ||||||
|
||||||
|
@@ -309,14 +292,23 @@ get_table_defs <- function(data) { | |||||
if (table_width == "auto") { | ||||||
|
||||||
if (all(grepl("px", widths, fixed = TRUE))) { | ||||||
# FIXME sometimes ends up being 0? #1532 and quarto-dev/quarto-cli#8233 | ||||||
table_width <- "0px" | ||||||
} else if (all(grepl("%", widths, fixed = TRUE))) { | ||||||
table_width <- "100%" | ||||||
} | ||||||
} | ||||||
|
||||||
if (table_width != "auto") { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rich-iannone to fix #1532, should we just have this condition be
Suggested change
If so, I will create a PR after this one is merged and update all snapshots. I did the refactoring here to make the potential fix clearer in the future There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the version that catches the zero-width table! I’d welcome a future PR that addresses that problem. |
||||||
table_style <- paste(table_style, paste0("width: ", table_width), sep = "; ") | ||||||
table_style <- htmltools::css( | ||||||
`table-layout` = table_layout, | ||||||
width = table_width | ||||||
) | ||||||
} else { | ||||||
table_style <- | ||||||
htmltools::css( | ||||||
`table-layout` = table_layout | ||||||
) | ||||||
} | ||||||
|
||||||
# Create the `<colgroup>` tag | ||||||
|
@@ -415,7 +407,7 @@ create_heading_component_h <- function(data) { | |||||
footnote_title_marks <- | ||||||
footnote_mark_to_html( | ||||||
data = data, | ||||||
mark = footnote_title_marks$fs_id_c | ||||||
mark = footnote_title_marks | ||||||
) | ||||||
|
||||||
} else { | ||||||
|
@@ -449,7 +441,7 @@ create_heading_component_h <- function(data) { | |||||
footnote_subtitle_marks <- | ||||||
footnote_mark_to_html( | ||||||
data = data, | ||||||
mark = footnote_subtitle_marks$fs_id_c | ||||||
mark = footnote_subtitle_marks | ||||||
) | ||||||
|
||||||
} else { | ||||||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I refactored
coalesce_marks()
to return a single string because the resulting data frame (1 col x 1 row) previously was never used, and all code needed to access the fs_id_c variable. e86b842There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great improvement! Yeah, a vector is all we need.