Liripo htmltools::browsable(tags$h1("a")) htmltools::browsable貌似就加了个browsable_html的属性,也不是加个class调用S3方法,怎么就可以在Rstudio的viewer里面输出了? function (x, value = TRUE) { attr(x, "browsable_html") <- if (isTRUE(value)) TRUE else NULL return(x) }
nan.xiao 首先这个 object 的 class 是 html, 所以在打印时会被 print.html() 方法捕获,在其中会判断 is.browsable() 即是否含有 browsable 属性,如果有,则调用 html_print() 来启动 viewer = getOption("viewer", utils::browseURL) 显示,而默认的 utils::browseURL 启动浏览器这个动作会被 RStudio 监听和劫持。