subroutinestash_fenced_codeprivate
subroutine stash_fenced_code(t, lines)
Replace fenced code blocks by placeholders.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| t | type(tree_t) | inout | the conversion | |
| lines | type(string_t) | inout | allocatabledimension(:) | the lines |
Calls
Source
Show the code
subroutine stash_fenced_code(t, lines)
type(tree_t), intent(inout) :: t !! the conversion
type(string_t), allocatable, intent(inout) :: lines(:) !! the lines
type(string_t), allocatable :: out(:)
character(len=:), allocatable :: info, html, placeholder, lang
type(buffer_t) :: code
integer :: k, j, n, m
character :: fence
if (.not. any([(index(lines(k)%s, '```') > 0 .or. index(lines(k)%s, '~~~') > 0, k=1, size(lines))])) return
allocate (out(0))
k = 1
do while (k <= size(lines))
n = fence_length(lines(k)%s)
j = 0
if (n > 0) then
fence = lines(k)%s(1:1)
do j = k + 1, size(lines)
m = fence_length(lines(j)%s)
if (m < n) cycle
if (lines(j)%s(1:1) == fence .and. len(strip(lines(j)%s(m + 1:))) == 0) exit
end do
if (j > size(lines)) j = 0
end if
if (j == 0) then
call push(out, lines(k)%s)
k = k + 1
cycle
end if
info = strip(lines(k)%s(n + 1:))
call fence_language(info, lang)
do m = k + 1, j - 1
call add(code, lines(m)%s)
call add(code, NL)
end do
call take(code, info)
call code_block_html(info, lang, html)
call stash_html(t, html, placeholder)
call push(out, '')
call push(out, placeholder)
call push(out, '')
k = j + 1
end do
call move_alloc(out, lines)
end subroutine stash_fenced_code