subroutineinsert_tocprivate
subroutine insert_toc(t, html)
Replace the [TOC] marker by the table of contents.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| t | type(tree_t) | in | the conversion | |
| html | character(len=:) | inout | allocatable | 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