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 · 7 comments

Comments

Projects
None yet
5 participants
@wch
Contributor

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

This comment has been minimized.

Member

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

This comment has been minimized.

Member

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

This comment has been minimized.

Member

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

This comment has been minimized.

Contributor

wch commented Dec 11, 2014

@xvrl

This comment has been minimized.

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

This comment has been minimized.

Member

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

This comment has been minimized.

Member

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...

@yihui yihui closed this Aug 31, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment