1#[derive(Clone, Debug)]
5pub struct Web2PptConfig {
6 pub max_slides: usize,
8 pub max_bullets_per_slide: usize,
10 pub include_images: bool,
12 pub include_tables: bool,
14 pub include_code: bool,
16 pub user_agent: String,
18 pub timeout_secs: u64,
20 pub title_font_size: u32,
22 pub content_font_size: u32,
24 pub extract_links: bool,
26 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 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 pub fn new() -> Self {
52 Self::default()
53 }
54
55 pub fn max_slides(mut self, max: usize) -> Self {
57 self.max_slides = max;
58 self
59 }
60
61 pub fn max_bullets(mut self, max: usize) -> Self {
63 self.max_bullets_per_slide = max;
64 self
65 }
66
67 pub fn with_images(mut self, include: bool) -> Self {
69 self.include_images = include;
70 self
71 }
72
73 pub fn with_tables(mut self, include: bool) -> Self {
75 self.include_tables = include;
76 self
77 }
78
79 pub fn with_code(mut self, include: bool) -> Self {
81 self.include_code = include;
82 self
83 }
84
85 pub fn user_agent(mut self, ua: &str) -> Self {
87 self.user_agent = ua.to_string();
88 self
89 }
90
91 pub fn timeout(mut self, secs: u64) -> Self {
93 self.timeout_secs = secs;
94 self
95 }
96
97 pub fn title_size(mut self, size: u32) -> Self {
99 self.title_font_size = size;
100 self
101 }
102
103 pub fn content_size(mut self, size: u32) -> Self {
105 self.content_font_size = size;
106 self
107 }
108
109 pub fn with_links(mut self, extract: bool) -> Self {
111 self.extract_links = extract;
112 self
113 }
114
115 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}