Add syntax highlighting support¶
Liara uses Pygments by default for code highlighting. To make syntax look nice though, you need to include a CSS spreadsheet for your preferred style and reference that, otherwise the Pygments output will not get any styling applied.
This is a 3-step process. We’ll be using the liara quickstart template here as the starting point.
Generate a style CSS for your preferred style. See the Pygments documentation for details, for the quick start, we’ll use:
$ cd templates $ mkdir static $ cd static $ pygmentize -f html -S colorful -a .code > code.css
Note
This generates a CSS file for the
colorfulstyle that can be used with all languages.Tell Liara about the CSS file and have it copied to the output. To achieve this, add
static_directory: statictotemplates/default.yaml. This will ensure thecode.cssfile inside thetemplates/staticrepository will be copied verbatim into the output.Update the CSS to reference it. Edit
templates/page.jinja2and add a reference like this<link type="text/css" rel="stylesheet" href="/code.css" />.
To test, add some code to one of the sample files in content using:
```c++
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "Hello" << std::endl;
}
```
It should show up nicely colored in your generated output.