fdoc

subroutinelink_targetprivate

subroutine link_target(text, open, url, title, close)

Read the (address "title") at open.

Arguments

NameTypeIntentAttributesDescription
textcharacter(len=*)in

the text

openintegerin

where ( is

urlcharacter(len=:)outallocatable

the address

titlecharacter(len=:)outallocatable

the title, or ''

closeintegerout

where ) is, or 0

Calls

Source

Show the code
subroutine link_target(text, open, url, title, close)
    character(len=*), intent(in) :: text                !! the text
    integer, intent(in) :: open                         !! where `(` is
    character(len=:), allocatable, intent(out) :: url   !! the address
    character(len=:), allocatable, intent(out) :: title !! the title, or `''`
    integer, intent(out) :: close                       !! where `)` is, or 0
    character(len=:), allocatable :: inner
    integer :: k, depth, q

    url = ''
    title = ''
    close = 0
    depth = 0
    q = 0
    do k = open, len(text)
        if (text(k:k) == '(') depth = depth + 1
        if (text(k:k) == ')') depth = depth - 1
        if (depth == 0) then
            close = k
            exit
        end if
    end do
    if (close == 0) return
    inner = strip(text(open + 1:close - 1))
    if (starts_with(inner, '<')) then
        k = index(inner, '>')
        if (k > 0) then
            url = inner(2:k - 1)
            inner = strip(inner(k + 1:))
            if (len(inner) >= 2) title = inner(2:len(inner) - 1)
            return
        end if
    end if
    if (len(inner) >= 2) then
        if (scan(inner(len(inner):len(inner)), '"''') == 1) then
            q = index(inner, ' '//inner(len(inner):len(inner)))
            if (q > 0) then
                title = inner(q + 2:len(inner) - 1)
                inner = strip(inner(:q - 1))
            end if
        end if
    end if
    url = inner
end subroutine link_target

Graphs

Calls

Called by