git.iko.soy/typeable/pandoc
on master help sign in
XML: toHtml5Entities: prefer shorter entities...

when there are several choices for a particular character.

commit511d647290eaa19907906807a9c4514a771ea66d authorJohn MacFarlane <jgm@berkeley.edu> dateSun 4 Nov 2018, 22:15 (8 years ago) parent0c84630
2 files changed+12−5
src/Text/Pandoc/XML.hs+10−3 test/command/ascii.md+2−2
src/Text/Pandoc/XML.hs+10−3
@@ -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
test/command/ascii.md+2−2
@@ -2,7 +2,7 @@
22pandoc -t html --ascii
33äéıå
44^D
5−<p>&auml;&eacute;&inodot;&aring;</p>
5+<p>&auml;&eacute;&imath;&aring;</p>
66```
77
88```
@@ -48,6 +48,6 @@ pandoc -t jats --ascii
4848pandoc -t markdown-smart --ascii
4949"äéıå"
5050^D
51−&ldquo;&auml;&eacute;&inodot;&aring;&rdquo;
51+&ldquo;&auml;&eacute;&imath;&aring;&rdquo;
5252```
5353