Latest | 1.2.3 |
---|---|
Homepage | https://github.com/siuying/CSSSelectorConverter |
License | MIT |
Platforms | ios 6.0, osx 10.8, requires ARC |
Dependencies | CocoaLumberjack, NUIParse |
Authors |
CSS Selector Converter
A CSS Selector to XPath Selector for Objective-C. Support mostly used subset of CSS Selector Level 3.
I build this converter so that I can use .class
instead of //*[contains(concat(' ', normalize-space(@class), ' '), ' class ')]
in IGHTMLQuery.
Usage
#import "CSSSelectorConverter.h"
CSSSelectorToXPathConverter* converter = [[CSSSelectorToXPathConverter alloc] init];
[converter xpathWithCSS:@"p" error:nil];
// => "//p"
[converter xpathWithCSS:@"p.intro" error:nil];
// => "//p[contains(concat(' ', normalize-space(@class), ' '), ' intro ')]"
Status
It supports following CSS Selectors:
* "//*"
p "//p"
p.intro "//p[contains(concat(' ', normalize-space(@class), ' '), ' intro ')]"
p#apple "//p[@id = 'apple']"
p * "//p//*"
p > * "//p/*"
H1 + P "//H1/following-sibling::*[1]/self::P"
H1 ~ P "//H1/following-sibling::P"
ul, ol "//ul | //ol"
p[align] "//p[@align]"
p[class~="intro"] "//p[contains(concat(" ", @class, " "),concat(" ", 'intro', " "))]"
div[att|="val"] "//div[@att = "val" or starts-with(@att, concat("val", '-'))]"
It supports following pseduo classes:
- first-child
- last-child
- first-of-type
- last-of-type
- only-child
- only-of-type
- empty
Currently pseduo classes with parameters are not supported (I probably will not implement them until I really NEEDS them):
- nth-child()
- nth-last-child()
- nth-of-type()
- nth-last-of-type()
- not()
Following pseduo classes will not be supported:
- Dynamic pseudo classes (:link, :visied, :hover … etc)
- UI elements states pseudo-classes (:enabled, :checked, :indeterminate)
- :target
- :lang
- :root
Development
Building the project
- Install cocoapods
- Install pods:
pod install
License
MIT License. See License.txt.
Latest podspec
{ "name": "CSSSelectorConverter", "version": "1.2.3", "license": "MIT", "summary": "Objective-C/Cocoa String Tokenizer and Parser toolkit. Supports Grammars.", "homepage": "https://github.com/siuying/CSSSelectorConverter", "authors": { "Francis Chong": "[email protected]" }, "source": { "git": "https://github.com/siuying/CSSSelectorConverter.git", "tag": "1.2.3" }, "description": "A CSS Selector to XPath Selector for Objective-C. Support mostly used subset of CSS Selector Level 3.", "platforms": { "ios": "6.0", "osx": "10.8" }, "dependencies": { "CocoaLumberjack": [ "~> 2.0.0" ], "NUIParse": [] }, "requires_arc": true, "public_header_files": [ "CSSSelectorConverter/CSSSelectorConverter.h", "CSSSelectorConverter/CSSSelectorToXPathConverter.h" ], "source_files": "CSSSelectorConverter/CSS*.{m,h}", "prefix_header_contents": "#import "CSSSelectorConverter.h"", "resources": [ "CSSSelectorConverter/*.{txt}", "CSSSelectorConverter/CSSSelectorParser.plist" ] }
Sun, 06 Mar 2016 12:50:04 +0000