diff --git a/Cargo.toml b/Cargo.toml index 3cb2130..7cf828f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,12 @@ [package] name = "cssifier" -version = "0.1.1" +version = "0.1.2" authors = ["kirbylife "] license = " GPL-3.0-or-later" readme = "README.md" homepage = "https://gitlab.com/kirbylife/cssifier" repository = "https://gitlab.com/kirbylife/cssifier" +documentation = "https://docs.rs/cssifier" description = "Simple crate to convert XPath selectors to CSS selectors" keywords = ["cssifier", "xpath", "css", "selector"] categories = ["parsing"] diff --git a/README.md b/README.md index ef5b7a6..79fedf3 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ cssifier("//a/b[contains(text(), 'hello')]") ``` ### Known issues +- [x] bug in 'contains' condition - [ ] invalid XPath return empty String +- [ ] Compatible with WASM Contributors are welcome :). diff --git a/src/lib.rs b/src/lib.rs index 708fd65..19daaa6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,29 @@ 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: +/// ``` +/// cssifier("//a/p") +/// Some("a p") +/// +/// cssifier("//a/p[@id='hello']") +/// Some("a b#hello") +/// +/// cssfier("//a/p/[contains(text(), 'hello')]") +/// Some(a b:contains(hello)) +/// +/// cssifier("*random selector//*") // Invalid selectors throw a empty string (WIP) +/// Some("") +/// ``` pub fn cssifier(xpath: &'static str) -> Option { // Ultra magic regex to parse XPath selectors let reg = Regex::new(r#"(?P(^id\(["']?(?P\s*[\w/:][-/\w\s,:;.]*)["']?\)|(?P