subroutineinline_emphasisrecursiveprivate
recursive subroutine inline_emphasis(t, text, i, options, out, depth, used)
Handle * and _.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| t | type(tree_t) | inout | the conversion | |
| text | character(len=*) | in | the text | |
| i | integer | in | where it is | |
| options | type(markdown_options_t) | in | what rendering depends on | |
| out | type(buffer_t) | inout | the HTML | |
| depth | integer | in | how deeply this is nested | |
| used | integer | out | how much was used |
Calls
Source
Show the code
recursive subroutine inline_emphasis(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 :: c
integer :: run, close, width
logical :: before_blank, after_blank
used = 0
c = text(i:i)
run = verify(text(i:)//' ', c) - 1
before_blank = i == 1
if (.not. before_blank) before_blank = scan(text(i - 1:i - 1), ' '//NL) == 1
after_blank = i + run > len(text)
if (.not. after_blank) after_blank = scan(text(i + run:i + run), ' '//NL) == 1
if (run <= 3 .and. before_blank .and. after_blank) then
call add(out, text(i:i + run - 1))
used = run
return
end if
if (c == '_') then
if (i > 1) then
if (index(WORD_CHARS, text(i - 1:i - 1)) > 0) then
call add(out, text(i:i + run - 1))
used = run
return
end if
end if
end if
do width = min(run, 3), 1, -1
if (width == 1 .and. run > 1) exit
call closing_mark(text, i + width, c, width, close)
if (close == 0) cycle
select case (width)
case (3)
call add(out, '<strong><em>')
call inline(t, text(i + 3:close - 1), options, out, depth + 1)
call add(out, '</em></strong>')
case (2)
call add(out, '<strong>')
call inline(t, text(i + 2:close - 1), options, out, depth + 1)
call add(out, '</strong>')
case default
call add(out, '<em>')
call inline(t, text(i + 1:close - 1), options, out, depth + 1)
call add(out, '</em>')
end select
used = close + width - i
return
end do
! `**` with nothing to close it: the second `*` may still open emphasis
if (run > 1) then
call add(out, c)
used = 1
end if
end subroutine inline_emphasis