【问题标题】:How to use tags with special characters in htmltools inside rmarkdown document?如何在 rmarkdown 文档中的 htmltools 中使用带有特殊字符的标签?
【发布时间】:2018-09-08 16:56:54
【问题描述】:

在 rmarkdown 文档中,如何在带有 htmltools 包的标签内使用 HTML 特殊字符?

如果我们在 rmarkdown 文档的 r 块中写入类似这样的内容

htmltools::tags$th("μ")

我们得到:

<th>&amp;mu;</th>

而不是

<th>&mu;</th>

【问题讨论】:

  • 除了我在下面的回答之外,您可能还想阅读此内容 stackoverflow.com/questions/35367945/… 。我对这个主题了解不多,但请确保您毕竟不需要输出中的 amp 部分。

标签: r r-markdown htmltools


【解决方案1】:

你能像这样解决它吗?

gsub("amp", "", htmltools::tags$th("&mu;"))
<th>&mu;</th>

【讨论】:

    【解决方案2】:

    htmltools 包有一个函数 HTML 用于此:

    require(htmltools)
    require(magrittr)
    
    "&mu;" %>% HTML %>% (tags$th) %>% as.character %>% cat
    

    这会导致:

    <th>&mu;</th>
    

    【讨论】:

      猜你喜欢
      • 2015-01-05
      • 2021-06-15
      • 1970-01-01
      • 2012-04-28
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多