]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Wiki/Interpreter/Outline.hs
Applied HLint
[Rakka.git] / Rakka / Wiki / Interpreter / Outline.hs
index 04554a69b85b09dbe5a1f4a10974d162d871aa70..983b4597cbb5d20d84c8bb878f2231bc0bf6b710 100644 (file)
@@ -3,7 +3,7 @@ module Rakka.Wiki.Interpreter.Outline
     )
     where
 
-import           Data.Generics
+import           Data.Maybe
 import           Rakka.Wiki
 import           Rakka.Wiki.Interpreter
 
@@ -17,30 +17,38 @@ outlineInterp = BlockCommandInterpreter {
                   bciName      = "outline"
                 , bciInterpret
                     = \ ctx _ ->
-                      case ctxMainTree ctx of
-                        Just tree -> return $ Div [("class", "outline")] [List $ mkOutline tree]
+                      case ctxMainWiki ctx of
+                        Just tree -> return $ Div [("class", "outline")] [Block $ mkOutline tree]
                         Nothing   -> return EmptyBlock
                 }
 
 
-mkOutline :: WikiPage -> ListElement
-mkOutline tree
-    = let headings = listify query tree
-      in
-        fst (mkOutline' emptyOutline 1 headings)
+mkOutline :: WikiPage -> BlockElement
+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 :: ListElement
-emptyOutline = ListElement Bullet []
+emptyOutline :: BlockElement
+emptyOutline = List Bullet []
 
                                    
-mkOutline' :: ListElement -> Int -> [BlockElement] -> (ListElement, [BlockElement])
+mkOutline' :: BlockElement -> Int -> [BlockElement] -> (BlockElement, [BlockElement])
 mkOutline' soFar _     []     = (soFar, [])
 mkOutline' soFar level (x:xs)
     = case x of
@@ -53,7 +61,7 @@ mkOutline' soFar level (x:xs)
                               , linkFragment = Just text
                               , linkText     = Just text
                               }
-                       item = [Right link]
+                       item = [Inline link]
                    in
                      mkOutline' (soFar { listItems = listItems soFar ++ [item] }) n xs
 
@@ -72,9 +80,11 @@ mkOutline' soFar level (x:xs)
 
                        lastItem' :: ListItem
                        lastItem' = case lastItem of
-                                     []   -> [Left nested]
-                                     i:[] -> i ++ [Left nested]
+                                     []   -> [Block nested]
+                                     i:[] -> i ++ [Block nested]
+                                     _    -> undefined
 
                        soFar' = soFar { listItems = nonLastItems ++ [lastItem'] }
                    in
                      mkOutline' soFar' level ys
+        _ -> undefined
\ No newline at end of file