5 import Text.HTML.TagSoup.Entity (lookupEntity)
7 replace_entities :: String -> String
8 replace_entities [] = []
9 replace_entities ('&':xs) =
10 let (b, a) = break (== ';') xs in
11 case (lookupEntity b, a) of
12 (Just c, ';':as) -> c : replace_entities as
13 _ -> '&' : replace_entities xs
14 replace_entities (x:xs) = x : replace_entities xs
18 html_tests = [ test_replace_entities ]
20 test_replace_entities :: Test
21 test_replace_entities =
22 TestCase $ assertEqual description expected_text actual_text
24 description = "All entities are replaced correctly."
27 ""The moon is gay……" " ++
28 "said <insert the current president of the " ++
29 "United States of America>. “It’s " ++
30 "OK—–he’s not a real doctor.”"
32 "\"The moon is gay……\" said <insert " ++
33 "the current president of the United States of America>. " ++
34 "“It’s OK—–he’s not a real doctor.”"