)
where
-import Data.Generics
+import Data.Maybe
import Rakka.Wiki
import Rakka.Wiki.Interpreter
mkOutline :: WikiPage -> BlockElement
-mkOutline tree
- = let headings = listify query tree
- in
- fst (mkOutline' emptyOutline 1 headings)
-
-
-query :: Typeable a => a -> Bool
-query = mkQ False $ \ x -> case x of
- Heading _ _ -> True
- _ -> False
+mkOutline tree = fst (mkOutline' emptyOutline 1 headings)
+ where
+ headings :: [BlockElement]
+ headings = concat (map collectInBlock tree)
+
+ collectInBlock :: BlockElement -> [BlockElement]
+ collectInBlock hd@(Heading _ _)
+ = [hd]
+ collectInBlock (Div _ xs)
+ = concat $ map collectInBlock $ catMaybes (map castToBlock xs)
+ collectInBlock (BlockCmd (BlockCommand _ _ xs))
+ = concat $ map collectInBlock xs
+ collectInBlock _
+ = []
+
+ castToBlock :: Element -> Maybe BlockElement
+ castToBlock (Block e) = Just e
+ castToBlock _ = Nothing
emptyOutline :: BlockElement