diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2015-10-18 00:33:59 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2015-10-18 00:33:59 +0200 |
commit | c2d711b32917d036e30f7c015f5d5d41b7aef030 (patch) | |
tree | 5f8ee60367fe46b26a99128815e8039968bef889 | |
parent | f9edf473fe3cc6c2dc0bf5d2829c2287baa1a0a6 (diff) | |
download | thermoprint-c2d711b32917d036e30f7c015f5d5d41b7aef030.tar thermoprint-c2d711b32917d036e30f7c015f5d5d41b7aef030.tar.gz thermoprint-c2d711b32917d036e30f7c015f5d5d41b7aef030.tar.bz2 thermoprint-c2d711b32917d036e30f7c015f5d5d41b7aef030.tar.xz thermoprint-c2d711b32917d036e30f7c015f5d5d41b7aef030.zip |
added massaging to avoid uneccesary whitespace injection
-rw-r--r-- | bbcode/src/BBCode.hs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/bbcode/src/BBCode.hs b/bbcode/src/BBCode.hs index 3071db6..087842f 100644 --- a/bbcode/src/BBCode.hs +++ b/bbcode/src/BBCode.hs | |||
@@ -55,7 +55,19 @@ 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 = massage <$> ((remerge . blockify <$> (tokenize input >>= treeify)) >>= semantics) |
59 | |||
60 | massage :: Block String -> Block String | ||
61 | massage (Over [x]) = massage x | ||
62 | massage (Over xs) = Over $ map massage xs | ||
63 | massage (Center x) = Center $ massage x | ||
64 | massage (Paragraph x) = Paragraph $ massage' x | ||
65 | |||
66 | massage' :: Inline String -> Inline String | ||
67 | massage' (Beside [x]) = massage' x | ||
68 | massage' (Beside xs) = Beside $ map massage' xs | ||
69 | massage' (Underline x) = Underline $ massage' x | ||
70 | massage' z = z | ||
59 | 71 | ||
60 | blockify :: ContentForest -> [Decorated String] | 72 | blockify :: ContentForest -> [Decorated String] |
61 | blockify = map sortDeco . concat . map (blockify' []) | 73 | blockify = map sortDeco . concat . map (blockify' []) |
@@ -82,7 +94,7 @@ remerge xs = concat $ map toTree $ groupLasts xs | |||
82 | toTree (x@(Decorated _ ds):xs) = [Tagged content tag] | 94 | toTree (x@(Decorated _ ds):xs) = [Tagged content tag] |
83 | where | 95 | where |
84 | tag = last ds | 96 | tag = last ds |
85 | content = toTree $ map stripLast (x:xs) | 97 | content = concat $ map toTree $ groupLasts $ map stripLast (x:xs) |
86 | stripLast (Decorated c ds) = Decorated c (init ds) | 98 | stripLast (Decorated c ds) = Decorated c (init ds) |
87 | 99 | ||
88 | unknownTag :: forall a. String -> Either String a | 100 | unknownTag :: forall a. String -> Either String a |