use html_streaming_editor::*; const HTML_INPUT: &str = r#"
Some first text
Some more text, even with an
Third text of HTML, but no CSS
Some new, boring text
"#) ); Ok(()) } #[test] fn overwrite_third_p_content() -> Result<(), StreamingEditorError> { let command = "EXTRACT-ELEMENT{#third-para} | SET-TEXT-CONTENT{'Simple Text'}"; let mut input = Box::new(HTML_INPUT.as_bytes()); let hse = HtmlStreamingEditor::new(&mut input); let result = hse.run(command)?; let result_string = result .iter() .map(|n| n.outer_html()) .collect::Simple Text
"#) ); Ok(()) } #[test] fn set_escape_needing_content() -> Result<(), StreamingEditorError> { let command = "EXTRACT-ELEMENT{#first-para} | SET-TEXT-CONTENT{'Some is > others < & you never know which'}"; let mut input = Box::new(HTML_INPUT.as_bytes()); let hse = HtmlStreamingEditor::new(&mut input); let result = hse.run(command)?; let result_string = result .iter() .map(|n| n.outer_html()) .collect::Some is > others < & you never know which
"# ) ); Ok(()) } #[test] fn set_ul_id_as_text_to_first_para() -> Result<(), StreamingEditorError> { let command = "FOR-EACH{#first-para ↦ SET-TEXT-CONTENT{ QUERY-PARENT{ul} | GET-ATTR{id} } }"; let mut input = Box::new(HTML_INPUT.as_bytes()); let hse = HtmlStreamingEditor::new(&mut input); let result = hse.run(command)?; let result_string = result .iter() .map(|n| n.outer_html()) .collect::list
Some more text, even with an
Third text of HTML, but no CSS
Some more text, even with an
Some more text, even with an
Third text of HTML, but no CSS
Some first text
"#) ); Ok(()) } #[test] fn set_text_content_to_adjusted_value_of_text_content() -> Result<(), StreamingEditorError> { let command = r#"EXTRACT-ELEMENT{#first-para} | SET-TEXT-CONTENT{USE-ELEMENT | GET-TEXT-CONTENT | REGEX-REPLACE{ '\s' ↤ '_'}}"#; let mut input = Box::new(HTML_INPUT.as_bytes()); let hse = HtmlStreamingEditor::new(&mut input); let result = hse.run(command)?; let result_string = result .iter() .map(|n| n.outer_html()) .collect::Some_first_text
"#) ); Ok(()) }