html_to_markdown_rs/options/
inline_image.rs1#[derive(Debug, Clone)]
11pub struct InlineImageConfig {
12 pub keep_inline_images_in: Vec<String>,
14}
15
16impl InlineImageConfig {
17 #[must_use]
19 pub const fn new() -> Self {
20 Self {
21 keep_inline_images_in: Vec::new(),
22 }
23 }
24
25 #[must_use]
31 pub const fn from_elements(elements: Vec<String>) -> Self {
32 Self {
33 keep_inline_images_in: elements,
34 }
35 }
36
37 pub fn add_element(&mut self, element: String) {
43 self.keep_inline_images_in.push(element);
44 }
45
46 #[must_use]
56 pub fn should_keep_images(&self, element: &str) -> bool {
57 self.keep_inline_images_in.iter().any(|e| e == element)
58 }
59}
60
61impl Default for InlineImageConfig {
62 fn default() -> Self {
63 Self::new()
64 }
65}
66
67#[cfg(test)]
68mod tests {
69 use super::*;
70
71 #[test]
72 fn test_inline_image_config_new() {
73 let config = InlineImageConfig::new();
74 assert_eq!(config.keep_inline_images_in.len(), 0);
75 }
76
77 #[test]
78 fn test_inline_image_config_from_elements() {
79 let elements = vec!["p".to_string(), "div".to_string()];
80 let config = InlineImageConfig::from_elements(elements);
81 assert_eq!(config.keep_inline_images_in.len(), 2);
82 assert!(config.should_keep_images("p"));
83 assert!(config.should_keep_images("div"));
84 assert!(!config.should_keep_images("span"));
85 }
86
87 #[test]
88 fn test_inline_image_config_add_element() {
89 let mut config = InlineImageConfig::new();
90 config.add_element("p".to_string());
91 config.add_element("div".to_string());
92
93 assert_eq!(config.keep_inline_images_in.len(), 2);
94 assert!(config.should_keep_images("p"));
95 assert!(config.should_keep_images("div"));
96 }
97
98 #[test]
99 fn test_inline_image_config_should_keep_images() {
100 let config = InlineImageConfig::from_elements(vec!["figure".to_string()]);
101 assert!(config.should_keep_images("figure"));
102 assert!(!config.should_keep_images("p"));
103 }
104
105 #[test]
106 fn test_inline_image_config_default() {
107 let config = InlineImageConfig::default();
108 assert_eq!(config.keep_inline_images_in.len(), 0);
109 assert!(!config.should_keep_images("p"));
110 }
111}