Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose markdown config property to templates #2052

Merged
merged 2 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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