@@ -277,15 +277,18 @@ transformBlock x = x
277-- | Version of 'ppTopElement' that specifies UTF-8 encoding.
277-- | Version of 'ppTopElement' that specifies UTF-8 encoding.
278ppTopElement :: Element -> String
278ppTopElement :: Element -> String
279ppTopElement = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ++) . unEntity . ppElement
279ppTopElement = ("<?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
281 -- (kindlegen seems to choke on these).
281 -- (kindlegen seems to choke on these).
282 where unEntity [] = ""
282 where unEntity [] = ""
283− unEntity ('&':'#':d:xs) | isDigit d =
283+ unEntity ('&':'#':xs) =
284− let ds = takeWhile isDigit xs
284+ let (ds,ys) = break (==';') xs
285+ c = if (all isDigit ds)
285− c = read $ '\'' : '\\' : d : ds ++ "'"
286+ then Just $ read $ '\'' : '\\' : ds ++ "'"
286− in if c > '\127'
287+ else Nothing
287− then c : unEntity (drop (length ds + 2) xs)
288+ rest = drop 1 ys
288− else '&':'#':d:ds ++ unEntity (drop (length ds + 2) xs)
289+ in case c of
290+ Just x | x > '\127' -> x : unEntity rest
291+ _ -> ('&':'#':ds) ++ ";" ++ unEntity rest
289 unEntity (x:xs) = x : unEntity xs
292 unEntity (x:xs) = x : unEntity xs
291imageTypeOf :: FilePath -> Maybe String
294imageTypeOf :: FilePath -> Maybe String