Skip to content

Commit

Permalink
Allow vectorised style sets
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Apr 18, 2024
1 parent 9a9e8d5 commit e4c5ef2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion R/grob.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ marquee_grob <- function(text, style, x = 0, y = 1, width = NULL, default.units
sum(block) != 3 || any(nchar(parsed$text[block]) > 0, na.rm = TRUE)
}, logical(1))
## If not inline, the prior p tag inherits the image styling so you can center it or add padding
parsed[images$index[!images$inline] - 1, names(style[[1]])] <- parsed[images$index[!images$inline], names(style[[1]])]
parsed[images$index[!images$inline] - 1, names(style[[1]][[1]])] <- parsed[images$index[!images$inline], names(style[[1]][[1]])]
## Convert all "paths" to grobs
env <- caller_env()
images$grobs <- images_as_grobs(images$path, env)
Expand Down
6 changes: 4 additions & 2 deletions R/parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@
#'
marquee_parse <- function(text, style) {
check_character(text)
if (!is_style_set(style)) {
stop_input_type(style, "a marquee style set")
if (is_style_set(style)) style <- list(style)
if (any(!vapply(style, is_style_set, logical(1)))) {
cli::cli_abort("{.arg style} must be a style set or a list of style sets")
}
style <- rep_len(style, length(text))
parsed <- marquee_c(text, style)
# Remove terminal line end from code blocks
parsed$text[parsed$type == "cb"] <- sub("\n$", "", parsed$text[parsed$type == "cb"])
Expand Down
3 changes: 2 additions & 1 deletion src/marquee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ static int text_callback(MD_TEXTTYPE type, const MD_CHAR* text, MD_SIZE size, vo

[[cpp11::register]]
cpp11::writable::list marquee_c(cpp11::strings text, cpp11::list_of<cpp11::list> styles) {
MARQUEE_DATA userdata(styles);
MARQUEE_DATA userdata(styles[0]);

MD_PARSER marquee_parser = {
0,
Expand All @@ -381,6 +381,7 @@ cpp11::writable::list marquee_c(cpp11::strings text, cpp11::list_of<cpp11::list>
for (R_xlen_t i = 0; i < text.size(); ++i) {
userdata.current_id = i + 1;
userdata.style_stack = std::stack<cpp11::list>();
if (i != 0) userdata.defined_styles = create_style_map(styles[i]);

std::string str(text[i]);

Expand Down

0 comments on commit e4c5ef2

Please sign in to comment.