+replace_entities target =
+ unescape_numeric (unescape_recursive xml_entities target)
+
+-- |Recursively unescape all numeric entities in the given String.
+unescape_numeric :: String -> String
+unescape_numeric target =
+ case match of
+ Nothing -> target
+ Just subexprs ->
+ case subexprs of
+ [] -> target
+ s1:_ ->
+ let this_entity_regex = mkRegex ("&#" ++ s1 ++ ";") in
+ let replacement = entity_from_codepoint s1 in
+ let new_target = subRegex this_entity_regex target replacement in
+ unescape_numeric new_target
+ where
+ from = "&#([0-9]+);"
+ match = matchRegex (mkRegex from) target