fn parse_code_snippet(element: scraper::ElementRef) -> Option<String> {
    eprintln!("about to parse code snippet");
    let mut code = String::new();
    for child in element.children() {
        let node = child.value();

        if node.is_element() {
            let element = node.as_element().unwrap();

            match element.name() {
                "span" => {
                    let span_child_node = child.first_child().unwrap();
                    let child_node = span_child_node.value();
                    // This section kinda sucks. I wanted to refactor this into a method for
                    // getting the descendent text but couldn't figure out how to reference
                    // ego_tree::NodeRef in the method signature as it is a dependency of
                    // scraper...
                    if child_node.is_text() {
                        if let Some(text) = child_node.as_text() {
                            code += text;
                        } else {
                            eprintln!("found span with no text... weird {:?}", child_node);
                        }
                    } else {  // Ignore doubly nested spans for now
                        return None;
                    }
                },
                "br" => {
                    code += "\n";
                },
                _ => {
                    eprintln!("element tag not supported");
                }
            }

        } else if node.is_text() {
            let text = node.as_text().unwrap();
            code += text;
        }
    }

    Some(code)
}
/// Given a element containing a code snippet, parse the code from the html
/// elements
Given a element containing a code snippet, parse the code from the html
elements
Given a element containing a code snippet parse the code from the html elements
fn parse_code_snippet(element: scraper::ElementRef) -> Option<String> {
    eprintln!("about to parse code snippet");
    let mut code = String::new();
    for child in element.children() {
        let node = child.value();
        if node.is_element() {
            let element = node.as_element().unwrap();
            match element.name() {
                "span" => {
                    let span_child_node = child.first_child().unwrap();
                    let child_node = span_child_node.value();
                    // This section kinda sucks. I wanted to refactor this into a method for
                    // getting the descendent text but couldn't figure out how to reference
                    // ego_tree::NodeRef in the method signature as it is a dependency of
                    // scraper...
                    if child_node.is_text() {
                        if let Some(text) = child_node.as_text() {
                            code += text;
                        } else {
                            eprintln!("found span with no text... weird {:?}", child_node);
                        }
                    } else {  // Ignore doubly nested spans for now
                        return None;
                    }
                },
                "br" => {
                    code += "\n";
                },
                _ => {
                    eprintln!("element tag not supported");
                }
            }
        } else if node.is_text() {
            let text = node.as_text().unwrap();
            code += text;
        }
    }
    Some(code)
}
fn parse_code_snippet ( element : scraper :: ElementRef ) -> Option < String > { eprintln ! ( " " ) ; let mut code = String :: new ( ) ; for child in element . children ( ) { let node = child . value ( ) ; if node . is_element ( ) { let element = node . as_element ( ) . unwrap ( ) ; match element . name ( ) { " " => { let span_child_node = child . first_child ( ) . unwrap ( ) ; let child_node = span_child_node . value ( ) ; // This section kinda sucks. I wanted to refactor this into a method for // getting the descendent text but couldn't figure out how to reference // ego_tree::NodeRef in the method signature as it is a dependency of // scraper... if child_node . is_text ( ) { if let Some ( text ) = child_node . as_text ( ) { code += text ; } else { eprintln ! ( " " child_node ) ; } } else { // Ignore doubly nested spans for now return None ; } } , " " => { code += " \n " ; } , _ => { eprintln ! ( " " ) ; } } } else if node . is_text ( ) { let text = node . as_text ( ) . unwrap ( ) ; code += text ; } } Some ( code ) }
Given a element containing a code snippet, parse the code from the html
elements
Given a element containing a code snippet parse the code from the html elements
element
scraper::ElementRef
element
scraper::ElementRef