add readme file

master
kirbylife 2021-03-07 19:48:08 -06:00
parent 45d9bd306b
commit 45183697de
2 changed files with 27 additions and 1 deletions

26
README.md 100644
View File

@ -0,0 +1,26 @@
# CSSIFIER_RS
## Simple crate to convert XPath selectors to CSS selectors
based on [cssify](https://github.com/santiycr/cssify) but rewrited in Rust (RiiR f4w).
### dependencies:
- [Regex](https://crates.io/crates/regex)
### Usage
The usage is simple:
```
cssifier("//a/b")
// Some("a b")
cssifier("//a/b[@id='hello']")
// Some(a b#hello)
cssifier("//a/b[contains(text(), 'hello')]")
// Some(a b:contains(hello))
```
### Known issues
[ ] invalid XPath selectors panic
Contributors are welcome :).

View File

@ -1,6 +1,6 @@
use regex::Regex;
fn cssifier(xpath: &'static str) -> Option<String> {
pub fn cssifier(xpath: &'static str) -> Option<String> {
// Ultra magic regex to parse XPath selectors
let reg = Regex::new(r#"(?P<node>(^id\(["']?(?P<idvalue>\s*[\w/:][-/\w\s,:;.]*)["']?\)|(?P<nav>//?)(?P<tag>([a-zA-Z][a-zA-Z0-9]{0,10}|\*))(\[((?P<matched>(?P<mattr>@?[.a-zA-Z_:][-\w:.]*(\(\))?)=["'](?P<mvalue>\s*[\w/:][-/\w\s,:;.]*))["']|(?P<contained>contains\((?P<cattr>@?[.a-zA-Z_:][-\w:.]*(\(\))?),\s*["'](?P<cvalue>\s*[\w/:][-/\w\s,:;.]*)["']\)))\])?(\[(?P<nth>\d)\])?))"#).unwrap();
let mut css = String::new();