我正try 在一个四重奏文档中动态创建一个标注.我可以创建标注,但Quarto似乎覆盖了我的格式指令.

我可以使用Quarto命令创建一个格式正确的静态NTFS:

::: {.callout-important}

This is the first hard-coded warning.

:::

它产生了

enter image description here

正如我所料.判断该HTML文档的此元素会显示以下HTML:

enter image description here

当我复制并粘贴此输出,无论是在Quarto文档的正文中,还是在同一文档中的代码块中,然后呈现文档时,我看到:

enter image description here

对应的HTML:

enter image description here

我原来的HTML在渲染过程中被修改了.

这里有一个MRE:

---
title: "Test"
format: html
editor: visual
---

::: {.callout-important}

This is the first hard-coded warning.

:::

```{r}
#| label: validation
#| echo: FALSE
#| results: asis
cat("
<div class=\"callout callout-style-default callout-important callout-titled\">
<div class=\"callout-header d-flex align-content-center\">
<div class=\"callout-icon-container\">
<i class=\"callout-icon\"></i>
</div>
<div class=\"callout-title-container flex-fill\">
Important
</div>
</div>
<div class=\"callout-body-container callout-body\">
<p>This is a dynamic warning.</p>
</div>
</div>    
")
```

<div class="callout callout-style-default callout-important callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Important
</div>
</div>
<div class="callout-body-container callout-body">
<p>This is the second hard-coded warning.</p>
</div>
</div>

此外,

cat("::: {.callout-important}\\n\\n This is the second dynamic callout. \\n\\n ::: \\n\\n")

而类似的做法也不起作用.

有人可以帮助我动态创建一个格式正确的NTFS吗?

Edit

按照Samr在 comments 中的建议,这

```{=HTML}
<div class="callout callout-style-default callout-important callout-titled">
 <div class="callout-header d-flex align-content-center">
 <div class="callout-icon-container">
 <i class="callout-icon"></i>
 </div>
 <div class="callout-title-container flex-fill">
 Important
 </div>
 </div>
 <div class="callout-body-container callout-body">
 <p>This is the second hard-coded warning.</p>
 </div>
 </div>
 ```

产生所需的输出,但保持静态,因此不能完全解决我的问题.

推荐答案

这里是第二个选项,它也使用了一个自定义函数直接向文档添加一个XSLT块(与你try 的方法相反,它没有转义断点,即我使用\n而不是\\n:

---
title: "Untitled"
format: html
editor: visual
---

```{r}
#| echo: FALSE
my_callout <- function(type, x) {
  sprintf(
    paste(
      "::: {.callout-%s}",
      "This is the %s dynamic callout.",
      ":::",
      sep = "\n\n"
    ),
    type, x
  ) |> 
    cat()
}
```

```{r}
#| echo: FALSE
#| results: asis
my_callout("important", "SECOND")

```

```{r}
#| echo: FALSE
#| results: asis
my_callout("note", "THIRD")
```

enter image description here

R相关问答推荐

在通过最大似然估计将ODE模型与数据匹配时,为什么要匹配实际参数的转换值?

R中具有gggplot 2的Likert图,具有不同的排名水平和显示百分比

如何修复R码的置换部分?

更改默认系列1以更改名称

如何使用STAT_SUMMARY向ggplot2中的密度图添加垂直线

汇总数据表中两个特定列条目的值

用关联字符串替换列名的元素

如何使用ggplot对堆叠条形图进行嵌套排序?

plotly hover文本/工具提示在shiny 中不起作用

R Read.table函数无法对制表符分隔的数据正常工作

`lazy_dt`不支持`dplyr/across`?

将Posict转换为数字时的负时间(以秒为单位)

如何基于两个条件从一列中提取行

展开对数比例绘图的轴(添加填充)

KM估计的差异:SvyKm与带权重的调查

如何平滑或忽略R中变量的微小变化?

将工作目录子文件夹中的文件批量重命名为顺序

删除在R中的write.table()函数期间创建的附加行

如何创建直方图与对齐的每月箱?

在一个multiplot中以非对称的方式在R中绘制多个图