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 first text
"#) ); Ok(()) } #[test] fn append_two_divs_to_first_p_content() -> Result<(), StreamingEditorError> { let command = "EXTRACT-ELEMENT{#first-para} | APPEND-ELEMENT{ CREATE-ELEMENT{div} } | APPEND-ELEMENT{ CREATE-ELEMENT{div} }"; 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(()) } #[test] fn append_div_with_attr_to_first_p_content() -> Result<(), StreamingEditorError> { let command = "EXTRACT-ELEMENT{#first-para} | APPEND-ELEMENT{ CREATE-ELEMENT{div} | SET-ATTR{id ↤ 'new'} }"; 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(()) } #[test] fn copy_title_to_meta_tag() -> Result<(), StreamingEditorError> { let command = "FOR-EACH{head ↦ APPEND-ELEMENT{ ↤ CREATE-ELEMENT{meta} | SET-ATTR{name ↤ 'title' } } | FOR-EACH{meta[name='title'] ↦ SET-ATTR{content ↤ QUERY-PARENT{title} | GET-TEXT-CONTENT } } }"; let mut input = Box::new( r#"