Skip to content

Commit

Permalink
handle empty strings. closes #5.
Browse files Browse the repository at this point in the history
  • Loading branch information
clauswilke committed Feb 3, 2020
1 parent 351d539 commit 6746a9e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# gridtext devel

Nothing done yet.
- `richtext_grob()` and `textbox_grob()` now gracefully handle empty strings.

# gridtext 0.1.0

Expand Down
2 changes: 1 addition & 1 deletion R/richtext-grob.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ make_inner_box <- function(text, halign, valign, use_markdown, gp) {
if (use_markdown) {
text <- markdown::markdownToHTML(text = text, options = c("use_xhtml", "fragment_only"))
}
doctree <- read_html(text)
doctree <- read_html(paste0("<!DOCTYPE html>", text))

drawing_context <- setup_context(gp = gp, halign = halign, word_wrap = FALSE)
boxlist <- process_tags(xml2::as_list(doctree)$html$body, drawing_context)
Expand Down
2 changes: 1 addition & 1 deletion R/textbox-grob.R
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ textbox_grob <- function(text, x = NULL, y = NULL,
if (use_markdown) {
text <- markdown::markdownToHTML(text = text, options = c("use_xhtml", "fragment_only"))
}
doctree <- read_html(text)
doctree <- read_html(paste0("<!DOCTYPE html>", text))

# if width is set to NULL, we use the native size policy and turn off word wrap
if (is.null(width)) {
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-richtext-grob.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ test_that("grobheight and grobwidth work", {
expect_equal(h1, h2)
})

test_that("misc. tests", {
# empty strings work
expect_silent(richtext_grob(""))
expect_silent(richtext_grob(" "))
})

test_that("visual tests", {
draw_labels <- function() {
function() {
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-textbox-grob.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
context("textbox grob")

test_that("misc. tests", {
# empty strings work
expect_silent(textbox_grob(""))
expect_silent(textbox_grob(" "))
})

test_that("visual tests", {
draw_box <- function() {
function() {
Expand Down

0 comments on commit 6746a9e

Please sign in to comment.