1

我正在使用 RMarkdown 通过 blogdown 撰写博客。例如,我想包括嵌入式推文。如下所示:

<blockquote class="twitter-tweet" data-partner="tweetdeck">
  <p lang="en" dir="ltr">Section 1.5 uses the gutenbergr package to pull literary text. Unfortunately, the function doesn&#39;t get through our work firewall.</p>&mdash; Jeremy GH (@JGreenbrookHeld) 
  <a href="https://twitter.com/JGreenbrookHeld/status/912774476533719040?ref_src=twsrc%5Etfw">September 26, 2017</a>
</blockquote>
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

我知道如何包含将被评估的 R 代码,但我不知道如何只插入一个 HTML 代码块并让它直接传递。有小费吗?

例如,我有一个简单的 RMarkdown 文档

---
title: "Test"
author: "Mark Ewing"
date: "October 2, 2017"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

<blockquote class="twitter-tweet" data-partner="tweetdeck">
  <p lang="en" dir="ltr">Section 1.5 uses the gutenbergr package to pull literary text. Unfortunately, the function doesn&#39;t get through our work firewall.</p>&mdash; Jeremy GH (@JGreenbrookHeld) 
  <a href="https://twitter.com/JGreenbrookHeld/status/912774476533719040?ref_src=twsrc%5Etfw">September 26, 2017</a>
</blockquote>
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

当我将 HTML 放在文档中间时,我得到了这个错误:

pandoc.exe: Could not fetch //platform.twitter.com/widgets.js
//platform.twitter.com/widgets.js: openBinaryFile: does not exist (No such file or directory)
Error: pandoc document conversion failed with error 67
In addition: Warning message:
running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS test.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.html --smart --email-obfuscation none --self-contained --standalone --section-divs --template "C:\Users\u772700\Documents\R\win-library\3.4\rmarkdown\rmd\h\default.html" --no-highlight --variable highlightjs=1 --variable "theme:bootstrap" --include-in-header "C:\Users\u772700\AppData\Local\Temp\RtmpK4i4dH\rmarkdown-str30e47033f51.html" --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"' had status 67 
Execution halted

如果我首先将它包装在代码标记 ``` 中,它会引用 html 而不是渲染它。

4

1 回答 1

4

尽管在上面的评论中已经指出了一种解决方案(将协议添加到 widget.js 的 URL),http://我想提一下blogdown文档,其中我专门使用了嵌入推文作为示例。我不建议您使用 Twitter 提供的嵌入代码,而是使用更轻量级的 Hugo 短代码(尽管它本质上在后台生成相同的东西)。

于 2017-10-02T20:42:48.643 回答