【问题标题】:How to echo raw code in html_document rendered by r-markdown如何在 r-markdown 呈现的 html_document 中回显原始代码
【发布时间】:2020-07-20 12:56:10
【问题描述】:

我的问题很简单,虽然我在任何地方都找不到令人满意的答案。

我正在尝试编写一个 r 代码块,当它呈现为 html_document 时,在呈现的文档的 html 源代码中提供以下内容:

<div class="mermaid">
graph LR

box1[1. do 1] ==> box2[2. do 2] ==> box3[3. do 3]
</div>

我将在 {r, echo = FALSE, results = 'asis'} r 块中结束此操作:

diag1_char <- 'graph LR

box1[1. do 1] ==> box2[2. do 2] ==> box3[3. do 3]'

cat(paste0('<div class="mermaid">\n', diag1_char,'\n</div>\n'))

但是我无法摆脱md -&gt; html pandoc 转换过程中出现的&lt;p&gt;&lt;/p&gt; html 格式:

<div class="mermaid">
<p>graph LR</p>
<p>box1[1. do 1] ==&gt; box2[2. do 2] ==&gt; box3[3. do 3]</p>
</div>

我正在尝试这样做,以便通过includes:in_header&lt;div class="mermaid"&gt; &lt;/div&gt; 的内容由包含在html_document 中的美人鱼库解释。

【问题讨论】:

  • 尝试使用htmltools::includeHTML("my_html.html") 插入一个新块并在文件“my_html.html”中编写您的html代码。
  • 是的,这行得通,非常感谢。

标签: r-markdown pandoc mermaid


【解决方案1】:

尝试使用 htmltools::includeHTML("my_html.html") 插入一个新块,并在文件 "my_html.html" 中编写您的 html 代码

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-22
    相关资源
    最近更新 更多