From a7433a58d5b01c286ab89fd8bced677c7c4bd294 Mon Sep 17 00:00:00 2001 From: David Reed Date: Mon, 2 Jan 2023 08:18:23 -0700 Subject: [PATCH] Expose `markdown` config property to templates (#2052) * Expose the markdown config property to templates * Document additional strategies for linking code-highlight stylesheets --- components/config/src/config/mod.rs | 17 +++++++++++++++++ .../content/syntax-highlighting.md | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/components/config/src/config/mod.rs b/components/config/src/config/mod.rs index 40ea154faa..b45a250867 100644 --- a/components/config/src/config/mod.rs +++ b/components/config/src/config/mod.rs @@ -105,6 +105,7 @@ pub struct SerializedConfig<'a> { taxonomies: &'a [taxonomies::TaxonomyConfig], build_search_index: bool, extra: &'a HashMap, + markdown: &'a markup::Markdown, } impl Config { @@ -319,6 +320,7 @@ impl Config { taxonomies: &options.taxonomies, build_search_index: options.build_search_index, extra: &self.extra, + markdown: &self.markdown, } } } @@ -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); + } } diff --git a/docs/content/documentation/content/syntax-highlighting.md b/docs/content/documentation/content/syntax-highlighting.md index d248d3d69b..0d32bf43e3 100644 --- a/docs/content/documentation/content/syntax-highlighting.md +++ b/docs/content/documentation/content/syntax-highlighting.md @@ -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 + + + + + +``` + +Themes can conditionally include code-highlighting stylesheet `` tags by wrapping them in a conditional: + +```jinja2 +{% if config.markdown.highlight_code and config.markdown.highlight_theme == "css" %} + + +{% endif %} +``` + ## Annotations