fdoc

subroutinecode_block_htmlprivate

subroutine code_block_html(code, lang, html)

The HTML of a code block.

Arguments

NameTypeIntentAttributesDescription
codecharacter(len=*)in

the code

langcharacter(len=*)in

its language, or ''

htmlcharacter(len=:)outallocatable

the HTML

Calls

Called by

Source

Show the code
subroutine code_block_html(code, lang, html)
    character(len=*), intent(in) :: code                !! the code
    character(len=*), intent(in) :: lang                !! its language, or `''`
    character(len=:), allocatable, intent(out) :: html  !! the HTML
    type(buffer_t) :: b

    ! a diagram stays as its text, which `fdoc.js` has Mermaid draw in the browser
    if (lowercase(lang) == 'mermaid') then
        call add(b, '<pre class="mermaid">')
        call html_escape(code, b, .false.)
        call add(b, '</pre>')
        call take(b, html)
        return
    end if
    call add(b, '<div class="codehilite"><pre><code')
    if (len(lang) > 0) then
        call add(b, ' class="language-')
        call html_escape(lang, b, .true.)
        call add(b, '"')
    end if
    call add(b, '>')
    select case (lowercase(lang))
    case ('fortran', 'f90', 'f', 'fortranfixed')
        call highlight_fortran(code, b, .false.)
    case ('json')
        call highlight_data(code, .false., b)
    case ('toml')
        call highlight_data(code, .true., b)
    case default
        call html_escape(code, b, .false.)
    end select
    call add(b, '</code></pre></div>')
    call take(b, html)
end subroutine code_block_html