Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed too strict parsers for id and class attributes

  • Loading branch information...
commit 800e318146a222c78f61e31572e940206c2ebfd1 1 parent 9bdda01
Dmitry Vyal authored
Showing with 14 additions and 3 deletions.
  1. +1 −1  HandsomeSoup.cabal
  2. +13 −2 Text/CSS/Parser.hs
View
2  HandsomeSoup.cabal
@@ -7,7 +7,7 @@ Name: HandsomeSoup
-- 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.3.1
+Version: 0.3.2
-- A short (one-line) description of the package.
Synopsis: Work with HTML more easily in HXT
View
15 Text/CSS/Parser.hs
@@ -3,6 +3,7 @@ module Text.CSS.Parser where
import Text.Parsec
import qualified Data.Functor.Identity as I
import Data.List
+import Data.Maybe
import Text.CSS.Utils
-- if no tag name was given, sName will be set to '*'
-- attrs are (attr name, attr value).
@@ -27,6 +28,16 @@ pp FollowedBy = "<followed by>"
pp (Selector name attrs pseudo) = show name ++ ":" ++ showMap attrs ++ ", " ++ show pseudo
where showMap m = ("{" ++ (foldl (\acc (k,v) -> acc ++ (show k) ++ ":" ++ (show v) ++ ", ") "" m)) ++ "}"
+{- Some lexeme parsers -}
+ident :: ParsecT [Char] u I.Identity String
+ident = do c1 <- optionMaybe (char '-')
+ c2 <- nmstart
+ cs <- many nmchar
+ return $ concat [maybeToList c1, [c2], cs]
+
+nmstart = alphaNum <|> char '_'
+nmchar = alphaNum <|> oneOf "_-"
+
{- TYPE SELECTORS FOLLOW -}
-- | selects a tag name, like @ h1 @
@@ -46,13 +57,13 @@ pseudoSelector = char ':' >> many1 (alphaNum <|> oneOf "-()")
-- | class selector, selects @ .foo @
classSelector :: ParsecT [Char] u I.Identity ([Char], [Char])
classSelector = do
- val <- char '.' >> many1 alphaNum
+ val <- char '.' >> ident
return ("class", '~':val)
-- | id selector, selects @ #foo @
idSelector :: ParsecT [Char] u I.Identity ([Char], [Char])
idSelector = do
- val <- char '#' >> many1 alphaNum
+ val <- char '#' >> many1 nmchar
return ("id", val)
-- | selects attributes, like @ [id] @ (element must have id) or @ [id=foo] @ (element must have id foo).
Please sign in to comment.
Something went wrong with that request. Please try again.