git.iko.soy/typeable/html-parse
on master help sign in
Track self-closing tags
commit56f94ecef69fcba430969ff14998370d76839902 authorBen Gamari <ben@smart-cactus.org> dateMon 2 Jan 2017, 13:31 (10 years ago) parent801d861
2 files changed+10−7
Text/HTML/Parser.hs+3−1 tests/Text/HTML/ParserSpec.hs+7−6
Text/HTML/Parser.hs+3−1
@@ -53,6 +53,8 @@ type AttrValue = Text
5353data Token
5454 -- | An opening tag. Attribute ordering is arbitrary.
5555 = TagOpen !TagName [Attr]
56+ -- | A self-closing tag.
57+ | TagSelfClose !TagName [Attr]
5658 -- | A closing tag.
5759 | TagClose !TagName
5860 -- | The content between tags.
@@ -129,7 +131,7 @@ tagName' = do
129131-- | /§8.2.4.43/: Self-closing start tag state
130132selfClosingStartTag :: TagName -> [Attr] -> Parser Token
131133selfClosingStartTag tag attrs = do
132− (char '>' >> return (TagOpen tag attrs))
134+ (char '>' >> return (TagSelfClose tag attrs))
133135 <|> beforeAttrName tag attrs
134136
135137-- | /§8.2.4.34/: Before attribute name state
tests/Text/HTML/ParserSpec.hs+7−6
@@ -24,12 +24,13 @@ import Text.HTML.Parser
2424instance Arbitrary Token where
2525 arbitrary = oneof [validOpen, validClose, validFlat]
2626
27− shrink (TagOpen n as) = TagOpen n <$> shrink as
28− shrink (TagClose _) = []
29− shrink (ContentText _) = []
30− shrink (ContentChar _) = []
31− shrink (Comment b) = Comment . B.fromText <$> (shrink . TL.toStrict . B.toLazyText $ b)
32− shrink (Doctype t) = Doctype <$> shrink t
27+ shrink (TagOpen n as) = TagOpen n <$> shrink as
28+ shrink (TagSelfClose n as) = TagSelfClose n <$> shrink as
29+ shrink (TagClose _) = []
30+ shrink (ContentText _) = []
31+ shrink (ContentChar _) = []
32+ shrink (Comment b) = Comment . B.fromText <$> (shrink . TL.toStrict . B.toLazyText $ b)
33+ shrink (Doctype t) = Doctype <$> shrink t
3334
3435instance Arbitrary Attr where
3536 arbitrary = Attr <$> validXmlAttrName <*> validXmlAttrValue