Skip to content

Commit

Permalink
Add css highlighting documentation
Browse files Browse the repository at this point in the history
This is copied from getzola#913

Co-Authored-By: Uwe Arzt <[email protected]>
  • Loading branch information
evan-brass and uwearzt committed Nov 16, 2020
1 parent 8b414ac commit 7472f1d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
72 changes: 72 additions & 0 deletions docs/content/documentation/content/css-syntax-highlighting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
+++
title = "CSS Syntax Highlighting"
weight = 80
+++

If you use a highlighting scheme like

```toml
highlight_theme = "base16-ocean-dark"
```

for a code block like

````md
```rs
let highlight = true;
```
````

you get the colors directly encoded in the html file

```html
<pre style="background-color:#2b303b;">
<code>
<span style="color:#b48ead;">let</span>
<span style="color:#c0c5ce;"> highlight = </span>
<span style="color:#d08770;">true</span>
<span style="color:#c0c5ce;">;
</span>
</code>
</pre>
```

this is nice, because if everything is inside one file, you get fast
page loadings. But if you would like to have the user choose a theme from a
list, or different color schemes for dark/light color schemes, ou need a
different solution.

If you use the special color scheme

```toml
highlight_theme = "css"
```

you get CSS class definitions

```html
<pre class="code">
<code class="code">
<span class="source rust">
<span class="storage type rust">let</span> highlight
<span class="keyword operator assignment rust">=</span>
<span class="constant language rust">true</span>
<span class="punctuation terminator rust">;</span>
</span>
</code>
</pre>
```

now you can generate and use CSS either manually or with Zola

```toml
highlighting_themes_css = [
{ theme = "base16-ocean-dark", filename = "syntax-theme-dark.css" },
{ theme = "base16-ocean-light", filename = "syntax-theme-light.css" },
]
```

```css
@import url("syntax-theme-dark.css") (prefers-color-scheme: dark);
@import url("syntax-theme-light.css") (prefers-color-scheme: light);
```
10 changes: 10 additions & 0 deletions docs/content/documentation/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ highlight_code = false

# The theme to use for code highlighting.
# See below for list of allowed values.
# This will put the colors of the theme directly in your html.
highlight_theme = "base16-ocean-dark"
# For using CSS class definitions in the higlighting, you can use the
# special theme "css". This is especially useful for dark/light themes,
# or letting the user decide the higlighting scheme.
# If the site uses some of the predefined syntax highlighing schemes as
# CSS, you can let Zola generate the CSS.
highlighting_themes_css = [
{ theme = "base16-ocean-dark", filename = "syntax-theme-dark.css" },
{ theme = "base16-ocean-light", filename = "syntax-theme-light.css" },
]

# When set to "true", a feed is automatically generated.
generate_feed = false
Expand Down

0 comments on commit 7472f1d

Please sign in to comment.