subroutineresolve_link
subroutine resolve_link(data, name, entity, child, child_entity, url, text, found)
Find what a [[name]] link means: see link_resolver in fdoc_markdown.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| data | class(*) | in | ||
| name | character(len=*) | in | the name | |
| entity | character(len=*) | in | its class, or | |
| child | character(len=*) | in | the child's name, or | |
| child_entity | character(len=*) | in | the child's class, or | |
| url | character(len=:) | out | allocatable | the link |
| text | character(len=:) | out | allocatable | the text to show |
| found | logical | out | false if there is no such entity |
Calls
Source
Show the code
subroutine resolve_link(data, name, entity, child, child_entity, url, text, found)
class(*), intent(in) :: data !! a [[link_context_t]]
character(len=*), intent(in) :: name !! the name
character(len=*), intent(in) :: entity !! its class, or `''`
character(len=*), intent(in) :: child !! the child's name, or `''`
character(len=*), intent(in) :: child_entity !! the child's class, or `''`
character(len=:), allocatable, intent(out) :: url !! the link
character(len=:), allocatable, intent(out) :: text !! the text to show
logical, intent(out) :: found !! false if there is no such entity
character(len=len(name)) :: low
character(len=len(entity)) :: class
character(len=:), allocatable :: label
integer :: item, inner, parent
found = .false.
url = ''
text = name
low = lowercase(name)
class = lowercase(entity)
select type (data)
type is (link_context_t)
item = 0
if (data%entity > 0) then
item = find_child(data%list, data%entity, low, class)
parent = data%list%box(data%entity)%e%parent
if (item == 0 .and. parent > 0) item = find_child(data%list, parent, low, class)
end if
if (item == 0) item = find_anywhere(data%list, low, class)
if (item == 0) return
label = data%list%box(item)%e%name
if (len(child) > 0) then
inner = find_child(data%list, item, lowercase(child), lowercase(child_entity))
if (inner > 0) then
item = inner
label = data%list%box(item)%e%name
end if
end if
call shown_entity(data%list, item)
call entity_url(data%list, item, url)
! something not shown has no anchor to go to: link to the page around it
do while (len(url) == 0 .and. data%list%box(item)%e%parent > 0)
item = data%list%box(item)%e%parent
call entity_url(data%list, item, url)
end do
if (len(url) == 0) return
if (.not. data%list%box(item)%e%visible .and. index(url, '#') > 0) url = url(:index(url, '#') - 1)
if (.not. allocated(data%list%box(item)%e%external_url)) url = data%prefix//url
text = label
found = .true.
end select
end subroutine resolve_link