@@ -39,15 +39,15 @@ module Text.Pandoc.Entities (
3939import Data.Char ( chr, ord )
4040import Text.ParserCombinators.Parsec
4141import Data.Maybe ( fromMaybe )
42+import qualified Data.Map as Map
4243
4344-- | Returns a string containing an entity reference for the character.
4445charToEntity :: Char -> String
4546charToEntity char =
46− let matches = filter (\(entity, character) -> (character == char))
47− entityTable in
48− if (length matches) == 0
47+ let matches = Map.filter (== char) entityTable in
48+ if Map.null matches
4949 then charToNumericalEntity char
50− else fst (head matches)
50+ else head $ Map.keys matches
5151
5252-- | Returns a string containing a numerical entity reference for the char.
5353charToNumericalEntity :: Char -> String
@@ -64,9 +64,7 @@ namedEntity = try $ do
6464 body <- many1 alphaNum
6565 end <- char ';'
6666 let entity = "&" ++ body ++ ";"
67− return $ case (lookup entity entityTable) of
68− Just ch -> ch
69− Nothing -> '?'
67+ return $ Map.findWithDefault '?' entity entityTable
7068
7169-- | Parse SGML hexadecimal entity.
7270hexEntity :: GenParser Char st Char
@@ -114,8 +112,8 @@ decodeEntities str =
114112 Left err -> error $ "\nError: " ++ show err
115113 Right result -> result
116114
117−entityTable :: [(String, Char)]
118−entityTable = [
115+entityTable :: Map.Map String Char
116+entityTable = Map.fromList [
119117 (""", chr 34),
120118 ("&", chr 38),
121119 ("<", chr 60),