如何在输出中不使用JavaScript来从RMarkdown呈现HTML [英] How to render HTML from RMarkdown without javascript in output

查看:199
本文介绍了如何在输出中不使用JavaScript来从RMarkdown呈现HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使是最简单的rmarkdown文档,在渲染时似乎也会创建一个包含javascript的html文档。我期待创建可以成为电子邮件正文的html。有没有一种方法可以在生成的html中不使用javascript来进行降价?



下面没有什么特别的,它只是一个通用的例子:

  --- 
标题:示例
作者:JKGrain
日期:March 31, 2015
输出:html_document
---

这是一个R Markdown文档。 Markdown是用于创作HTML,PDF和MS Word文档的简单格式化语法。有关使用R Markdown的更多详细信息,请参阅< http://rmarkdown.rstudio.com> ;.

当您单击** Knit **按钮时,将生成一个文档,其中包含文档中的任何嵌入式R代码块的内容以及输出。您可以像这样嵌入一个R代码块:

```{r}
汇总(汽车)
```

您也可以嵌入图,例如:

```{r,echo = FALSE}
plot(cars)
```

请注意, `echo = FALSE`参数被添加到代码块中以防止生成该图的R代码的打印。

生成的html源代码如下所示:

 <!DOCTYPE html> 

< html xmlns =http://www.w3.org/1999/xhtml>

< head>

< meta charset =utf-8>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< meta name =generatorcontent =pandoc/>

< meta name =authorcontent =JKGrain/>

< meta name =datecontent =2015-03-31/>

< title>示例< / title>

< script src =data:application / x-javascript,%2F%2A%21%20jQuery%20v1%2E11 .....



显然,我已经修剪了其余的html,但希望这可以解释这个问题。

>解决方案

默认的html输出格式的javascript来自主题,语法高亮和方程式的mathjax,你可以在头部禁用这三样东西:

  --- 
输出:
html_document:
主题:null
highlight:null
mathjax:null
---


Even the simplest rmarkdown document when rendered seems to create an html document that includes javascript. I am looking to create html that can be the body of an email. Is there a way to render markdown with no javascript in the resulting html?

There is nothing special about the following, it is just a generic example:

---
title: "Sample"
author: "JKGrain"
date: "March 31, 2015"
output: html_document
---

This is an R Markdown document. Markdown is a simple formatting syntax for     authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r}
summary(cars)
```

You can also embed plots, for example:

```{r, echo=FALSE}
plot(cars)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

The resulting html source begins like this:

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />

<meta name="author" content="JKGrain" />

<meta name="date" content="2015-03-31" />

<title>Sample</title>

<script src="data:application/x-javascript,%2F%2A%21%20jQuery%20v1%2E11.....

Obviously, i have clipped the rest of the html, but hopefully this explains the issue.

解决方案

The javascript in the default html output format comes from the theme, syntax highlighting, and mathjax for equations. You can disable these three things in the header like so:

---
output: 
    html_document:
        theme: null
        highlight: null
        mathjax: null
---

这篇关于如何在输出中不使用JavaScript来从RMarkdown呈现HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆