use node_html_parser::{parse_with_options, Node, Options};
#[test]
fn issue_203_code_not_none_in_block_text_elements() {
let html = "<pre><code class=\"language-js\">const a = 1;</code></pre>";
let mut opts = Options::default();
opts.block_text_elements.remove("pre");
let mut root = parse_with_options(html, &opts);
fn find_code<'a>(
el: &'a mut node_html_parser::HTMLElement,
) -> Option<&'a mut node_html_parser::HTMLElement> {
for child in el.children.iter_mut() {
if let Node::Element(e) = child {
if e.name() == "code" {
return Some(e);
}
if let Some(found) = find_code(e) {
return Some(found);
}
}
}
None
}
let pre = root.first_element_child_mut().unwrap();
let code_el = find_code(pre).expect("code element present");
assert_eq!(code_el.get_attribute("class"), Some("language-js".into()));
}