diff options
author | John MacFarlane <jgm@berkeley.edu> | 2010-12-07 20:10:21 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2010-12-07 20:10:21 -0800 |
commit | 3a5fceeef9c5f55b1769fbe95bf420ca3a20ea35 (patch) | |
tree | 8617198e1b1b0ff66857aa8d08aae637992e901d /src | |
parent | e20052a1bad73fb4c1556afe80a569343011d669 (diff) | |
download | pandoc-3a5fceeef9c5f55b1769fbe95bf420ca3a20ea35.tar.gz |
Rewrote normalizeSpaces (mostly aesthetic reasons).
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index f2f38519b..9878f7c23 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -326,20 +326,17 @@ orderedListMarkers (start, numstyle, numdelim) = -- @Space@ elements, collapse double @Space@s into singles, and -- remove empty Str elements. normalizeSpaces :: [Inline] -> [Inline] -normalizeSpaces [] = [] -normalizeSpaces list = - let removeDoubles [] = [] - removeDoubles (Space:Space:rest) = removeDoubles (Space:rest) - removeDoubles (Space:(Str ""):Space:rest) = removeDoubles (Space:rest) - removeDoubles ((Str ""):rest) = removeDoubles rest - removeDoubles (x:rest) = x:(removeDoubles rest) - removeLeading (Space:xs) = removeLeading xs - removeLeading x = x - removeTrailing [] = [] - removeTrailing lst = if (last lst == Space) - then init lst - else lst - in removeLeading $ removeTrailing $ removeDoubles list +normalizeSpaces = cleanup . dropWhile isSpaceOrEmpty + where isSpaceOrEmpty Space = True + isSpaceOrEmpty (Str "") = True + isSpaceOrEmpty _ = False + cleanup [] = [] + cleanup (Space:rest) = let rest' = dropWhile isSpaceOrEmpty rest + in case rest' of + [] -> [] + _ -> Space : cleanup rest' + cleanup ((Str ""):rest) = cleanup rest + cleanup (x:rest) = x : cleanup rest -- | Convert list of inlines to a string with formatting removed. stringify :: [Inline] -> String |