aboutsummaryrefslogtreecommitdiff
path: root/bbcode/src/BBCode.hs
diff options
context:
space:
mode:
Diffstat (limited to 'bbcode/src/BBCode.hs')
-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