fdoc

subroutinerender_noderecursiveprivate

recursive subroutine render_node(t, id, options, out)

Write node id.

Arguments

NameTypeIntentAttributesDescription
ttype(tree_t)inout

the conversion

idintegerin

the node

optionstype(markdown_options_t)in

what rendering depends on

outtype(buffer_t)inout

the HTML

Calls

Source

Show the code
recursive subroutine render_node(t, id, options, out)
    type(tree_t), intent(inout) :: t                !! the conversion
    integer, intent(in) :: id                       !! the node
    type(markdown_options_t), intent(in) :: options !! what rendering depends on
    type(buffer_t), intent(inout) :: out            !! the HTML
    character(len=:), allocatable :: tag, attrs, html, text
    integer :: at

    tag = t%nodes(id)%tag
    attrs = t%nodes(id)%attrs
    select case (tag)
    case ('hr')
        call add(out, '<hr>')
    case ('code')
        call render_code(t%nodes(id)%text, html)
        call add(out, html)
    case ('table')
        call render_table(t, t%nodes(id)%text, options, out)
    case ('p')
        text = t%nodes(id)%text
        if (is_placeholder(strip(text))) then
            call add(out, strip(text))
            return
        end if
        if (strip(text) == '[TOC]' .and. options%toc) then
            call add(out, STX//'toc'//ETX)
            return
        end if
        call add(out, '<p'//attrs//'>')
        call inline(t, strip(text), options, out, 0)
        call add(out, '</p>')
    case ('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'dt')
        text = t%nodes(id)%text
        at = 0
        if (ends_with(text, '}')) at = index(text, ' {', back=.true.)
        if (at > 0 .and. tag /= 'dt') then
            call attribute_list(strip(text(at + 2:len(text) - 1)), attrs)
            if (starts_with(strip(attrs), ':')) attrs = ''
            text = strip(text(:at - 1))
        end if
        call render_heading(t, tag, attrs, text, options, out)
    case default
        call add(out, '<'//tag//attrs//'>')
        if (len(t%nodes(id)%text) > 0) call inline(t, strip(t%nodes(id)%text), options, out, 0)
        if (size(t%nodes(id)%kids) > 0) then
            if (tag /= 'li' .or. len(t%nodes(id)%text) == 0) call add(out, NL)
            if (tag == 'li' .and. len(t%nodes(id)%text) > 0) call add(out, NL)
            call render_children(t, id, options, out)
            call add(out, NL)
        end if
        call add(out, '</'//tag//'>')
    end select
end subroutine render_node

Graphs

Calls

Called by