Skip to content

Commit

Permalink
Expose markdown config property to templates (#2052)
Browse files Browse the repository at this point in the history
* Expose the markdown config property to templates

* Document additional strategies for linking code-highlight stylesheets
  • Loading branch information
davidmreed authored and Keats committed Feb 16, 2023
1 parent f2072fa commit a7433a5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
17 changes: 17 additions & 0 deletions components/config/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub struct SerializedConfig<'a> {
taxonomies: &'a [taxonomies::TaxonomyConfig],
build_search_index: bool,
extra: &'a HashMap<String, Toml>,
markdown: &'a markup::Markdown,
}

impl Config {
Expand Down Expand Up @@ -319,6 +320,7 @@ impl Config {
taxonomies: &options.taxonomies,
build_search_index: options.build_search_index,
extra: &self.extra,
markdown: &self.markdown,
}
}
}
Expand Down Expand Up @@ -767,4 +769,19 @@ title = "Zola"
let serialised = config.serialize(&config.default_language);
assert_eq!(serialised.title, &config.title);
}

#[test]
fn markdown_config_in_serializedconfig() {
let config = r#"
base_url = "https://www.getzola.org/"
title = "Zola"
[markdown]
highlight_code = true
highlight_theme = "css"
"#;

let config = Config::parse(config).unwrap();
let serialised = config.serialize(&config.default_language);
assert_eq!(serialised.markdown.highlight_theme, config.markdown.highlight_theme);
}
}
19 changes: 19 additions & 0 deletions docs/content/documentation/content/syntax-highlighting.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,25 @@ You can then support light and dark mode like so:
@import url("syntax-theme-light.css") (prefers-color-scheme: light);
```

Alternately, you can reference the stylesheets in your base template to reduce request chains:

```html
<head>
<!-- Other content -->
<link rel="stylesheet" type="text/css" href="/syntax-theme-dark.css" media="(prefers-color-scheme: dark)" />
<link rel="stylesheet" type="text/css" href="/syntax-theme-light.css" media="(prefers-color-scheme: light)" />
</head>
```

Themes can conditionally include code-highlighting stylesheet `<link>` tags by wrapping them in a conditional:

```jinja2
{% if config.markdown.highlight_code and config.markdown.highlight_theme == "css" %}
<link rel="stylesheet" type="text/css" href="/syntax-theme-dark.css" media="(prefers-color-scheme: dark)" />
<link rel="stylesheet" type="text/css" href="/syntax-theme-light.css" media="(prefers-color-scheme: light)" />
{% endif %}
```


## Annotations

Expand Down

0 comments on commit a7433a5

Please sign in to comment.