Skip to content

Commit

Permalink
fix #310: also support .sass and .scss files in the css argument (#311
Browse files Browse the repository at this point in the history
)
  • Loading branch information
cderv authored May 13, 2021
1 parent 463c75f commit 3780768
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Imports:
knitr (>= 1.30),
servr (>= 0.13),
xfun (>= 0.18),
rmarkdown (>= 2.7)
rmarkdown (>= 2.8)
Suggests: rstudioapi, testit
License: MIT + file LICENSE
URL: https://github.com/yihui/xaringan
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- When an image is empty (e.g., `![]()`), the output format option `self_contained: true` of `xaringan::moon_reader` fails to encode the image (thanks, @Mosk915, #302).

- `css` argument in `moon_reader()` now correctly support `.scss` and `.sass` files following their support in base format `rmarkdown::html_document()` in **rmarkdown** 2.8 (thanks, @abichat, #310).

# CHANGES IN xaringan VERSION 0.20

- Fixed the bug that HTML widgets stopped working with new versions of **htmltools** and **rmarkdown** (thanks, @vcannataro @gadenbuie, #293).
Expand Down
7 changes: 5 additions & 2 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
#' \code{.css}, it is supposed to be a built-in CSS file in this package,
#' e.g., for \code{css = c('default', 'extra.css')}), it means
#' \code{default.css} in this package and a user-provided \code{extra.css}. To
#' find out all built-in CSS files, use \code{xaringan:::list_css()}.
#' find out all built-in CSS files, use \code{xaringan:::list_css()}. With
#' \pkg{rmarkdown} >= 2.8, Sass files (filenames ending with \file{.scss} or
#' \file{.sass}) can also be used, and they will be processed by the
#' \pkg{sass} package, which needs to be installed.
#' @param self_contained Whether to produce a self-contained HTML file by
#' embedding all external resources into the HTML file. See the \sQuote{Note}
#' section below.
Expand Down Expand Up @@ -96,7 +99,7 @@ moon_reader = function(
chakra = 'https://remarkjs.com/downloads/remark-latest.min.js', nature = list(),
anchor_sections = FALSE, ...
) {
theme = grep('[.]css$', css, value = TRUE, invert = TRUE)
theme = grep('[.](?:sa|sc|c)ss$', css, value = TRUE, invert = TRUE)
deps = if (length(theme)) {
css = setdiff(css, theme)
check_builtin_css(theme)
Expand Down
22 changes: 22 additions & 0 deletions inst/rmarkdown/templates/xaringan/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,28 @@ See [yihui/xaringan#83](https://github.com/yihui/xaringan/issues/83) for an exam

---

# CSS (with Sass)

**xaringan** also supports Sass support via **rmarkdown**. Suppose you want to use the same color for different elements, e.g., first heading and bold text. You can create a `.scss` file, say `mytheme.scss`, using the [sass](https://sass-lang.com/) syntax with variables:

```scss
$mycolor: #ff0000;
.remark-slide-content > h1 { color: $mycolor; }
.remark-slide-content strong { color: $mycolor; }
```

Then set the `css` option in the YAML metadata using this file placed under the same directory as your Rmd:

```yaml
output:
xaringan::moon_reader:
css: ["default", "mytheme.scss"]
```

This requires **rmarkdown** >= 2.8 and the [**sass**](https://rstudio.github.io/sass/) package. You can learn more about **rmarkdown** and **sass** support in [this blog post](https://blog.rstudio.com/2021/04/15/2021-spring-rmd-news/#sass-and-scss-support-for-html-based-output) and in [**sass** overview vignette](https://rstudio.github.io/sass/articles/sass.html).

---

# Themes

Don't want to learn CSS? Okay, you can use some user-contributed themes. A theme typically consists of two CSS files `foo.css` and `foo-fonts.css`, where `foo` is the theme name. Below are some existing themes:
Expand Down
5 changes: 4 additions & 1 deletion man/moon_reader.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3780768

Please sign in to comment.