subroutineadmonition_linesprivate
subroutine admonition_lines(lines)
Turn @note blocks into a line @note Type followed by indented lines, ending at @endnote, a
blank line, another admonition, or the end of the text.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| lines | type(string_t) | inout | allocatabledimension(:) | the lines |
Calls
Source
Show the code
subroutine admonition_lines(lines)
type(string_t), allocatable, intent(inout) :: lines(:) !! the lines
type(string_t), allocatable :: out(:)
character(len=:), allocatable :: kind, rest, end_kind, end_rest
integer :: k, j, stop_at, blank
logical :: explicit
if (.not. any([(index(lines(k)%s, '@') > 0, k=1, size(lines))])) return
allocate (out(0))
k = 1
do while (k <= size(lines))
call admonition_start(lines(k)%s, '@', kind, rest)
if (len(kind) == 0) then
call push(out, lines(k)%s)
k = k + 1
cycle
end if
! the end: an end marker if there is one before the next admonition, or the first blank line
stop_at = size(lines)
blank = 0
explicit = .false.
do j = k + 1, size(lines)
call admonition_start(lines(j)%s, '@end', end_kind, end_rest)
if (len(end_kind) > 0) then
stop_at = j
explicit = .true.
exit
end if
call admonition_start(lines(j)%s, '@', end_kind, end_rest)
if (len(end_kind) > 0) then
stop_at = j - 1
exit
end if
if (len(lines(j)%s) == 0 .and. blank == 0) blank = j
end do
if (.not. explicit .and. blank > 0) stop_at = blank - 1
call push(out, '')
call push(out, '@note '//achar(iachar(kind(1:1)) - 32)//kind(2:))
if (len(rest) > 0) call push(out, ' '//rest)
do j = k + 1, stop_at
if (explicit .and. j == stop_at) exit
if (len(lines(j)%s) == 0) then
call push(out, '')
else
call push(out, ' '//lines(j)%s)
end if
end do
call push(out, '')
if (explicit) then
call admonition_start(lines(stop_at)%s, '@end', end_kind, end_rest)
if (len(end_rest) > 0) call push(out, end_rest)
end if
k = stop_at + 1
end do
call move_alloc(out, lines)
end subroutine admonition_lines