Reputation: 105
I'm trying to replicate the Rstudio 'cobalt' theme on my Rmarkdown code chunks. So far I have this:
```{css, echo=FALSE}
.cobalt {
background-color: #002240;
border: 3px #324c63;
}
```
```{r class.source="cobalt"}
"string"
x <- 1
function() return()
# comment
TRUE
```
Which looks like this:
But I want it to look like this:
How can I do this? notice that the font (and ligatures), highlighting of strings, booleans, doubles and functions are all different. My hope is that there is some template in GitHub or perhaps as part of Rstudio itself so that I can simply do class.source=cobalt
and class.output=cobalt
.
The biggest problem I have at the moment is that I don't know besides background-color:
and border:
what other options I can specify. So If someone could point me towards the relevant documentation that would be appreciated too.
Thanks for your help!
Upvotes: 1
Views: 615
Reputation: 19857
One way to replicate Rstudio cobalt theme on the Rmarkdown code syntax highlighting, is to create a custom theme for syntax highlighting.
(I have added the complete theme file down below, tweak that as necessary following this cobalt rstheme
) and refer to this page to know which selector in rstheme means what.
---
title: "Cobalt - Syntax Highlighting"
output:
html_document:
highlight: cobalt.theme
theme:
version: 4
code_font:
google: Fira Code
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
```{r results='hide'}
"string"
x <- 1
function() return()
y <- x + 1
# comment
TRUE
```
cobalt.theme
{
"text-color": "#F4F4F4",
"background-color": "#002240",
"line-number-color": "#aaaaaa",
"line-number-background-color": null,
"text-styles": {
"Other": {
"text-color": "#BED6FF",
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"Attribute": {
"text-color": "#FF9D00",
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"SpecialString": {
"text-color": "#FF9D00",
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"Annotation": {
"text-color": "#60a0b0",
"background-color": null,
"bold": true,
"italic": true,
"underline": false
},
"Function": {
"text-color": "#FF9D00",
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"String": {
"text-color": "#3AD900",
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"ControlFlow": {
"text-color": "#FF9D00",
"background-color": null,
"bold": true,
"italic": false,
"underline": false
},
"Operator": {
"text-color": "#BED6FF",
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"Error": {
"text-color": "#FF0000",
"background-color": null,
"bold": true,
"italic": false,
"underline": false
},
"BaseN": {
"text-color": "#40a070",
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"Alert": {
"text-color": "#ff0000",
"background-color": null,
"bold": true,
"italic": false,
"underline": false
},
"Variable": {
"text-color": "#CCCCCC",
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"BuiltIn": {
"text-color": "#BED6FF",
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"Extension": {
"text-color": null,
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"Preprocessor": {
"text-color": "#bc7a00",
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"Information": {
"text-color": "#60a0b0",
"background-color": null,
"bold": true,
"italic": true,
"underline": false
},
"VerbatimString": {
"text-color": "#4070a0",
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"Warning": {
"text-color": "#60a0b0",
"background-color": null,
"bold": true,
"italic": true,
"underline": false
},
"Documentation": {
"text-color": "#ba2121",
"background-color": null,
"bold": false,
"italic": true,
"underline": false
},
"Import": {
"text-color": null,
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"Char": {
"text-color": "#4070a0",
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"DataType": {
"text-color": "#902000",
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"Float": {
"text-color": "#40a070",
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"Comment": {
"text-color": "#0088FF",
"background-color": null,
"bold": false,
"italic": true,
"underline": false
},
"CommentVar": {
"text-color": "#60a0b0",
"background-color": null,
"bold": true,
"italic": true,
"underline": false
},
"Constant": {
"text-color": "#FF628C",
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"SpecialChar": {
"text-color": "#BED6FF",
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"DecVal": {
"text-color": "#FF628C",
"background-color": null,
"bold": false,
"italic": false,
"underline": false
},
"Keyword": {
"text-color": "#FF628C",
"background-color": null,
"bold": true,
"italic": false,
"underline": false
}
}
}
Upvotes: 1