subroutineplain_textprivate
subroutine plain_text(html, limit, out)
html as plain text of at most limit characters, with blanks collapsed.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| html | character(len=*) | in | the HTML | |
| limit | integer | in | the length wanted | |
| out | character(len=:) | out | allocatable | 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