css - 将 Rmarkdown 与来自 CDN 的 CSS 结合使用

标签 css r twitter-bootstrap knitr r-markdown

我想使用来自 CDN (http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css) 的 Bootstrap CSS 创建一个 Rmarkdown。

我正在尝试这样做,但没有成功...

这是我试过的(我试过没有使用NULL,也没有使用“”,但我有同样的错误)

---
title: "Habits"
output:
  html_document:
    theme: NULL
    highlight: NULL
    css: "http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"

---

产生的错误是:

"E:/Program Files/R/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS teste.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output teste.html --smart --email-obfuscation none --self-contained --standalone --section-divs --template "C:\Users\diego\Documents\R\win-library\3.2\rmarkdown\rmd\h\default.html" --css "http:\\maxcdn.bootstrapcdn.com\bootstrap\3.3.6\css\bootstrap.min.css" --mathjax --variable "mathjax-url:https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --no-highlight 
output file: teste.knit.md

pandoc.exe: Could not fetch http:\\maxcdn.bootstrapcdn.com\bootstrap\3.3.6\css\bootstrap.min.css
InvalidUrlException "http:%5C%5Cmaxcdn.bootstrapcdn.com%5Cbootstrap%5C3.3.6%5Ccss%5Cbootstrap.min.css" "URL must be absolute"
Error: pandoc document conversion failed with error 67
Besides that: Warning message:
command execution '"E:/Program Files/R/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS teste.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output teste.html --smart --email-obfuscation none --self-contained --standalone --section-divs --template "C:\Users\diego\Documents\R\win-library\3.2\rmarkdown\rmd\h\default.html" --css "http:\\maxcdn.bootstrapcdn.com\bootstrap\3.3.6\css\bootstrap.min.css" --mathjax --variable "mathjax-url:https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --no-highlight' teve status 67 
Execution interrupted

有一些方法可以用绝对路径引用在线 CSS 吗?

谢谢,

最佳答案

来自 Rmarkdown Github 成员@jjallaire:

不支持 css 选项的外部 URL,但是您可以这样做:

---
title: "Habits"
output:
  html_document:
    theme: NULL
    highlight: NULL
---

<style type="text/css">
@import url("http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css");
</style>
—

编辑: 我在 Rmarkdown 页面上找到的另一个解决方案:

---
title: "Habits"
output:
  html_document:
    theme: flatly
    highlight: tango
---

The flatly come from Bootstrap and have the bootstrap styles.

关于css - 将 Rmarkdown 与来自 CDN 的 CSS 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35653260/

相关文章:

html - 在页面上居中元素的问题

html - 使按钮和链接高度相同

R lag/lead - 如何忽略现有行之前和之后的行

r - 在 R 中选择数据表的每隔一列。两种语法有什么区别

html - Div 的内部 Bootstrap 列在缩放后重叠

css - 使用 CSS 缩放

java - 从 R 传递 java arraylist 对象

jquery - Bootstrap 多个画廊

css - 调整浏览器大小无法正确调整 div 大小 - 如此简单,我做错了什么?

javascript - 如何知道在大量代码中正在执行哪个 java 脚本函数?