use regex::Regex; /// Convert the Xpath selectors to CSS selector /// /// ## Things it supports /// Any tag (including *), contains(), text(), indexed, any attribute (@id, @class, @anything). /// /// ## Things it does not support /// Move up to a parent tag (//a/../p) and maybe something else I'm not aware of... /// /// ## Examples /// /// Basic usage: /// ``` /// let result = cssifier::cssifier("//a/p"); /// assert_eq!(result, Some("a p".to_string())); /// /// let result = cssifier::cssifier("//a/p[@id='hello']"); /// assert_eq!(result, Some("a p#hello".to_string())); /// /// let result = cssifier::cssifier("//a/p[contains(text(), 'hello')]"); /// assert_eq!(result, Some("a p:contains(hello)".to_string())); /// /// let result = cssifier::cssifier("*random selector//*"); // Invalid selectors throw a empty string (WIP) /// assert_eq!(result, Some("".to_string())); /// ``` pub fn cssifier>(xpath: S) -> Option { // Trait to &str let xpath = xpath.as_ref(); // Ultra magic regex to parse XPath selectors let reg = Regex::new(r#"(?P(^id\(["']?(?P\s*[\w/:][-/\w\s,:;.]*)["']?\)|(?P