Rmarkdown: Different formats for code and output with .css

R source code in rmarkdown HTML output is placed between a <code> tag that lives inside a <pre> with class r. You want to apply the style to all instances of <code> that don’t share this property. Here’s an example using the :not() selector:

pre:not(.r) code {
  font: 12px Monaco, "Courier New";
  color: red;

For bookdown output formats you want to exlcude instances of <code> with class sourceCode:

code:not(.sourceCode) {
  font: 12px Monaco, "Courier New" !important;
  color: red !important;

Note that the use of !important is required here because the default styles have precedence.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top