module Text.Docvim.Visitor.Heading ( getHeadings
, injectTOC
) where
import Control.Lens
import Text.Docvim.AST
getHeadings :: Node -> [String]
getHeadings = walk gather []
where
gather CommandsAnnotation = ["Commands"]
gather FunctionsAnnotation = ["Functions"]
gather (HeadingAnnotation h) = [h]
gather MappingsAnnotation = ["Mappings"]
gather OptionsAnnotation = ["Options"]
gather _ = []
injectTOC :: Node -> Node
injectTOC ast = transform inject ast
where
inject n = case n of
PluginAnnotation {} -> DocBlock $ n : [TOC $ getHeadings ast]
_ -> n