From e65e1eaac335a4738abb9e8ee8da7a229f96c2c0 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 17 Oct 2015 21:23:45 +0200 Subject: Drafts --- bbcode/src/BBCode.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'bbcode/src') 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 @@ module BBCode ( parse + , make ) where import Thermoprint @@ -42,6 +43,17 @@ testTag f k = fromMaybe False (f <$> Map.lookup (CI.mk k) knownTags) data Decorated c = Decorated c [String] deriving (Show, Eq) +make :: Block String -> String +make (Over blocks) = concat $ map make blocks +make (Center block) = "[center]" ++ make block ++ "[/center]\n" +make (Paragraph inline) = make' inline ++ "\n" + +make' :: Inline String -> String +make' (Beside inlines) = concat $ map make' inlines +make' (Underline inline) = "[u]" ++ make' inline ++ "[/u]" +make' (Cooked c) = c +make' (Raw _) = error "Cannot transform block containing raw data to bbcode" + parse :: String -> Either String (Block String) parse input = (remerge . blockify <$> (tokenize input >>= treeify)) >>= semantics -- cgit v1.2.3