diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2015-10-17 21:23:45 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2015-10-17 21:23:45 +0200 |
commit | e65e1eaac335a4738abb9e8ee8da7a229f96c2c0 (patch) | |
tree | 8711caffd49f24ee8136523e0aefc76e37d8666a /bbcode | |
parent | 005dc408dc09c3b479398ebe3e92efa2cd54846e (diff) | |
download | thermoprint-e65e1eaac335a4738abb9e8ee8da7a229f96c2c0.tar thermoprint-e65e1eaac335a4738abb9e8ee8da7a229f96c2c0.tar.gz thermoprint-e65e1eaac335a4738abb9e8ee8da7a229f96c2c0.tar.bz2 thermoprint-e65e1eaac335a4738abb9e8ee8da7a229f96c2c0.tar.xz thermoprint-e65e1eaac335a4738abb9e8ee8da7a229f96c2c0.zip |
Drafts
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 | ||