fdoc

subroutineinsert_tocprivate

subroutine insert_toc(t, html)

Replace the [TOC] marker by the table of contents.

Arguments

NameTypeIntentAttributesDescription
ttype(tree_t)in

the conversion

htmlcharacter(len=:)inoutallocatable

the HTML

Calls

Source

Show the code
subroutine insert_toc(t, html)
    type(tree_t), intent(in) :: t                       !! the conversion
    character(len=:), allocatable, intent(inout) :: html !! the HTML
    type(buffer_t) :: b
    character(len=:), allocatable :: toc
    integer :: at, k, depth, level, lowest

    at = index(html, STX//'toc'//ETX)
    if (at == 0) return
    call add(b, '<div class="toc">'//NL)
    lowest = 7
    do k = 1, size(t%headings)
        lowest = min(lowest, t%headings(k)%level)
    end do
    depth = lowest - 1
    do k = 1, size(t%headings)
        level = t%headings(k)%level
        do while (depth < level)
            call add(b, '<ul>'//NL)
            depth = depth + 1
        end do
        do while (depth > level)
            call add(b, '</ul>'//NL)
            depth = depth - 1
        end do
        call add(b, '<li><a href="#'//t%headings(k)%id//'">'//t%headings(k)%html//'</a></li>'//NL)
    end do
    do while (depth >= lowest)
        call add(b, '</ul>'//NL)
        depth = depth - 1
    end do
    call add(b, '</div>')
    call take(b, toc)
    html = html(:at - 1)//toc//html(at + 5:)
end subroutine insert_toc

Graphs

Calls

Called by