Syntax highlighting demo

Demonstrating syntax highlighting in Quarto with various languages.

Syntax highlighting theme can be set in YAML as highlight-style with either the name of a KDE style (see KSyntaxHighlighting color themes), or as a valid JSON file with extension .theme. For details on KDE color-theme files, see “The Color Themes JSON Format” (Working with Color Themes, KDE Documentation).

See Quarto’s options for code chunks for HTML output for more information on styling code chunks.

R example

# plotting of R objects
plot <- function (x, y, ...)
{
  if (is.function(x) && 
      is.null(attr(x, "class")))
  {
    if (missing(y))
      y <- NULL
    
    # check for ylab argument
    hasylab <- function(...) 
      !all(is.na(
        pmatch(names(list(...)),
              "ylab")))
    
    if (hasylab(...))
      plot.function(x, y, ...)
    
    else 
      plot.function(
        x, y, 
        ylab = paste(
          deparse(substitute(x)),
          "(x)"), 
        ...)
  }
  else 
    UseMethod("plot")
}

Python example

@requires_authorization(roles=["ADMIN"])
def somefunc(param1='', param2=0):
    r'''A docstring'''
    if param1 > param2: # interesting
        print 'Gre\'ater'
    return (param2 - param1 + 1 + 0b10l) or None

class SomeClass:
    pass

>>> message = '''interpreter
... prompt'''

JavaScript example

const pluckDeep = key => obj => key.split('.').reduce((accum, key) => accum[key], obj)

const compose = (...fns) => res => fns.reduce((accum, next) => next(accum), res)

const unfold = (f, seed) => {
  const go = (f, seed, acc) => {
    const res = f(seed)
    return res ? go(f, res[1], acc.concat([res[0]])) : acc
  }
  return go(f, seed, [])
}

SCSS example

/*-- scss:defaults --*/
$h2-font-size:          1.6rem !default;
$headings-font-weight:  500 !default;
$body-color:            $gray-700 !default;

/*-- scss:rules --*/
h1, h2, h3, h4, h5, h6 {
  text-shadow: -1px -1px 0 rgba(0, 0, 0, .3);
}

YAML example

title: "My Document"
format:
  html: 
    theme: cosmo
    fontsize: 1.1em
    linestretch: 1.7
Back to top