问题
This is a follow-up question to a previous answer I got. Can I apply RStudio editor themes to help files? @Allan Cameron hinted that this is possible in his answer but I can't get it to work. My knowledge of css is poor but this page says that RStudio themes (.rstheme file ) are just css files:
Since an rstheme is just CSS, anything that you can do with CSS you can do in an rstheme.
so I thought I could bring in some of that css code into my help files (css version) to change colouring etc. but it doesn't work. For example including .ace_constant is meant to change the colours and style of words like TRUE and FALSE:
.ace_constant
Changes the color and style of constants like TRUE, FALSE, and numeric literals.
Using the lm help file as an example, I made a copy of the lm R.css help file and called it my.css as outlined in @Allan answer and added .ace_constant with red but it didn't change TRUE FALSE colours. Specifying red for h2 worked though. my.css file:
body {
background: white;
color: black;
}
.ace_constant {
color: red
}
.ace_keyword,
.ace_meta,
.ace_storage,
.ace_storage.ace_type,
.ace_support.ace_type {
color: red
}
a:link {
background: white;
color: blue;
}
a:visited {
background: white;
color: rgb(50%, 0%, 50%);
}
h1 {
background: white;
color: rgb(55%, 55%, 55%);
font-family: monospace;
font-size: x-large;
text-align: center;
}
h2 {
background: white;
color: red;
font-family: monospace;
font-size: large;
text-align: center;
}
h3 {
background: white;
color: rgb(40%, 40%, 40%);
font-family: monospace;
font-size: large;
}
h4 {
background: white;
color: rgb(40%, 40%, 40%);
font-family: monospace;
font-style: italic;
font-size: large;
}
h5 {
background: white;
color: rgb(40%, 40%, 40%);
font-family: monospace;
}
h6 {
background: white;
color: rgb(40%, 40%, 40%);
font-family: monospace;
font-style: italic;
}
img.toplogo {
width: 4em;
vertical-align: middle;
}
img.arrow {
width: 30px;
height: 30px;
border: 0;
}
span.acronym {
font-size: small;
}
span.env {
font-family: monospace;
}
span.file {
font-family: monospace;
}
span.option{
font-family: monospace;
}
span.pkg {
font-weight: bold;
}
span.samp{
font-family: monospace;
}
div.vignettes a:hover {
background: rgb(85%, 85%, 85%);
}
And then call it using @Allan solution:
help_css <- function(func, css_file)
{
pack <- sub("^.*:(.*)>$", "\\1", capture.output(environment(func)))
func <- deparse(substitute(func))
x <- readLines(paste0(find.package(pack), "/html/", func, ".html"))
x[3] <- paste("<style>",
paste(readLines(css_file), collapse = "\n"),
"</style>")
writeLines(x, file.path(tempdir(), "test.html"))
myViewer <- getOption("viewer")
myViewer(file.path(tempdir(), "test.html"))
}
help_css(lm, "C:\\my.css")
gives:
Note how TRUE, FALSE have not changed colour (although the heading has worked, i.e. its red).
My two questions are:
- should the theme
csscommands:.ace_constant,ace_storageetc. work using the approach I have tried to do above? If so, what have I done wrong. - Is there an easier way to apply
RStudioeditor themes to help files?
Thanks
来源:https://stackoverflow.com/questions/64424229/apply-rstudio-editor-themes-to-help-files