fdoc

subroutineinline_bracketrecursiveprivate

recursive subroutine inline_bracket(t, text, i, options, out, depth, used)

Handle [: a FORD link, a footnote reference or a link.

Arguments

NameTypeIntentAttributesDescription
ttype(tree_t)inout

the conversion

textcharacter(len=*)in

the text

iintegerin

where it is

optionstype(markdown_options_t)in

what rendering depends on

outtype(buffer_t)inout

the HTML

depthintegerin

how deeply this is nested

usedintegerout

how much was used

Calls

Source

Show the code
recursive subroutine inline_bracket(t, text, i, options, out, depth, used)
    type(tree_t), intent(inout) :: t                !! the conversion
    character(len=*), intent(in) :: text            !! the text
    integer, intent(in) :: i                        !! where it is
    type(markdown_options_t), intent(in) :: options !! what rendering depends on
    type(buffer_t), intent(inout) :: out            !! the HTML
    integer, intent(in) :: depth                    !! how deeply this is nested
    integer, intent(out) :: used                    !! how much was used
    character(len=:), allocatable :: url, title, id
    integer :: close, after, k, target, next

    used = 0
    if (i < len(text)) then
        if (text(i + 1:i + 1) == '[') then
            call ford_link(text, i, options, out, used)
            if (used > 0) return
        end if
        if (text(i + 1:i + 1) == '^') then
            close = index(text(i:), ']')
            if (close > 2) then
                do k = 1, size(t%notes)
                    if (t%notes(k)%id == text(i + 2:i + close - 2)) then
                        t%notes(k)%used = .true.
                        call add(out, '<sup id="fnref:'//t%notes(k)%id//'"><a class="footnote-ref" href="#fn:'// &
                                 t%notes(k)%id//'">'//trim(int_text(k))//'</a></sup>')
                        used = close
                        return
                    end if
                end do
            end if
        end if
    end if

    close = bracket_end(text, i)
    if (close == 0) return
    after = close + 1
    if (after <= len(text)) then
        if (text(after:after) == '(') then
            call link_target(text, after, url, title, k)
            if (k > 0) then
                call write_link(t, text(i + 1:close - 1), url, title, options, out, depth)
                used = k - i + 1
                return
            end if
        end if
    end if

    ! a reference: `[text][id]`, `[text] [id]`, `[id][]` or `[id]`
    next = after
    if (next <= len(text)) then
        if (text(next:next) == ' ') next = next + 1
    end if
    if (next <= len(text)) then
        if (text(next:next) == '[') then
            k = bracket_end(text, next)
            if (k > 0) then
                id = text(next + 1:k - 1)
                if (len(id) == 0) id = text(i + 1:close - 1)
                target = find_reference(t, id)
                if (target > 0) then
                    call write_link(t, text(i + 1:close - 1), t%refs(target)%url, t%refs(target)%title, options, out, depth)
                    used = k - i + 1
                    return
                end if
            end if
        end if
    end if
    target = find_reference(t, text(i + 1:close - 1))
    if (target > 0) then
        call write_link(t, text(i + 1:close - 1), t%refs(target)%url, t%refs(target)%title, options, out, depth)
        used = close - i + 1
    end if
end subroutine inline_bracket

Graphs

Calls

Called by