Skip to main content

blinc_layout/markdown/
config.rs

1//! Configuration for markdown rendering
2
3use blinc_core::Color;
4use blinc_theme::{ColorToken, ThemeState};
5
6/// Configuration for markdown rendering
7#[derive(Clone, Debug)]
8pub struct MarkdownConfig {
9    // Typography sizes
10    /// H1 heading size
11    pub h1_size: f32,
12    /// H2 heading size
13    pub h2_size: f32,
14    /// H3 heading size
15    pub h3_size: f32,
16    /// H4 heading size
17    pub h4_size: f32,
18    /// H5 heading size
19    pub h5_size: f32,
20    /// H6 heading size
21    pub h6_size: f32,
22    /// Body text size
23    pub body_size: f32,
24    /// Code text size
25    pub code_size: f32,
26
27    // Colors
28    /// Primary text color
29    pub text_color: Color,
30    /// Secondary text color (for muted content)
31    pub text_secondary: Color,
32    /// Link text color
33    pub link_color: Color,
34    /// Code background color
35    pub code_bg: Color,
36    /// Code text color
37    pub code_text: Color,
38    /// Blockquote border color
39    pub blockquote_border: Color,
40    /// Blockquote background color
41    pub blockquote_bg: Color,
42    /// Horizontal rule color
43    pub hr_color: Color,
44
45    // Spacing
46    /// Spacing between paragraphs
47    pub paragraph_spacing: f32,
48    /// Spacing after headings
49    pub heading_spacing: f32,
50    /// List item indent
51    pub list_indent: f32,
52    /// List item spacing
53    pub list_item_spacing: f32,
54    /// Blockquote padding
55    pub blockquote_padding: f32,
56    /// Code block padding
57    pub code_padding: f32,
58    /// List marker width (space reserved for bullet/number)
59    pub list_marker_width: f32,
60    /// List marker gap (space between marker and content)
61    pub list_marker_gap: f32,
62}
63
64impl Default for MarkdownConfig {
65    fn default() -> Self {
66        let theme = ThemeState::get();
67        Self {
68            // Typography
69            h1_size: 32.0,
70            h2_size: 28.0,
71            h3_size: 24.0,
72            h4_size: 20.0,
73            h5_size: 18.0,
74            h6_size: 16.0,
75            body_size: 16.0,
76            code_size: 14.0,
77
78            // Colors from theme
79            text_color: theme.color(ColorToken::TextPrimary),
80            text_secondary: theme.color(ColorToken::TextSecondary),
81            link_color: theme.color(ColorToken::TextLink),
82            code_bg: theme.color(ColorToken::SurfaceOverlay),
83            code_text: theme.color(ColorToken::TextPrimary),
84            blockquote_border: theme.color(ColorToken::Border),
85            blockquote_bg: theme.color(ColorToken::SurfaceOverlay),
86            hr_color: theme.color(ColorToken::Border),
87
88            // Spacing
89            paragraph_spacing: 16.0,
90            heading_spacing: 24.0,
91            list_indent: 0.0,
92            list_item_spacing: 4.0,
93            blockquote_padding: 16.0,
94            code_padding: 12.0,
95            list_marker_width: 12.0,
96            list_marker_gap: 4.0,
97        }
98    }
99}
100
101impl MarkdownConfig {
102    /// Create a new config with theme defaults
103    pub fn new() -> Self {
104        Self::default()
105    }
106
107    /// Create a light theme config suitable for white backgrounds
108    /// Uses the global ThemeState for colors
109    pub fn light() -> Self {
110        let theme = ThemeState::get();
111        Self {
112            // Typography - slightly smaller for tighter layout
113            h1_size: 24.0,
114            h2_size: 20.0,
115            h3_size: 17.0,
116            h4_size: 15.0,
117            h5_size: 14.0,
118            h6_size: 13.0,
119            body_size: 14.0,
120            code_size: 13.0,
121
122            // Colors from global theme
123            text_color: theme.color(ColorToken::TextPrimary),
124            text_secondary: theme.color(ColorToken::TextSecondary),
125            link_color: theme.color(ColorToken::TextLink),
126            code_bg: theme.color(ColorToken::SurfaceOverlay),
127            code_text: theme.color(ColorToken::TextPrimary),
128            blockquote_border: theme.color(ColorToken::Border),
129            blockquote_bg: theme.color(ColorToken::SurfaceOverlay),
130            hr_color: theme.color(ColorToken::Border),
131
132            // Tight spacing
133            paragraph_spacing: 6.0,
134            heading_spacing: 8.0,
135            list_indent: 0.0,
136            list_item_spacing: 4.0,
137            blockquote_padding: 8.0,
138            code_padding: 8.0,
139            list_marker_width: 12.0,
140            list_marker_gap: 4.0,
141        }
142    }
143
144    /// Set the body text size
145    pub fn body_size(mut self, size: f32) -> Self {
146        self.body_size = size;
147        self
148    }
149
150    /// Set the link color
151    pub fn link_color(mut self, color: Color) -> Self {
152        self.link_color = color;
153        self
154    }
155
156    /// Set the text color
157    pub fn text_color(mut self, color: Color) -> Self {
158        self.text_color = color;
159        self
160    }
161
162    /// Set paragraph spacing
163    pub fn paragraph_spacing(mut self, spacing: f32) -> Self {
164        self.paragraph_spacing = spacing;
165        self
166    }
167
168    /// Set blockquote background color
169    pub fn blockquote_bg(mut self, color: Color) -> Self {
170        self.blockquote_bg = color;
171        self
172    }
173
174    /// Set blockquote border color
175    pub fn blockquote_border(mut self, color: Color) -> Self {
176        self.blockquote_border = color;
177        self
178    }
179}