diff --git a/R/grob.R b/R/grob.R index e3c014f..cf2ff70 100644 --- a/R/grob.R +++ b/R/grob.R @@ -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) diff --git a/R/parse.R b/R/parse.R index ecd7b02..c26abc2 100644 --- a/R/parse.R +++ b/R/parse.R @@ -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"]) diff --git a/src/marquee.cpp b/src/marquee.cpp index 962fff0..0a2356a 100644 --- a/src/marquee.cpp +++ b/src/marquee.cpp @@ -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 styles) { - MARQUEE_DATA userdata(styles); + MARQUEE_DATA userdata(styles[0]); MD_PARSER marquee_parser = { 0, @@ -381,6 +381,7 @@ cpp11::writable::list marquee_c(cpp11::strings text, cpp11::list_of for (R_xlen_t i = 0; i < text.size(); ++i) { userdata.current_id = i + 1; userdata.style_stack = std::stack(); + if (i != 0) userdata.defined_styles = create_style_map(styles[i]); std::string str(text[i]);