fdoc

subroutineplain_textprivate

subroutine plain_text(html, limit, out)

html as plain text of at most limit characters, with blanks collapsed.

Arguments

NameTypeIntentAttributesDescription
htmlcharacter(len=*)in

the HTML

limitintegerin

the length wanted

outcharacter(len=:)outallocatable

the text

Calls

Source

Show the code
subroutine plain_text(html, limit, out)
    character(len=*), intent(in) :: html                !! the HTML
    integer, intent(in) :: limit                        !! the length wanted
    character(len=:), allocatable, intent(out) :: out   !! the text
    type(buffer_t) :: b
    logical :: in_tag, blank
    integer :: k

    in_tag = .false.
    blank = .false.
    do k = 1, len(html)
        associate (c => html(k:k))
            if (c == '<') then
                in_tag = .true.
            else if (c == '>' .and. in_tag) then
                in_tag = .false.
            else if (.not. in_tag) then
                if (c == ' ' .or. c == achar(10)) then
                    blank = b%n > 0
                else
                    if (blank) call add(b, ' ')
                    blank = .false.
                    call add(b, c)
                end if
            end if
        end associate
        if (b%n >= limit) exit
    end do
    call take(b, out)
end subroutine plain_text

Graphs

Calls

Called by