1 module Rakka.Wiki.Formatter
7 import Control.Arrow.ArrowList
10 import Text.XML.HXT.Arrow.XmlArrow
11 import Text.XML.HXT.DOM.TypeDefs
15 packParagraph :: [WikiElement] -> [Either BlockElement [InlineElement]]
16 packParagraph elems = map pack grp
18 grp :: [[WikiElement]]
19 grp = groupBy criteria elems
21 criteria :: WikiElement -> WikiElement -> Bool
22 criteria (Inline _) (Inline _) = True
25 pack :: [WikiElement] -> Either BlockElement [InlineElement]
26 pack (Block b : []) = Left b
27 pack xs = Right [ case x of
28 Inline i -> i | x <- xs ]
31 formatWikiElements :: (ArrowXml a, ArrowChoice a) => a [WikiElement] XmlTree
34 -> do chunk <- arrL id -< packParagraph elems
36 Left x -> formatBlock -< x
37 Right xs -> formatParagraph -< xs
40 formatBlock :: (ArrowXml a, ArrowChoice a) => a BlockElement XmlTree
45 -> formatHeader -< (level, text)
50 formatHeader :: ArrowXml a => a (Int, String) XmlTree
53 -> selem ("h" ++ show level) [txt text] -<< ()
56 formatParagraph :: (ArrowXml a, ArrowChoice a) => a [InlineElement] XmlTree
59 -> do elem <- arrL id -< xs
61 += formatInline ) -< elem
65 formatInline :: (ArrowXml a, ArrowChoice a) => a InlineElement XmlTree