feedparser_rs/namespace/
content.rs1use crate::types::{Content, Entry};
13
14pub const CONTENT_NAMESPACE: &str = "http://purl.org/rss/1.0/modules/content/";
16
17pub fn handle_entry_element(element: &str, text: &str, entry: &mut Entry) {
25 if element == "encoded" {
26 entry.content.push(Content {
28 value: text.to_string(),
29 content_type: Some("text/html".into()),
30 language: None,
31 base: None,
32 });
33 }
34}
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39
40 #[test]
41 fn test_content_encoded() {
42 let mut entry = Entry::default();
43 let html = r"<p>Full HTML content with <strong>formatting</strong>.</p>";
44
45 handle_entry_element("encoded", html, &mut entry);
46
47 assert_eq!(entry.content.len(), 1);
48 assert_eq!(entry.content[0].value, html);
49 assert_eq!(entry.content[0].content_type.as_deref(), Some("text/html"));
50 }
51
52 #[test]
53 fn test_multiple_content_encoded() {
54 let mut entry = Entry::default();
55
56 handle_entry_element("encoded", "<p>First content</p>", &mut entry);
57 handle_entry_element("encoded", "<p>Second content</p>", &mut entry);
58
59 assert_eq!(entry.content.len(), 2);
60 }
61
62 #[test]
63 fn test_content_with_cdata() {
64 let mut entry = Entry::default();
65 let html = r"<p>Content from <![CDATA[...]]></p>";
67
68 handle_entry_element("encoded", html, &mut entry);
69
70 assert!(!entry.content.is_empty());
71 }
72
73 #[test]
74 fn test_ignore_unknown_elements() {
75 let mut entry = Entry::default();
76
77 handle_entry_element("unknown", "test", &mut entry);
78
79 assert!(entry.content.is_empty());
80 }
81}