diff options
Diffstat (limited to 'bbcode/src')
-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 |