How to style output in RStudio Markers tab

145 views Asked by At

The help of ?rstudioapi::sourceMarkers states:

Note that if the message field is of class "html" (i.e. inherits(message, "html") == TRUE) then its contents will be treated as HTML.

However, when running the following Code, the text is evaluated as is, not as html.

foo <- shiny::HTML('<div style="color:red;">I am red</div>')
bar <- shiny::HTML('<p style="color:red;">I am red</p>')
inherits(foo, "html")
#> [1] TRUE
inherits(bar, "html")
#> [1] TRUE

markers <- list(
  list(
    type = "error",
    file = getwd(),
    line = 145,
    column = 1,
    message = foo),
  list(
    type = "info", 
    file = getwd(),
    line = 145,
    column = 1,
    message = bar))

rstudioapi::sourceMarkers(name = "Test Name", markers)

enter image description here

EDIT

Was able to track down the issue and filed a bug report at rstudio

1

There are 1 answers

0
mnist On BEST ANSWER

As lon g as this bug is not solved within RStudio, it is easily possible to use a data frame instead of a nested list to achieve the html-evaluation:

bar <- '<p style="color:green;">I am green</p>'

markers <- data.frame(
    type = c("error", "info"),
    file = getwd(),
    line = 145:146,
    column = 1,
    message = c(foo, bar))

attr(markers$message, which = "class") <- c("html", "character")
inherits(markers$message, "html")
#> TRUE

rstudioapi::sourceMarkers(name = "Test Name", markers)

enter image description here