aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2011-12-12 09:02:26 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2011-12-12 09:02:26 -0800
commitbdb7648de24888b38196f59f83359af2f097aaa0 (patch)
tree8a7f38e352c8465be3e439dd6c19789c427d5756 /src/Text/Pandoc/Writers
parent1adb8074071f543f0ff541916fef9a750538b0c9 (diff)
downloadpandoc-bdb7648de24888b38196f59f83359af2f097aaa0.tar.gz
Fixed previous patch so it doesn't swallow a character!
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r--src/Text/Pandoc/Writers/EPUB.hs17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs
index 1bd614952..8897473b3 100644
--- a/src/Text/Pandoc/Writers/EPUB.hs
+++ b/src/Text/Pandoc/Writers/EPUB.hs
@@ -277,15 +277,18 @@ transformBlock x = x
-- | Version of 'ppTopElement' that specifies UTF-8 encoding.
ppTopElement :: Element -> String
ppTopElement = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ++) . unEntity . ppElement
- -- unEntity removes decimal entities introduced by ppElement
+ -- unEntity removes numeric entities introduced by ppElement
-- (kindlegen seems to choke on these).
where unEntity [] = ""
- unEntity ('&':'#':d:xs) | isDigit d =
- let ds = takeWhile isDigit xs
- c = read $ '\'' : '\\' : d : ds ++ "'"
- in if c > '\127'
- then c : unEntity (drop (length ds + 2) xs)
- else '&':'#':d:ds ++ unEntity (drop (length ds + 2) xs)
+ unEntity ('&':'#':xs) =
+ let (ds,ys) = break (==';') xs
+ c = if (all isDigit ds)
+ then Just $ read $ '\'' : '\\' : ds ++ "'"
+ else Nothing
+ rest = drop 1 ys
+ in case c of
+ Just x | x > '\127' -> x : unEntity rest
+ _ -> ('&':'#':ds) ++ ";" ++ unEntity rest
unEntity (x:xs) = x : unEntity xs
imageTypeOf :: FilePath -> Maybe String