X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FWiki%2FInterpreter%2FOutline.hs;h=983b4597cbb5d20d84c8bb878f2231bc0bf6b710;hb=43113f26d3e61c96d896724c5509abe67b6a99e7;hp=16ed0c5f7999ad52670df7398ca10e41f8a7b647;hpb=656fdb2772ab4de5cd083cbe9e7c1610cccef73b;p=Rakka.git diff --git a/Rakka/Wiki/Interpreter/Outline.hs b/Rakka/Wiki/Interpreter/Outline.hs index 16ed0c5..983b459 100644 --- a/Rakka/Wiki/Interpreter/Outline.hs +++ b/Rakka/Wiki/Interpreter/Outline.hs @@ -3,7 +3,7 @@ module Rakka.Wiki.Interpreter.Outline ) where -import Data.Generics +import Data.Maybe import Rakka.Wiki import Rakka.Wiki.Interpreter @@ -24,16 +24,24 @@ outlineInterp = BlockCommandInterpreter { mkOutline :: WikiPage -> BlockElement -mkOutline tree - = let headings = listify query tree - in - fst (mkOutline' emptyOutline 1 headings) +mkOutline tree = fst (mkOutline' emptyOutline 1 headings) + where + headings :: [BlockElement] + headings = concatMap collectInBlock tree + collectInBlock :: BlockElement -> [BlockElement] + collectInBlock hd@(Heading _ _) + = [hd] + collectInBlock (Div _ xs) + = concatMap collectInBlock $ catMaybes (map castToBlock xs) + collectInBlock (BlockCmd (BlockCommand _ _ xs)) + = concatMap collectInBlock xs + collectInBlock _ + = [] -query :: Typeable a => a -> Bool -query = mkQ False $ \ x -> case x of - Heading _ _ -> True - _ -> False + castToBlock :: Element -> Maybe BlockElement + castToBlock (Block e) = Just e + castToBlock _ = Nothing emptyOutline :: BlockElement @@ -74,7 +82,9 @@ mkOutline' soFar level (x:xs) lastItem' = case lastItem of [] -> [Block nested] i:[] -> i ++ [Block nested] + _ -> undefined soFar' = soFar { listItems = nonLastItems ++ [lastItem'] } in mkOutline' soFar' level ys + _ -> undefined \ No newline at end of file