aboutsummaryrefslogtreecommitdiff
path: root/bbcode
diff options
context:
space:
mode:
Diffstat (limited to 'bbcode')
-rw-r--r--bbcode/src/BBCode.hs12
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
3module BBCode 3module BBCode
4 ( parse 4 ( parse
5 , make
5 ) where 6 ) where
6 7
7import Thermoprint 8import Thermoprint
@@ -42,6 +43,17 @@ testTag f k = fromMaybe False (f <$> Map.lookup (CI.mk k) knownTags)
42data Decorated c = Decorated c [String] 43data Decorated c = Decorated c [String]
43 deriving (Show, Eq) 44 deriving (Show, Eq)
44 45
46make :: Block String -> String
47make (Over blocks) = concat $ map make blocks
48make (Center block) = "[center]" ++ make block ++ "[/center]\n"
49make (Paragraph inline) = make' inline ++ "\n"
50
51make' :: Inline String -> String
52make' (Beside inlines) = concat $ map make' inlines
53make' (Underline inline) = "[u]" ++ make' inline ++ "[/u]"
54make' (Cooked c) = c
55make' (Raw _) = error "Cannot transform block containing raw data to bbcode"
56
45parse :: String -> Either String (Block String) 57parse :: String -> Either String (Block String)
46parse input = (remerge . blockify <$> (tokenize input >>= treeify)) >>= semantics 58parse input = (remerge . blockify <$> (tokenize input >>= treeify)) >>= semantics
47 59