diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2015-10-18 00:12:55 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2015-10-18 00:12:55 +0200 |
commit | 6db9326c348f54cd25f399ad1e472b20cb7771c0 (patch) | |
tree | b1d860091f914b0be92377d85c157b203189ae10 /bbcode | |
parent | e65e1eaac335a4738abb9e8ee8da7a229f96c2c0 (diff) | |
download | thermoprint-6db9326c348f54cd25f399ad1e472b20cb7771c0.tar thermoprint-6db9326c348f54cd25f399ad1e472b20cb7771c0.tar.gz thermoprint-6db9326c348f54cd25f399ad1e472b20cb7771c0.tar.bz2 thermoprint-6db9326c348f54cd25f399ad1e472b20cb7771c0.tar.xz thermoprint-6db9326c348f54cd25f399ad1e472b20cb7771c0.zip |
Added massaging to make sure blocks are not followed by extraneous whitespace
Diffstat (limited to 'bbcode')
-rw-r--r-- | bbcode/src/BBCode.hs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/bbcode/src/BBCode.hs b/bbcode/src/BBCode.hs index 3071db6..118aed7 100644 --- a/bbcode/src/BBCode.hs +++ b/bbcode/src/BBCode.hs | |||
@@ -55,7 +55,20 @@ make' (Cooked c) = c | |||
55 | make' (Raw _) = error "Cannot transform block containing raw data to bbcode" | 55 | make' (Raw _) = error "Cannot transform block containing raw data to bbcode" |
56 | 56 | ||
57 | parse :: String -> Either String (Block String) | 57 | parse :: String -> Either String (Block String) |
58 | parse input = (remerge . blockify <$> (tokenize input >>= treeify)) >>= semantics | 58 | parse input = (remerge . massage . blockify <$> (tokenize input >>= treeify)) >>= semantics |
59 | |||
60 | massage :: [Decorated String] -> [Decorated String] | ||
61 | massage [] = [] | ||
62 | massage (x@(Decorated _ tags) : x'@(Decorated wSpace []) : xs) | ||
63 | | any $ map isSpace wSpace | ||
64 | , any $ map isBlock tags = (x:Decorated (massage' wSpace) []:xs) | ||
65 | | otherwise = x : massage (x':xs) | ||
66 | where | ||
67 | massage' [] = [] | ||
68 | massage' l@(x:xs) | ||
69 | | isSpace x = massage' xs | ||
70 | | otherwise = l | ||
71 | massage (x:xs) = x : massage xs | ||
59 | 72 | ||
60 | blockify :: ContentForest -> [Decorated String] | 73 | blockify :: ContentForest -> [Decorated String] |
61 | blockify = map sortDeco . concat . map (blockify' []) | 74 | blockify = map sortDeco . concat . map (blockify' []) |