@@ -326,20 +326,17 @@ orderedListMarkers (start, numstyle, numdelim) =
326326-- @Space@ elements, collapse double @Space@s into singles, and
327327-- remove empty Str elements.
328328normalizeSpaces :: [Inline] -> [Inline]
329−normalizeSpaces [] = []
330−normalizeSpaces list =
331− let removeDoubles [] = []
332− removeDoubles (Space:Space:rest) = removeDoubles (Space:rest)
333− removeDoubles (Space:(Str ""):Space:rest) = removeDoubles (Space:rest)
334− removeDoubles ((Str ""):rest) = removeDoubles rest
335− removeDoubles (x:rest) = x:(removeDoubles rest)
336− removeLeading (Space:xs) = removeLeading xs
337− removeLeading x = x
338− removeTrailing [] = []
339− removeTrailing lst = if (last lst == Space)
340− then init lst
341− else lst
342− in removeLeading $ removeTrailing $ removeDoubles list
329+normalizeSpaces = cleanup . dropWhile isSpaceOrEmpty
330+ where isSpaceOrEmpty Space = True
331+ isSpaceOrEmpty (Str "") = True
332+ isSpaceOrEmpty _ = False
333+ cleanup [] = []
334+ cleanup (Space:rest) = let rest' = dropWhile isSpaceOrEmpty rest
335+ in case rest' of
336+ [] -> []
337+ _ -> Space : cleanup rest'
338+ cleanup ((Str ""):rest) = cleanup rest
339+ cleanup (x:rest) = x : cleanup rest
343340
344341-- | Convert list of inlines to a string with formatting removed.
345342stringify :: [Inline] -> String