Support hierarchy toc and flat toc.
correct hierarchy handling.
support both hierarchy toc and flat toc.