F. Guilhaumon
F. Guilhaumon

Reputation: 11

How to echo raw code in html_document rendered by r-markdown

My question is simple, though I cannot really find a satisfying answer anywhere.

I'm trying to write an r code chunk that, when rendered as html_document, gives exactly the following in the html source of the rendered document :

<div class="mermaid">
graph LR

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

I'm ending doing this in a {r, echo = FALSE, results = 'asis'} r chunk:

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'))

However I cannot get rid of the <p></p> html formatting that appears during the md -> html pandoc conversion:

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

I'm trying to do this so as to have the content of <div class="mermaid"> </div> to be interpreted by the mermaid library included in the html_document via includes:in_header.

Upvotes: 0

Views: 131

Answers (1)

F. Guilhaumon
F. Guilhaumon

Reputation: 11

Try to insert a new chunk with htmltools::includeHTML("my_html.html") and in the filye "my_html.html" write your html code

Upvotes: 1

Related Questions