2015-03-31 62 views
7

即使渲染時最簡單的rmarkdown文檔似乎會創建一個包含javascript的html文檔。我期待創建可以成爲電子郵件正文的html。有沒有一種方法可以在生成的HTML中不使用JavaScript來進行降價?如何在輸出中使用不帶javascript的RMarkdown呈現HTML

沒有什麼特別之處下面,它只是一個普通的例子:

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

生成的HTML源代碼是這樣開始的:

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

顯然,我已經修剪的休息HTML,但希望這可以解釋這個問題。

+0

@rawr - 我試過了您的建議,並且生成的html仍包含javascript。不管怎麼說,還是要謝謝你。 – jkgrain 2015-03-31 14:10:46

回答

7

默認html輸出格式的javascript來自方程式的主題,語法高亮和mathjax。您可以在標題中禁用這三樣東西,如下所示:

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

來幫助其他可能有這個問題的人,我會指出在YAML中縮進和冒號的位置是非常無情的。如果你的選項沒有按預期工作,請檢查它們。 – jkgrain 2016-02-04 17:18:41

+0

謝謝你。 715KB減1KB。鑑於我只是想要生成R輸出(進入WordPress),這是完美的。 – 2016-05-24 13:40:37

相關問題