@@ -243,10 +243,7 @@ orderedListMarkers (start, numstyle, numdelim) =
243243-- remove empty Str elements.
244244normalizeSpaces :: [Inline] -> [Inline]
245245normalizeSpaces = cleanup . dropWhile isSpaceOrEmpty
246− where isSpaceOrEmpty Space = True
247− isSpaceOrEmpty (Str "") = True
248− isSpaceOrEmpty _ = False
249− cleanup [] = []
246+ where cleanup [] = []
250247 cleanup (Space:rest) = let rest' = dropWhile isSpaceOrEmpty rest
251248 in case rest' of
252249 [] -> []
@@ -254,13 +251,18 @@ normalizeSpaces = cleanup . dropWhile isSpaceOrEmpty
254251 cleanup ((Str ""):rest) = cleanup rest
255252 cleanup (x:rest) = x : cleanup rest
256253
254+isSpaceOrEmpty :: Inline -> Bool
255+isSpaceOrEmpty Space = True
256+isSpaceOrEmpty (Str "") = True
257+isSpaceOrEmpty _ = False
258+
257259-- | Normalize @Pandoc@ document, consolidating doubled 'Space's,
258260-- combining adjacent 'Str's and 'Emph's, remove 'Null's and
259261-- empty elements, etc.
260262normalize :: (Eq a, Data a) => a -> a
261263normalize = topDown removeEmptyBlocks .
262264 topDown consolidateInlines .
263− bottomUp removeEmptyInlines
265+ bottomUp (removeEmptyInlines . removeTrailingInlineSpaces)
264266
265267removeEmptyBlocks :: [Block] -> [Block]
266268removeEmptyBlocks (Null : xs) = removeEmptyBlocks xs
@@ -284,6 +286,9 @@ removeEmptyInlines (Str "" : zs) = removeEmptyInlines zs
284286removeEmptyInlines (x : xs) = x : removeEmptyInlines xs
285287removeEmptyInlines [] = []
286288
289+removeTrailingInlineSpaces :: [Inline] -> [Inline]
290+removeTrailingInlineSpaces = reverse . dropWhile isSpaceOrEmpty . reverse
291+
287292consolidateInlines :: [Inline] -> [Inline]
288293consolidateInlines (Str x : ys) =
289294 case concat (x : map fromStr strs) of