如何在 RStudio 标记选项卡中设置输出样式

How to style output in RStudio Markers tab

?rstudioapi::sourceMarkers 的帮助指出:

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

但是,当 运行 以下代码时,文本按原样计算,而不是 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)

编辑

能够找到问题并且 filed a bug report at rstudio

只要这个错误没有在 RStudio 中解决,就可以很容易地使用数据框而不是嵌套列表来实现 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)