代码之家  ›  专栏  ›  技术社区  ›  Mark

如何在RMarkdown文档中包含任意HTML?

  •  1
  • Mark  · 技术社区  · 7 年前

    我正在使用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>
    

    例如,我有一个简单的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
    

    1 回复  |  直到 7 年前
        1
  •  4
  •   Yihui Xie    7 年前

    尽管上述评论中指出了一种解决方案(添加协议 http:// 到小部件的URL。js),我想提一下 the blogdown documentation