diff --git a/R/block_articles.R b/R/block_articles.R index 2df94bae..5b0b98f0 100644 --- a/R/block_articles.R +++ b/R/block_articles.R @@ -5,8 +5,9 @@ #' a column of articles at lower screen widths). #' #' @param image An optional URL pointing to an image resource. -#' @param title An optional title for the article. -#' @param content An optional paragraph of text for the article. +#' @param title An optional title for the article. Markdown is supported. +#' @param content An optional paragraph of text for the article. Markdown is +#' supported. #' @param link An optional link to apply to the content elements. #' #' @examples @@ -19,7 +20,7 @@ #' title = "Hong Kong", #' content = #' "Once home to fishermen and farmers, \\ -#' modern Hong Kong is a teeming, \\ +#' modern _Hong Kong_ is a teeming, \\ #' commercially-vibrant metropolis where \\ #' Chinese and Western influences fuse.", #' link = "http://www.discoverhongkong.com" @@ -198,43 +199,63 @@ block_article_3 <- function(items) { ) } + paragraph <- "

" + x1_title <- glue::glue( article_title_template(), - title = items[[1]]$title, + title = + items[[1]]$title %>% + commonmark::markdown_html() %>% + tidy_gsub("

", paragraph), link = items[[1]]$link ) x2_title <- glue::glue( article_title_template(), - title = items[[2]]$title, + title = + items[[2]]$title %>% + commonmark::markdown_html() %>% + tidy_gsub("

", paragraph), link = items[[2]]$link ) x3_title <- glue::glue( article_title_template(), - title = items[[3]]$title, + title = + items[[3]]$title %>% + commonmark::markdown_html() %>% + tidy_gsub("

", paragraph), link = items[[3]]$link ) x1_content <- glue::glue( - article_content_template_2(), - content = items[[1]]$content + article_content_template(), + content = + items[[1]]$content %>% + commonmark::markdown_html() %>% + tidy_gsub("

", paragraph) ) x2_content <- glue::glue( - article_content_template_2(), - content = items[[2]]$content + article_content_template(), + content = + items[[2]]$content %>% + commonmark::markdown_html() %>% + tidy_gsub("

", paragraph) ) x3_content <- glue::glue( - article_content_template_2(), - content = items[[3]]$content + article_content_template(), + content = + items[[3]]$content %>% + commonmark::markdown_html() %>% + tidy_gsub("

", paragraph) ) block <- @@ -323,30 +344,44 @@ block_article_2 <- function(items) { ) } + paragraph <- "

" + x1_title <- glue::glue( article_title_template(), - title = items[[1]]$title, + title = + items[[1]]$title %>% + commonmark::markdown_html() %>% + tidy_gsub("

", paragraph), link = items[[1]]$link ) x2_title <- glue::glue( article_title_template(), - title = items[[2]]$title, + title = + items[[2]]$title %>% + commonmark::markdown_html() %>% + tidy_gsub("

", paragraph), link = items[[2]]$link ) x1_content <- glue::glue( - article_content_template_2(), - content = items[[1]]$content + article_content_template(), + content = + items[[1]]$content %>% + commonmark::markdown_html() %>% + tidy_gsub("

", paragraph) ) x2_content <- glue::glue( - article_content_template_2(), - content = items[[2]]$content + article_content_template(), + content = + items[[2]]$content %>% + commonmark::markdown_html() %>% + tidy_gsub("

", paragraph) ) block <- @@ -408,24 +443,36 @@ block_article_1 <- function(items) { link = items[[1]]$link) } + paragraph <- "

" + + x1_title <- + glue::glue( + article_title_template(), + title = + items[[1]]$title %>% + commonmark::markdown_html() %>% + tidy_gsub("

", paragraph), + link = items[[1]]$link + ) + x1_content <- glue::glue( - article_content_template_1(), - content = items[[1]]$content + article_content_template(), + content = + items[[1]]$content %>% + commonmark::markdown_html() %>% + tidy_gsub("

", paragraph) ) block <- glue::glue( " - - + @@ -464,9 +511,11 @@ article_image_template_2 <- function() { #' @noRd article_image_template_1 <- function() { -"

+"

+ + " } @@ -482,19 +531,9 @@ article_title_template <- function() { " } -#' A template for an article content HTML fragment (one across) -#' @noRd -article_content_template_1 <- function() { - -"

-{content} -

-" -} - -#' A template for an article content HTML fragment (two across) +#' A template for an article content HTML fragment #' @noRd -article_content_template_2 <- function() { +article_content_template <- function() { "
+ - - -
{x1_image} +{x1_title} {x1_content} -
\"image -

+
diff --git a/R/blocks.R b/R/blocks.R index 49ea682d..1f1790f1 100644 --- a/R/blocks.R +++ b/R/blocks.R @@ -40,7 +40,7 @@ blocks <- function(...) { # block of text to serve as a spacer if (inherits(x[[1]], "block_articles")) { - x <- prepend_list(x, block_text(" ")) + x <- prepend_list(x, list(block_text(" "))) } # Apply the `blocks` and `list` classes diff --git a/man/article.Rd b/man/article.Rd index 5d38460c..c04f49b6 100644 --- a/man/article.Rd +++ b/man/article.Rd @@ -9,9 +9,10 @@ article(image = NULL, title = NULL, content = NULL, link = NULL) \arguments{ \item{image}{An optional URL pointing to an image resource.} -\item{title}{An optional title for the article.} +\item{title}{An optional title for the article. Markdown is supported.} -\item{content}{An optional paragraph of text for the article.} +\item{content}{An optional paragraph of text for the article. Markdown is +supported.} \item{link}{An optional link to apply to the content elements.} } @@ -30,7 +31,7 @@ article <- title = "Hong Kong", content = "Once home to fishermen and farmers, \\\\ - modern Hong Kong is a teeming, \\\\ + modern _Hong Kong_ is a teeming, \\\\ commercially-vibrant metropolis where \\\\ Chinese and Western influences fuse.", link = "http://www.discoverhongkong.com" diff --git a/tests/testthat/test-blocks.R b/tests/testthat/test-blocks.R index b84e8586..82e569d0 100644 --- a/tests/testthat/test-blocks.R +++ b/tests/testthat/test-blocks.R @@ -153,6 +153,7 @@ test_that("blocks have the correct internal contents", { # Expect that any `blocks()` object will automatically # insert empty text to serve as a small spacer - expect_equal(blocks(block_articles(an_article))[[1]], " ") + expect_equal(blocks(block_articles(an_article))[[1]][[1]], " ") + expect_is(blocks(block_articles(an_article))[[1]], "block_text") expect_is(blocks(block_articles(an_article))[[2]], "block_articles") })