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 · 4 comments
Labels
feature Feature requests
Milestone

Comments

@gadenbuie
Copy link
Contributor

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 Feature requests label Feb 28, 2019
@yihui yihui closed this as completed in c2aae98 Feb 28, 2019
@yihui
Copy link
Owner

yihui 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 yihui/yihui.org that referenced this issue Mar 1, 2019
@gadenbuie
Copy link
Contributor Author

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
Copy link
Owner

yihui commented Mar 5, 2019

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

Thanks for the blog post. It looks great!

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Feature requests
Projects
None yet
Development

No branches or pull requests

2 participants