Skip to content

plissken-core::render::theme

Rust

Theme adapters for SSG-native CSS variable integration

This module provides adapters that map semantic color names to the native CSS variables of various static site generators. By using inline styles that reference these variables, generated documentation automatically inherits the SSG’s theme (including dark mode support) without shipping any external CSS.

Supported SSGs

  • MkDocs Material: Uses var(--md-*) CSS variables
  • mdBook: Uses var(--*) CSS variables
  • Starlight: Uses var(--sl-color-*) CSS variables (Aurora tokens with starlight-aurora)
  • Minimal: Hardcoded fallback colors for unstyled contexts

Examples:

use plissken_core::render::{get_theme_adapter, ThemeAdapter};
let adapter = get_theme_adapter(Some("mkdocs-material"));
let style = format!("background: {}; color: {}", adapter.code_bg(), adapter.code_fg());
// Results in: "background: var(--md-code-bg-color); color: var(--md-code-fg-color)"

pub

Derives: Debug, Clone, Copy, Default

MkDocs Material theme adapter

Uses MkDocs Material’s --md-* CSS custom properties for seamless integration with Material for MkDocs themes.

Reference: https://squidfunk.github.io/mkdocs-material/setup/changing-the-colors/

pub

Derives: Debug, Clone, Copy, Default

mdBook theme adapter

Uses mdBook’s CSS custom properties for integration with mdBook themes. mdBook uses simpler variable names without a prefix.

Reference: https://rust-lang.github.io/mdBook/format/theme/index.html

pub

Derives: Debug, Clone, Copy, Default

Astro Starlight theme adapter

Uses Starlight’s --sl-color-* CSS custom properties. Each value follows the site’s light and dark themes. With the starlight-aurora theme, these variables are set from Aurora’s tokens (for example --sl-color-green-low is --ok-bg), so badges take Aurora’s status colors, hyper included.

A badge is a fill (-low) with text in the same hue (-high), the pair that Starlight and Aurora make for text on a tint.

Reference: https://starlight.astro.build/guides/css-and-tailwind/#theming

pub

Derives: Debug, Clone, Copy, Default

Minimal theme adapter with hardcoded fallback colors

Provides reasonable default colors for contexts where CSS variables are not available (plain markdown viewers, unstyled HTML, etc.). Uses a light theme with accessible contrast ratios.

pub

Supertraits: Send + Sync

Trait for mapping semantic color names to SSG-specific CSS variables.

Implementations of this trait provide the actual CSS variable references (or hardcoded colors) for each semantic color role. Templates use these methods to generate inline styles that integrate with the target SSG’s theming system.

fn code_bg(&self) -> &str

Background color for code blocks and inline code

Source
fn code_bg(&self) -> &str;
fn code_fg(&self) -> &str

Foreground (text) color for code

Source
fn code_fg(&self) -> &str;
fn primary(&self) -> &str

Primary/brand color for headings, important elements

Source
fn primary(&self) -> &str;
fn accent(&self) -> &str

Accent color for links, interactive elements

Source
fn accent(&self) -> &str;
fn muted(&self) -> &str

Muted/secondary text color

Source
fn muted(&self) -> &str;
fn border(&self) -> &str

Border color for tables, separators

Source
fn border(&self) -> &str;
fn name(&self) -> &str

Name of this theme adapter (for debugging/logging)

Source
fn name(&self) -> &str;
fn success(&self) -> &str

Success color (typically green) - for positive states

Source
fn success(&self) -> &str {
"#4caf50"
}
fn warning(&self) -> &str

Warning color (typically yellow/orange) - for caution states

Source
fn warning(&self) -> &str {
"#ff9800"
}
fn error(&self) -> &str

Error color (typically red) - for error/danger states

Source
fn error(&self) -> &str {
"#f44336"
}
fn info(&self) -> &str

Info color (typically blue) - for informational states

Source
fn info(&self) -> &str {
"#2196f3"
}
fn badge_async(&self) -> &str

Color for async badges

Source
fn badge_async(&self) -> &str {
self.primary()
}
fn badge_unsafe(&self) -> &str

Color for unsafe badges

Source
fn badge_unsafe(&self) -> &str {
self.error()
}
fn badge_deprecated(&self) -> &str

Color for deprecated badges

Source
fn badge_deprecated(&self) -> &str {
self.warning()
}
fn badge_binding(&self) -> &str

Color for PyO3/binding badges

Source
fn badge_binding(&self) -> &str {
"#9c27b0" // purple
}
fn badge_pub(&self) -> &str

Color for visibility pub badges

Source
fn badge_pub(&self) -> &str {
self.success()
}
fn badge_pub_crate(&self) -> &str

Color for visibility pub(crate) badges

Source
fn badge_pub_crate(&self) -> &str {
"#ff5722" // deep orange
}
fn badge_rust(&self) -> &str

Color for Rust source badges

Source
fn badge_rust(&self) -> &str {
"#ff5722" // deep orange (Rust's brand color is orange-ish)
}
fn badge_python(&self) -> &str

Color for Python source badges

Source
fn badge_python(&self) -> &str {
"#306998" // Python blue
}
fn badge_fill(&self, color_type: &str) -> String

Fill of a badge of the given color type.

Color types: “blue”, “green”, “yellow”, “red”, “purple”, “orange”, and “gray” (any other value).

Source
fn badge_fill(&self, color_type: &str) -> String {
match color_type {
"blue" => self.primary(),
"green" => self.success(),
"yellow" => self.warning(),
"red" => self.error(),
"purple" => self.badge_binding(),
"orange" => self.badge_pub_crate(),
_ => self.muted(),
}
.to_string()
}
fn badge_text(&self, color_type: &str) -> String

Text color of a badge of the given color type (on its fill).

Source
fn badge_text(&self, color_type: &str) -> String {
match color_type {
"yellow" => "black",
_ => "white",
}
.to_string()
}
fn badge_base_style(&self) -> &str

CSS for the shape of a badge (everything but its colors).

Source
fn badge_base_style(&self) -> &str {
"display: inline-block; padding: 0.1em 0.35em; font-size: 0.55em; font-weight: 600; border-radius: 0.2em; vertical-align: middle;"
}

pub

fn get_theme_adapter(template: Option<&str>) -> Box<dyn ThemeAdapter>

Get a theme adapter based on the template name from config.

Returns the appropriate adapter for known SSG templates, or the Minimal adapter as a fallback for unknown templates.

Parameters:

Name Type Description
template Option<&str> Optional template name from output.template in config

Returns:

A boxed trait object implementing ThemeAdapter

Examples:

use plissken_core::render::get_theme_adapter;
// Known templates
let mkdocs = get_theme_adapter(Some("mkdocs-material"));
assert_eq!(mkdocs.name(), "mkdocs-material");
let mdbook = get_theme_adapter(Some("mdbook"));
assert_eq!(mdbook.name(), "mdbook");
// Unknown or missing template falls back to minimal
let minimal = get_theme_adapter(None);
assert_eq!(minimal.name(), "minimal");
Source
pub fn get_theme_adapter(template: Option<&str>) -> Box<dyn ThemeAdapter> {
match template {
Some(t) => match t.to_lowercase().as_str() {
"mkdocs-material" | "mkdocs_material" | "material" => Box::new(MkDocsMaterial),
"mdbook" | "md-book" | "md_book" => Box::new(MdBook),
"starlight" | "astro-starlight" => Box::new(Starlight),
_ => Box::new(Minimal),
},
None => Box::new(Minimal),
}
}