Skip to main content

ppt_rs/web2ppt/
config.rs

1//! Configuration for Web2PPT conversion
2
3/// Configuration options for web2ppt conversion
4#[derive(Clone, Debug)]
5pub struct Web2PptConfig {
6    /// Maximum number of slides to generate
7    pub max_slides: usize,
8    /// Maximum bullets per slide
9    pub max_bullets_per_slide: usize,
10    /// Include images from the webpage
11    pub include_images: bool,
12    /// Include tables from the webpage
13    pub include_tables: bool,
14    /// Include code blocks
15    pub include_code: bool,
16    /// User agent for HTTP requests
17    pub user_agent: String,
18    /// Request timeout in seconds
19    pub timeout_secs: u64,
20    /// Title font size
21    pub title_font_size: u32,
22    /// Content font size
23    pub content_font_size: u32,
24    /// Extract links as hyperlinks
25    pub extract_links: bool,
26    /// Group content by headings
27    pub group_by_headings: bool,
28}
29
30impl Default for Web2PptConfig {
31    fn default() -> Self {
32        Web2PptConfig {
33            max_slides: 20,
34            max_bullets_per_slide: 6,
35            include_images: true,
36            include_tables: true,
37            include_code: true,
38            // Use a realistic browser user agent
39            user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36".to_string(),
40            timeout_secs: 30,
41            title_font_size: 44,
42            content_font_size: 24,
43            extract_links: true,
44            group_by_headings: true,
45        }
46    }
47}
48
49impl Web2PptConfig {
50    /// Create a new config with defaults
51    pub fn new() -> Self {
52        Self::default()
53    }
54
55    /// Set maximum slides
56    pub fn max_slides(mut self, max: usize) -> Self {
57        self.max_slides = max;
58        self
59    }
60
61    /// Set maximum bullets per slide
62    pub fn max_bullets(mut self, max: usize) -> Self {
63        self.max_bullets_per_slide = max;
64        self
65    }
66
67    /// Enable/disable images
68    pub fn with_images(mut self, include: bool) -> Self {
69        self.include_images = include;
70        self
71    }
72
73    /// Enable/disable tables
74    pub fn with_tables(mut self, include: bool) -> Self {
75        self.include_tables = include;
76        self
77    }
78
79    /// Enable/disable code blocks
80    pub fn with_code(mut self, include: bool) -> Self {
81        self.include_code = include;
82        self
83    }
84
85    /// Set custom user agent
86    pub fn user_agent(mut self, ua: &str) -> Self {
87        self.user_agent = ua.to_string();
88        self
89    }
90
91    /// Set request timeout
92    pub fn timeout(mut self, secs: u64) -> Self {
93        self.timeout_secs = secs;
94        self
95    }
96
97    /// Set title font size
98    pub fn title_size(mut self, size: u32) -> Self {
99        self.title_font_size = size;
100        self
101    }
102
103    /// Set content font size
104    pub fn content_size(mut self, size: u32) -> Self {
105        self.content_font_size = size;
106        self
107    }
108
109    /// Enable/disable link extraction
110    pub fn with_links(mut self, extract: bool) -> Self {
111        self.extract_links = extract;
112        self
113    }
114
115    /// Enable/disable grouping by headings
116    pub fn group_by_headings(mut self, group: bool) -> Self {
117        self.group_by_headings = group;
118        self
119    }
120}
121
122#[cfg(test)]
123mod tests {
124    use super::*;
125
126    #[test]
127    fn test_default_config() {
128        let config = Web2PptConfig::default();
129        assert_eq!(config.max_slides, 20);
130        assert_eq!(config.max_bullets_per_slide, 6);
131        assert!(config.include_images);
132    }
133
134    #[test]
135    fn test_config_builder() {
136        let config = Web2PptConfig::new()
137            .max_slides(10)
138            .max_bullets(4)
139            .with_images(false);
140        
141        assert_eq!(config.max_slides, 10);
142        assert_eq!(config.max_bullets_per_slide, 4);
143        assert!(!config.include_images);
144    }
145}