diff options
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Entities.hs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Entities.hs b/src/Text/Pandoc/Entities.hs index 8e184432b..0b77ea334 100644 --- a/src/Text/Pandoc/Entities.hs +++ b/src/Text/Pandoc/Entities.hs @@ -43,11 +43,7 @@ import qualified Data.Map as Map -- | Returns a string containing an entity reference for the character. charToEntity :: Char -> String -charToEntity char = - let matches = Map.filter (== char) entityTable in - if Map.null matches - then charToNumericalEntity char - else head $ Map.keys matches +charToEntity char = Map.findWithDefault (charToNumericalEntity char) char reverseEntityTable -- | Returns a string containing a numerical entity reference for the char. charToNumericalEntity :: Char -> String @@ -113,7 +109,13 @@ decodeEntities str = Right result -> result entityTable :: Map.Map String Char -entityTable = Map.fromList [ +entityTable = Map.fromList entityTableList + +reverseEntityTable :: Map.Map Char String +reverseEntityTable = Map.fromList $ map (\(a,b) -> (b,a)) entityTableList + +entityTableList :: [(String, Char)] +entityTableList = [ (""", chr 34), ("&", chr 38), ("<", chr 60), |