diff options
Diffstat (limited to 'bbcode')
| -rw-r--r-- | bbcode/src/BBCode.hs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/bbcode/src/BBCode.hs b/bbcode/src/BBCode.hs index 750fb0f..3071db6 100644 --- a/bbcode/src/BBCode.hs +++ b/bbcode/src/BBCode.hs | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | module BBCode | 3 | module BBCode |
| 4 | ( parse | 4 | ( parse |
| 5 | , make | ||
| 5 | ) where | 6 | ) where |
| 6 | 7 | ||
| 7 | import Thermoprint | 8 | import Thermoprint |
| @@ -42,6 +43,17 @@ testTag f k = fromMaybe False (f <$> Map.lookup (CI.mk k) knownTags) | |||
| 42 | data Decorated c = Decorated c [String] | 43 | data Decorated c = Decorated c [String] |
| 43 | deriving (Show, Eq) | 44 | deriving (Show, Eq) |
| 44 | 45 | ||
| 46 | make :: Block String -> String | ||
| 47 | make (Over blocks) = concat $ map make blocks | ||
| 48 | make (Center block) = "[center]" ++ make block ++ "[/center]\n" | ||
| 49 | make (Paragraph inline) = make' inline ++ "\n" | ||
| 50 | |||
| 51 | make' :: Inline String -> String | ||
| 52 | make' (Beside inlines) = concat $ map make' inlines | ||
| 53 | make' (Underline inline) = "[u]" ++ make' inline ++ "[/u]" | ||
| 54 | make' (Cooked c) = c | ||
| 55 | make' (Raw _) = error "Cannot transform block containing raw data to bbcode" | ||
| 56 | |||
| 45 | parse :: String -> Either String (Block String) | 57 | parse :: String -> Either String (Block String) |
| 46 | parse input = (remerge . blockify <$> (tokenize input >>= treeify)) >>= semantics | 58 | parse input = (remerge . blockify <$> (tokenize input >>= treeify)) >>= semantics |
| 47 | 59 | ||
