Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply class.output to all chunk outputs or add custom classes for error, warning, message #1676

Closed
gadenbuie opened this issue Feb 25, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@gadenbuie
Copy link
Contributor

commented Feb 25, 2019

I just discovered the class.source and class.output options introduced in #1335 and really appreciate this feature for adding CSS classes to chunk outputs in HTML. But I noticed that the class.output value is not added to outputs from "side effect" chunk outputs, such as messages, warnings and errors.

It would be great if this class could be applied to messages, warnings and errors as well. I would even more appreciate it if each of these could receive a custom CSS class -- perhaps class.message, class.warning, class.error -- that defaults to class.output if not otherwise specified.

Here's a small demo reprex.

RMD source
---
title: "class.output for messages, warnings, errors"
output: html_document
---

```{r setup}
# setup
knitr::opts_chunk$set(echo = TRUE, class.output = "output-style")
```

```{css}
/* class.output */
.output-style {
  background: #A2CD5A;
}
```

```{r}
cat("Normal R chunk output")
```

```{r, error = TRUE}
stop("An error occurred in this chunk.")
```

```{r}
message("This is a message")
```

```{r}
warning("This is a warning")
```

image

@yihui yihui added this to the v1.21 milestone Feb 28, 2019

@yihui yihui added the Feature label Feb 28, 2019

@yihui yihui closed this in c2aae98 Feb 28, 2019

@yihui

This comment has been minimized.

Copy link
Owner

commented Feb 28, 2019

That's a good feature request and easy enough to implement, so it's done now. Feel free to use class.error/class.warning, etc. Thanks!

yihui added a commit to rbind/yihui that referenced this issue Mar 1, 2019

@gadenbuie

This comment has been minimized.

Copy link
Contributor Author

commented Mar 5, 2019

Thank you @yihui, this is awesome! I wrote up a small demonstration using this example, and it looks great!

Btw, I looked in NEWS.md and thought this would be in version 1.22, but I just noticed you put this issue in the v1.21 milestone. Let me know if I need to revise my post.

@yihui yihui modified the milestones: v1.21, v1.22 Mar 5, 2019

@yihui

This comment has been minimized.

Copy link
Owner

commented Mar 5, 2019

Oh, it should be v1.22, which I actually forgot to create...

Thanks for the blog post. It looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.