@@ -277,15 +277,18 @@ transformBlock x = x
277277-- | Version of 'ppTopElement' that specifies UTF-8 encoding.
278278ppTopElement :: Element -> String
279279ppTopElement = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ++) . unEntity . ppElement
280− -- unEntity removes decimal entities introduced by ppElement
280+ -- unEntity removes numeric entities introduced by ppElement
281281 -- (kindlegen seems to choke on these).
282282 where unEntity [] = ""
283− unEntity ('&':'#':d:xs) | isDigit d =
284− let ds = takeWhile isDigit xs
285− c = read $ '\'' : '\\' : d : ds ++ "'"
286− in if c > '\127'
287− then c : unEntity (drop (length ds + 2) xs)
288− else '&':'#':d:ds ++ unEntity (drop (length ds + 2) xs)
283+ unEntity ('&':'#':xs) =
284+ let (ds,ys) = break (==';') xs
285+ c = if (all isDigit ds)
286+ then Just $ read $ '\'' : '\\' : ds ++ "'"
287+ else Nothing
288+ rest = drop 1 ys
289+ in case c of
290+ Just x | x > '\127' -> x : unEntity rest
291+ _ -> ('&':'#':ds) ++ ";" ++ unEntity rest
289292 unEntity (x:xs) = x : unEntity xs
290293
291294imageTypeOf :: FilePath -> Maybe String