@@ -39,13 +39,13 @@ import Data.Char ( chr, ord )
3939import Text.Regex ( mkRegex, matchRegexAll, Regex )
4040import Maybe ( fromMaybe )
4141
42−-- | Regular expression for decimal coded entity.
43−decimalCodedEntity :: Text.Regex.Regex
44−decimalCodedEntity = mkRegex "&#([0-9]+);"
42+-- | Regular expression for numerical coded entity.
43+numericalEntity :: Text.Regex.Regex
44+numericalEntity = mkRegex "&#([0-9]+|[xX][0-9A-Fa-f]+);"
4545
4646-- | Regular expression for character entity.
4747characterEntity :: Text.Regex.Regex
48−characterEntity = mkRegex "&#[0-9]+;|&[A-Za-z0-9]+;"
48+characterEntity = mkRegex "&#[0-9]+;|&#[xX][0-9A-Fa-f]+;|&[A-Za-z0-9]+;"
4949
5050-- | Return a string with all entity references decoded to unicode characters
5151-- where possible.
@@ -73,8 +73,8 @@ entityToChar :: String -> Maybe Char
7373entityToChar entity =
7474 case (lookup entity entityTable) of
7575 Just ch -> Just ch
76− Nothing -> case (matchRegexAll decimalCodedEntity entity) of
77− Just (_, _, _, [sub]) -> Just (chr (read sub))
76+ Nothing -> case (matchRegexAll numericalEntity entity) of
77+ Just (_, _, _, [sub]) -> Just (chr (read ('0':sub)))
7878 Nothing -> Nothing
7979
8080-- | Returns a string containing an entity reference for the character.