@@ -114,9 +114,16 @@ toHtml5Entities = T.concatMap go
114114 Nothing -> T.pack ("&#" ++ show (ord c) ++ ";")
115115
116116html5EntityMap :: M.Map Char Text
117−html5EntityMap = M.fromList [(c, T.takeWhile (/=';') (T.pack ent))
118− | (ent@(_:_), [c]) <- htmlEntities
119− , last ent == ';']
117+html5EntityMap = foldr go mempty htmlEntities
118+ where go (ent, s) entmap =
119+ case s of
120+ [c] -> M.insertWith
121+ (\new old -> if T.length new > T.length old
122+ then old
123+ else new) c ent' entmap
124+ where ent' = T.takeWhile (/=';') (T.pack ent)
125+ _ -> entmap
126+
120127
121128-- Unescapes XML entities
122129fromEntities :: String -> String