knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

There are three types of configuration related to hugodown:

Hugo

hugodown does not work with every possible hugo site. There is some config that we assume (typically in config.toml, but hugo has a bewildering array of places that this might live instead.)

Syntax highlighting {#syntax-highlighting}

The hugo config above causes downlit/hugo to generate output html with the following structure:

<div class="highlight">
  <pre class='chroma'><code class='language-r' data-lang='r'>
    <span class='m'>1</span> <span class='o'>+</span> <span class='m'>1</span>
    <span class='c'>#&gt; [1] 2</span>
  </code></pre>
</div>

To have that look good on your website, you need to defines styles for the CSS necessary classes. You can generate starter CSS with the code below, substituting pygments for the style of your choice:

hugo gen chromastyles --style=pygments > static/css/highlight.css

This generates a file containing definitions that look like this:

/* Background */ .chroma {  }
/* Other */ .chroma .x {  }
/* Error */ .chroma .err {  }
...
/* Keyword */ .chroma .k { color: #008000; }
...
/* LiteralNumber */ .chroma .m { color: #666666 }
...
/* Operator */ .chroma .o { color: #666666 }

Unfortunately, the correct location for highlight.css file varies by theme, so you'll need to do a little detective work to figure out the best place to put it. Is it:

You may also need to do some detective work to figure out how these styles interact with your existing styles, particularly for links within code. Your best bet is to use the web developer console to figure out what's going wrong. You'll then need to figure out how to tweak highlight.css to override these styles. This is a pain, which is why hugodown ships with a couple of themes that are preconfigured.

highlight.js inactivation

If you are using an old hugo theme that uses highlight.js you may want to convert to server-side syntax highlighting. This is not required (and not important if you only use R code on your blog), but is a good idea if you show a variety of programming languages and want the code style to be as consistent as possible.

From easiest to hardest, based on the theme you chose:

hugodown

hugodown also has its own configuration file, _hugodown.yaml. Currently this has one option:



r-lib/hugodown documentation built on Nov. 24, 2022, 10:06 a.m.