HandsomeSoup 0.1 → 0.2
raw patch · 3 files changed
+23/−6 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- HandsomeSoup.cabal +1/−1
- README.markdown +15/−1
- Text/HandsomeSoup.hs +7/−4
HandsomeSoup.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version: 0.1+Version: 0.2 -- A short (one-line) description of the package. Synopsis: Work with HTML more easily in HXT
README.markdown view
@@ -1,6 +1,6 @@ # HandsomeSoup -Current Status: very very pre-alpha. Usable but buggy.+Current Status: Usable but untested (tests coming soon! See todo list). HandsomeSoup is the library I wish I had when I started parsing HTML in Haskell. @@ -8,6 +8,10 @@ Most importantly, it adds CSS selectors to HXT. The goal of HandsomeSoup is to be a complete CSS2 parser for HXT (it is very close to this right now). +## Install++ cabal install HandsomeSoup+ ## Example [Nokogiri](http://nokogiri.org/), the HTML parser for Ruby, has an example showing how to scrape Google search results. This is easy in HandsomeSoup:@@ -46,3 +50,13 @@ doc <<< css "img" ! "src" doc <<< css "a" ! "href"++## Docs++Find [Haddock docs on Hackage](http://hackage.haskell.org/package/HandsomeSoup).++I also wrote [The Complete Guide To Parsing HXT With Haskell](http://adit.io/posts/2012-04-14-working_with_HTML_in_haskell.html).++## Credits++Made by [Adit](http://adit.io).
Text/HandsomeSoup.hs view
@@ -59,12 +59,15 @@ _fromSelectors (s:selectors) = foldl (\acc selector -> make acc selector) (make this s) selectors where make acc sel@(Selector name attrs pseudo)- | name == "*" = acc >>> (multi this >>> makeAttrs attrs)- | otherwise = acc >>> (multi $ hasName name >>> makeAttrs attrs)- make acc Space = acc >>> multi getChildren- make acc ChildOf = acc >>> getChildren+ | name == "*" = acc >>> ((multi this >>> makeAttrs attrs) >>. makePseudos pseudo)+ | otherwise = acc >>> ((multi $ hasName name >>> makeAttrs attrs) >>. makePseudos pseudo)+ make acc Space = acc >>> getChildren+ make acc ChildOf = acc >>> getChildren >>> processChildren none makeAttrs (a:attrs) = foldl (\acc attr -> acc >>> makeAttr attr) (makeAttr a) attrs makeAttrs [] = this makeAttr (name, "") = hasAttr name makeAttr (name, '~':value) = hasAttrValue name (elem value . words) makeAttr (name, value) = hasAttrValue name (==value)+ makePseudos (p:pseudos) = foldl (\acc pseudo -> acc >>> makePseudo pseudo) (makePseudo p) pseudos+ makePseudos [] = id+ makePseudo "first-child" = take 1