X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FWiki%2FInterpreter%2FOutline.hs;h=f6d798d295ce85b9f7eaf05193e543c4f68f3a78;hb=4abf7df08bf0a614ea8179e8d1d69a17aac4f197;hp=eb8c9d4db095b3b1d2e8e14edcabf9a65b7c8664;hpb=e43bb104a7313dd696b8bb8aa3bafff94706a187;p=Rakka.git diff --git a/Rakka/Wiki/Interpreter/Outline.hs b/Rakka/Wiki/Interpreter/Outline.hs index eb8c9d4..f6d798d 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 @@ -17,23 +17,31 @@ outlineInterp = BlockCommandInterpreter { bciName = "outline" , bciInterpret = \ ctx _ -> - case ctxMainTree ctx of + case ctxMainWiki ctx of Just tree -> return $ Div [("class", "outline")] [Block $ mkOutline tree] Nothing -> return EmptyBlock } 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 = 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 _ + = [] -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