@@ -2,6 +2,8 @@
22{-# LANGUAGE DeriveGeneric #-}
33{-# LANGUAGE LambdaCase #-}
44
5+{-# OPTIONS_GHC -O2 #-}
6+
57-- | This is a performance-oriented HTML tokenizer aim at web-crawling
68-- applications. It follows the HTML5 parsing specification quite closely,
79-- so it behaves reasonable well on ill-formed documents from the open Web.
@@ -176,9 +178,10 @@ attrName tag attrs = do
176178 <|> (char '=' >> beforeAttrValue tag attrs name)
177179 <|> try (do mc <- peekChar
178180 case mc of
179− Just c | inClass "\x09\x0a\x0c />" c -> afterAttrName tag attrs name
181+ Just c | notNameChar c -> afterAttrName tag attrs name
180182 _ -> empty)
181183 -- <|> -- TODO: NULL
184+ where notNameChar = isWhitespace `orC` isC '/' `orC` isC '>'
182185
183186-- | /§8.2.4.34/: After attribute name state
184187afterAttrName :: TagName -> [Attr] -> AttrName -> Parser Token
@@ -216,7 +219,7 @@ attrValueSQuoted tag attrs name = do
216219-- | /§8.2.4.38/: Attribute value (unquoted) state
217220attrValueUnquoted :: TagName -> [Attr] -> AttrName -> Parser Token
218221attrValueUnquoted tag attrs name = do
219− value <- takeTill (inClass "\x09\x0a\x0c >")
222+ value <- takeTill $ isWhitespace `orC` isC '>'
220223 id $ (satisfy isWhitespace >> beforeAttrName tag attrs) -- unsure: don't emit?
221224 <|> (char '>' >> return (TagOpen tag (Attr name value : attrs)))
222225 <|> (endOfInput >> return endOfFileToken)