Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline HTML not passed through #326

Closed
wch opened this issue Dec 11, 2014 · 8 comments
Closed

Inline HTML not passed through #326

wch opened this issue Dec 11, 2014 · 8 comments
Milestone

Comments

@wch
Copy link
Contributor

@wch wch commented Dec 11, 2014

When raw HTML is added to a Rmd document, any tags that are indented four or more spaces get treated as code instead of raw HTML. @hadley and @jmcphers pointed me to some workarounds, shown below:


---
title: "Untitled"

---

Doesn't work:

<div>
    <div>block 1
    </div>
</div>

*****

Works:

```{r echo=FALSE}
knitr::asis_output(htmltools::htmlPreserve("
<div>
    <div>block 2
    </div>
</div>
"))
```

*****

Works:

<!--html_preserve-->
<div>
    <div>block 3
    </div>
</div>
<!--/html_preserve-->

I suspect this is actually a bug in Pandoc. I'm using 1.13.1 with RStudio 0.99.97.

@jjallaire
Copy link
Member

@jjallaire jjallaire commented Dec 11, 2014

It's not a bug in pandoc it's actually expected behavior! This is because pandoc allows markdown in HTML, and when you indent 4 spaces that's actually considered a markdown code block. The solution is to use one of the workarounds described by Winston or to just generate HTML without the indentation.

@hadley
Copy link
Member

@hadley hadley commented Dec 11, 2014

It's not clear that this is desired behaviour in pandoc. One of the example in the manual (under raw_html) is

<table>
    <tr>
        <td>*one*</td>
        <td>[a link](http://google.com)</td>
    </tr>
</table>

I don't think the expectation is that this is transformed into

<table>
<pre>
<tr>
    <td>*one*</td>
    <td>[a link](http://google.com)</td>
</tr>
<pre>
</table>
@hadley
Copy link
Member

@hadley hadley commented Dec 11, 2014

That said, if I run that block of html through pandoc I get:

<table>
<pre><code>&lt;tr&gt;
    &lt;td&gt;*one*&lt;/td&gt;
    &lt;td&gt;[a link](http://google.com)&lt;/td&gt;
&lt;/tr&gt;</code></pre>
</table>

So it's either a bug in the implementation or the documentation. Might be worth a post to the pandoc mailing list

@wch
Copy link
Contributor Author

@wch wch commented Dec 11, 2014

@xvrl
Copy link

@xvrl xvrl commented Mar 2, 2015

@hadley I'm running into this issue as well. Is there a way to tell rmarkdown to use the markdown_strict variant when producing html output? That would also be a workaround.

@jjallaire
Copy link
Member

@jjallaire jjallaire commented Mar 31, 2015

You can now use the md_extensions parameter to remove the "markdown in html" behavior on a per-document basis.

@yihui yihui added this to the v1.7 milestone Aug 31, 2017
@yihui
Copy link
Member

@yihui yihui commented Aug 31, 2017

The example on the rmarkdown website seems to have been fixed. There isn't much we can do on rmarkdown's side. For this issue, we are at the mercy of Pandoc...

@github-actions
Copy link

@github-actions github-actions bot commented Nov 3, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants