使用 quarto 的 HMTL 输出功能,我尝试从 data.frame 生成一个 kable,其中包含一些应显示在最终文档中的 Markdown 样式格式。在实际用例中,我有许多文档已经以这种方式格式化,我想重新使用这些命令来正确呈现输出。
这是我的示例.qmd:
---
title: "example"
format:
html
---
```{r setup}
library(kableExtra)
```
```{r}
#| echo: false
data.frame(Function = "`read_delim()`",
Formula = "$\\leftarrow$",
Break = "this continues on a<br>new line",
Link = "[Google](www.google.com)") |>
kbl(format = "html")
```
运行该块后,RStudio 中的预览确实正确显示了箭头和换行符,但 ` ` 和链接无法生效:
将 qmd 渲染为 HTML 时,结果如下所示,即忽略格式:
我缺少什么?将四开文档渲染为 HTML 时,是否有办法将此类格式化命令包含到 kable 中?
在 Quarto 中创建表格时,您不能将 Markdown 与 HTML 混合 - Markdown 语法不会在 HTML 表格中进行处理。
这个 R 代码可以工作
data.frame(Function = "`read_delim()`",
Formula = "$\\leftarrow$",
Break = "this continues on a<br>new line",
Link = "[Google](www.google.com)") |>
kbl(format = "markdown")
所以如果可以的话,只输出 Markdown 表knitr::kable()
应该默认执行。
如果您需要输出 HTML 表格(例如,针对特定的 HTML 功能),则需要使用一个框架来在创建 HTML 表格时为您呈现 Markdown。
-
gt with fmt_markdown() https://gt.rstudio.com/reference/fmt_markdown.html and md() https://gt.rstudio.com/reference/md.html
-
灵活的 with ftextra and colformat_md() https://ftextra.atusy.net/reference/colformat_md.html or as_paragraph_md https://ftextra.atusy.net/reference/as_paragraph_md.html
注释能够在 HTML 表格中包含原始 Markdown 的限制将来可能会得到改善(https://github.com/quarto-dev/quarto-cli/discussions/957#discussioncomment-2807907 https://github.com/quarto-dev/quarto-cli/discussions/957#discussioncomment-2807907)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)