【问题标题】:How to render HTML from RMarkdown without javascript in output如何在没有 javascript 的情况下从 RMarkdown 渲染 HTML
【发布时间】:2015-03-31 13:56:47
【问题描述】:

即使是最简单的 rmarkdown 文档,在呈现时似乎也会创建一个包含 javascript 的 html 文档。我正在寻找可以作为电子邮件正文的 html。有没有办法在生成的 html 中不使用 javascript 来呈现 markdown?

以下没有什么特别之处,只是一个通用的例子:

---
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 的其余部分,但希望这可以解释问题。

【问题讨论】:

  • @rawr - 我尝试了你的建议,结果 html 仍然包含 javascript。无论如何,谢谢。

标签: html r r-markdown


【解决方案1】:

默认 html 输出格式的 javascript 来自主题、语法高亮和 mathjax 等式。您可以像这样在标题中禁用这三件事:

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

【讨论】:

  • 为了帮助其他可能有同样问题的人,我会指出,缩进和冒号的位置在 YAML 中是非常不宽容的。如果您的选项未按预期工作,请检查这些选项。
  • 谢谢你。 715KB 降至 1KB 以下。鉴于我只想生成 R 输出(进入 wordpress),这是完美的。
猜你喜欢
  • 2019-09-14
  • 2018-04-13
  • 1970-01-01
  • 1970-01-01
  • 2023-04-05
  • 1970-01-01
  • 2022-10-07
  • 2020-06-01
  • 2021-10-28
相关资源
最近更新 更多