From 76b4a15aff47369d75ba7b3e7031dca98b41ed3c Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Tue, 4 May 2021 13:25:45 -0300 Subject: [PATCH] Almost there... --- html5test/src/main.rs | 47 +++++++++---------------------------------- 1 file changed, 10 insertions(+), 37 deletions(-) diff --git a/html5test/src/main.rs b/html5test/src/main.rs index d088f63..fd947fd 100644 --- a/html5test/src/main.rs +++ b/html5test/src/main.rs @@ -18,28 +18,6 @@ macro_rules! keep_going { }; } -// fn handle_anchor(node: &mut Node, attrs: &RefCell>) -> HandleResult { -// let attrs = attrs.borrow(); -// let rels = attrs -// .iter() -// .find(|attr| attr.name.local.to_string() == "rel"); -// let hrefs = attrs -// .iter() -// .find(|attr| attr.name.local.to_string() == "href"); -// match (rels, hrefs) { -// (Some(rel), Some(href)) => { -// if !rel.value.to_string().contains("tag") { -// let new_node = Node::link(&href.value); -// node.add_child(new_node); -// HandleResult::NewNode(new_node) -// } else { -// HandleResult::Keep -// } -// } -// _ => HandleResult::Stop, -// } -// } - fn walk(input: &Handle, result: &mut String) { match input.data { NodeData::Text { ref contents } => { @@ -66,7 +44,10 @@ fn walk(input: &Handle, result: &mut String) { .find(|attr| attr.name.local.to_string() == "class"); match classes_attr { Some(classes) => { - if !classes.value.contains("invisible") { + if classes.value.contains("ellipsis") { + keep_going!(input, result); + result.push_str("..."); + } else if !classes.value.contains("invisible") { keep_going!(input, result); } } @@ -81,7 +62,6 @@ fn walk(input: &Handle, result: &mut String) { let hrefs = attrs .iter() .find(|attr| attr.name.local.to_string() == "href"); - println!("Rels: {:?}, Hrefs: {:?}", rels, hrefs); match (rels, hrefs) { (Some(rel), Some(href)) => { if !rel.value.to_string().contains("tag") { @@ -107,13 +87,14 @@ fn walk(input: &Handle, result: &mut String) { } fn build_nodes(source: &str) { + println!("Source: {}", source); let dom = parse_document(RcDom::default(), Default::default()) .from_utf8() .read_from(&mut source.as_bytes()) .unwrap(); let mut result = String::new(); walk(&dom.document, &mut result); - println!("Result: {:?}", result); + println!("Result: {}", result); } fn main() { @@ -130,16 +111,8 @@ fn main() { ); build_nodes(&example_3); - // let example_1 = String::from( - // r#"

Today I finally moved with my contact and calendar management into the terminal with #vdirsyncer #khal and #khard.

Thank you @hund for your great post: hund.tty1.se/2020/08/12/how-to

#carddav #caldav #terminal

"#, - // ); - // println!("Source: {}", &example_1); - // println!("---------------------------------"); - - // let dom = parse_document(RcDom::default(), Default::default()) - // .from_utf8() - // .read_from(&mut example_1.as_bytes()) - // .unwrap(); - // let mut tree = Node::root(); - // walk(&dom.document, &mut tree); + let example_full_1 = String::from( + r#"

Today I finally moved with my contact and calendar management into the terminal with #vdirsyncer #khal and #khard.

Thank you @hund for your great post: hund.tty1.se/2020/08/12/how-to

#carddav #caldav #terminal

"#, + ); + build_nodes(&example_full_1); }