X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fhalcyon.git;a=blobdiff_plain;f=src%2FHtml.hs;fp=src%2FHtml.hs;h=3abd82b037879becf76d8f22bab2c45de50ddd3f;hp=59876a5b5c0e9fd9f782442a7e5232dee4679ca6;hb=1b72ed45ef890ed1329a32457b4d7f3a7fb37788;hpb=0ed071e75268da9ba8273d5c13817fa1297c94e2;ds=sidebyside diff --git a/src/Html.hs b/src/Html.hs index 59876a5..3abd82b 100644 --- a/src/Html.hs +++ b/src/Html.hs @@ -7,6 +7,34 @@ import Test.Tasty ( TestTree, testGroup ) import Test.Tasty.HUnit ( (@?=), testCase ) import Text.HTML.TagSoup.Entity ( lookupEntity ) + +-- | Replace (x)html entities in a 'String'. To do this, we search +-- through the string looking for ampersands which may indicate the +-- beginning of an entity. +-- +-- If we find one and there's a semicolon after it, we attempt to +-- look up the identifier that we found between the ampersand and +-- the semicolon. If an entity is found, we replace the ampersand, +-- semicolon, and everything in between with the entity. However if +-- no corresponding entity is found, we leave everything alone. +-- +-- Examples: +-- +-- >>> replace_entities "Hello, world!" +-- "Hello, world!" +-- +-- >>> replace_entities "Hello; world!" +-- "Hello; world!" +-- +-- >>> replace_entities "Hello, world & other worlds!" +-- "Hello, world & other worlds!" +-- +-- >>> replace_entities "Hello, world & other worlds; hello indeed!" +-- "Hello, world & other worlds; hello indeed!" +-- +-- >>> putStrLn $ replace_entities "Hello world—I guess" +-- Hello world—I guess +-- replace_entities :: String -> String replace_entities [] = [] replace_entities ('&':xs) =