New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vCard/JSON extraction #19443
vCard/JSON extraction #19443
Changes from 1 commit
eb2c7e0
015ef37
43aeb7c
f306835
0530512
f939632
3d68d2a
a4ed961
4628943
cbfc666
146dd58
9284187
dd4dc70
43650c2
19408a0
79d140d
aab6900
35468f8
8cafd64
87d1efa
c580c3f
3cd9731
d0cb12e
0ae2d08
7131823
a3e5b9f
0e5023d
37f70c6
543de1c
a781bba
04a043d
c740aab
File filter...
Jump to…
Removed JSON code and replaced with a stub
- Loading branch information
| @@ -17,19 +17,9 @@ use std::borrow::Cow; | ||
| use std::collections::HashMap; | ||
|
|
||
| pub struct Microdata {} | ||
|
||
| #[derive(Clone,Serialize)] | ||
| #[serde(untagged)] | ||
| enum Data { | ||
| StrValue(String), | ||
| VecValue(Vec<Data>), | ||
| DataValue(Box<Data>), | ||
| HashValue(HashMap<String, Data>) | ||
| } | ||
|
|
||
| impl Microdata { | ||
| //[Pref="dom.microdata.testing.enabled"] | ||
| pub fn parse(doc: &Document, node: &Node) -> HashMap<String, String> { | ||
jdm
Member
|
||
| //let dup_doc = Cow::Borrowed(doc); | ||
| let serialized_vcard = Self::parse_vcard(doc); | ||
| let serialized_json = Self::parse_json(node); | ||
| let mut serialized_data: HashMap<String, String> = HashMap::new(); | ||
| @@ -165,70 +155,7 @@ impl Microdata { | ||
| } | ||
|
|
||
| pub fn parse_json(node: &Node) -> String { | ||
| let json_data: Data = Self::traverse(node).unwrap(); | ||
| let json = serde_json::to_string(&json_data); | ||
| //println!("printing json from microdata {:?}", json); | ||
| //return json.ok().unwrap(); | ||
|
|
||
| // TODO Write the logic for JSON Parsing | ||
| return "".to_string(); | ||
| } | ||
|
|
||
| fn get_attr_value(element: &Element, property: &str) -> Option<String> { | ||
| println!("{:?}", property); | ||
| // let mut atoms = match property { | ||
| // "itemprop" => element.get_tokenlist_attribute(&local_name!("itemprop"), ), | ||
| // "itemtype" => element.get_tokenlist_attribute(&local_name!("itemtype"), ), | ||
| // _ => {}, | ||
| // }; | ||
| // if !atoms.is_empty() { | ||
| // let temp_key = atoms.remove(0); | ||
| // return Some(String::from(temp_key.trim()).to_owned()); | ||
| // } | ||
| // else { | ||
| // return None; | ||
| // } | ||
| Some(String::from("itemprop")) | ||
| } | ||
|
|
||
| fn traverse(node: &Node) -> Option<Data> { | ||
| if !node.is::<Element>() { | ||
| if let Some(ref text) = node.downcast::<Text>() { | ||
| let mut content = String::new(); | ||
| content.push_str(&text.upcast::<CharacterData>().data()); | ||
| return Some(Data::StrValue(String::from(content))); | ||
| } | ||
| None | ||
| } else { | ||
| let element = node.downcast::<Element>().unwrap(); | ||
| let mut head_str = String::from(""); | ||
| let mut parent_vec: Vec<Data> = Vec::new(); | ||
| let item_type = Self::get_attr_value(element, "itemtype").unwrap(); | ||
| // if element.has_attribute(&local_name!("itemscope")) && | ||
| // element.has_attribute(&local_name!("itemtype")) && | ||
| // !element.has_attribute(&local_name!("itemprop")) { | ||
| // head_str = String::from("items"); | ||
| // let mut propMap:HashMap<String,Data> = HashMap::new(); | ||
| // //Data::HashValue(propMap) | ||
| // let item_type = Self::get_attr_value(element,"item_type").unwrap(); | ||
|
|
||
| // } | ||
| // else if element.has_attribute(&local_name!("itemprop")) && | ||
| // element.has_attribute(&local_name!("item_type")) { | ||
|
|
||
| // head_str = Self::get_attr_value(element,"itemprop").unwrap(); | ||
| // let item_type = Self::get_attr_value(element,"item_type").unwrap(); | ||
|
|
||
| // } else { | ||
| // return None; | ||
| // } | ||
| let mut inner_map: HashMap<String, Data> = HashMap::new(); | ||
| for child in node.children() { | ||
| if let Some(childData) = Self::traverse(child.upcast::<Node>()) { | ||
| parent_vec.push(childData); | ||
| } | ||
| } | ||
| inner_map.insert(head_str, Data::VecValue(parent_vec)); | ||
| Some(Data::HashValue(inner_map)) | ||
| } | ||
| } | ||
| } | ||
Rather than an empty structure with static methods, we should use plain old functions in this file instead. Code in other modules can use
microdata::parseinstead.