aboutsummaryrefslogtreecommitdiff
path: root/bbcode
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2015-10-18 00:33:59 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2015-10-18 00:33:59 +0200
commitc2d711b32917d036e30f7c015f5d5d41b7aef030 (patch)
tree5f8ee60367fe46b26a99128815e8039968bef889 /bbcode
parentf9edf473fe3cc6c2dc0bf5d2829c2287baa1a0a6 (diff)
downloadthermoprint-c2d711b32917d036e30f7c015f5d5d41b7aef030.tar
thermoprint-c2d711b32917d036e30f7c015f5d5d41b7aef030.tar.gz
thermoprint-c2d711b32917d036e30f7c015f5d5d41b7aef030.tar.bz2
thermoprint-c2d711b32917d036e30f7c015f5d5d41b7aef030.tar.xz
thermoprint-c2d711b32917d036e30f7c015f5d5d41b7aef030.zip
added massaging to avoid uneccesary whitespace injection
Diffstat (limited to 'bbcode')
-rw-r--r--bbcode/src/BBCode.hs16
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
55make' (Raw _) = error "Cannot transform block containing raw data to bbcode" 55make' (Raw _) = error "Cannot transform block containing raw data to bbcode"
56 56
57parse :: String -> Either String (Block String) 57parse :: String -> Either String (Block String)
58parse input = (remerge . blockify <$> (tokenize input >>= treeify)) >>= semantics 58parse input = massage <$> ((remerge . blockify <$> (tokenize input >>= treeify)) >>= semantics)
59
60massage :: Block String -> Block String
61massage (Over [x]) = massage x
62massage (Over xs) = Over $ map massage xs
63massage (Center x) = Center $ massage x
64massage (Paragraph x) = Paragraph $ massage' x
65
66massage' :: Inline String -> Inline String
67massage' (Beside [x]) = massage' x
68massage' (Beside xs) = Beside $ map massage' xs
69massage' (Underline x) = Underline $ massage' x
70massage' z = z
59 71
60blockify :: ContentForest -> [Decorated String] 72blockify :: ContentForest -> [Decorated String]
61blockify = map sortDeco . concat . map (blockify' []) 73blockify = 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
88unknownTag :: forall a. String -> Either String a 100unknownTag :: forall a. String -> Either String a