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 withstarlight-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)"Structs
Section titled “Structs”struct MkDocsMaterial
Section titled “struct MkDocsMaterial”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/
struct MdBook
Section titled “struct MdBook”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
struct Starlight
Section titled “struct Starlight”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
struct Minimal
Section titled “struct Minimal”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.
Traits
Section titled “Traits”trait ThemeAdapter
Section titled “trait ThemeAdapter”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.
Methods
Section titled “Methods”code_bg
Section titled “code_bg”fn code_bg(&self) -> &strBackground color for code blocks and inline code
Source
fn code_bg(&self) -> &str;code_fg
Section titled “code_fg”fn code_fg(&self) -> &strForeground (text) color for code
Source
fn code_fg(&self) -> &str;primary
Section titled “primary”fn primary(&self) -> &strPrimary/brand color for headings, important elements
Source
fn primary(&self) -> &str;accent
Section titled “accent”fn accent(&self) -> &strAccent color for links, interactive elements
Source
fn accent(&self) -> &str;fn muted(&self) -> &strMuted/secondary text color
Source
fn muted(&self) -> &str;border
Section titled “border”fn border(&self) -> &strBorder color for tables, separators
Source
fn border(&self) -> &str;fn name(&self) -> &strName of this theme adapter (for debugging/logging)
Source
fn name(&self) -> &str;success
Section titled “success”fn success(&self) -> &strSuccess color (typically green) - for positive states
Source
fn success(&self) -> &str { "#4caf50" }warning
Section titled “warning”fn warning(&self) -> &strWarning color (typically yellow/orange) - for caution states
Source
fn warning(&self) -> &str { "#ff9800" }fn error(&self) -> &strError color (typically red) - for error/danger states
Source
fn error(&self) -> &str { "#f44336" }fn info(&self) -> &strInfo color (typically blue) - for informational states
Source
fn info(&self) -> &str { "#2196f3" }badge_async
Section titled “badge_async”fn badge_async(&self) -> &strColor for async badges
Source
fn badge_async(&self) -> &str { self.primary() }badge_unsafe
Section titled “badge_unsafe”fn badge_unsafe(&self) -> &strColor for unsafe badges
Source
fn badge_unsafe(&self) -> &str { self.error() }badge_deprecated
Section titled “badge_deprecated”fn badge_deprecated(&self) -> &strColor for deprecated badges
Source
fn badge_deprecated(&self) -> &str { self.warning() }badge_binding
Section titled “badge_binding”fn badge_binding(&self) -> &strColor for PyO3/binding badges
Source
fn badge_binding(&self) -> &str { "#9c27b0" // purple }badge_pub
Section titled “badge_pub”fn badge_pub(&self) -> &strColor for visibility pub badges
Source
fn badge_pub(&self) -> &str { self.success() }badge_pub_crate
Section titled “badge_pub_crate”fn badge_pub_crate(&self) -> &strColor for visibility pub(crate) badges
Source
fn badge_pub_crate(&self) -> &str { "#ff5722" // deep orange }badge_rust
Section titled “badge_rust”fn badge_rust(&self) -> &strColor for Rust source badges
Source
fn badge_rust(&self) -> &str { "#ff5722" // deep orange (Rust's brand color is orange-ish) }badge_python
Section titled “badge_python”fn badge_python(&self) -> &strColor for Python source badges
Source
fn badge_python(&self) -> &str { "#306998" // Python blue }badge_fill
Section titled “badge_fill”fn badge_fill(&self, color_type: &str) -> StringFill 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() }badge_text
Section titled “badge_text”fn badge_text(&self, color_type: &str) -> StringText 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() }badge_base_style
Section titled “badge_base_style”fn badge_base_style(&self) -> &strCSS 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;" }Functions
Section titled “Functions”fn get_theme_adapter
Section titled “fn get_theme_adapter”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 templateslet 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 minimallet 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), }}