123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596moduleUrl=Odoc_document.Urlletflat=reffalse(* Translation from Url.Path *)modulePath=structletfor_printingurl=List.mapsnd@@Url.Path.to_listurlletsegment_to_string(kind,name)=matchkindwith|`Module|`Page->name|_->Format.asprintf"%a-%s"Url.Path.pp_kindkindnameletis_leaf_pageurl=url.Url.Path.kind=`LeafPageletget_dir_and_fileurl=letl=Url.Path.to_listurlinletis_dir=if!flatthenfunction`Page->`Always|_->`Neverelsefunction`LeafPage->`Never|`File->`Never|_->`Alwaysinletdir,file=Url.Path.split~is_dirlinletdir=List.mapsegment_to_stringdirinletfile=matchfilewith|[]->"index.html"|[(`LeafPage,name)]->name^".html"|[(`File,name)]->name|xs->assert!flat;String.concat"-"(List.mapsegment_to_stringxs)^".html"in(dir,file)letfor_linkingurl=letdir,file=get_dir_and_fileurlindir@[file]letas_filename(url:Url.Path.t)=Fpath.(v@@String.concatFpath.dir_sep@@for_linkingurl)endletsemantic_uris=reffalsetyperesolve=CurrentofUrl.Path.t|Baseofstringletrecdrop_shared_prefixl1l2=match(l1,l2)with|l1::l1s,l2::l2swhenl1=l2->drop_shared_prefixl1sl2s|_,_->(l1,l2)lethref~resolvet=let{Url.Anchor.page;anchor;_}=tinlettarget_loc=Path.for_linkingpagein(* If xref_base_uri is defined, do not perform relative URI resolution. *)matchresolvewith|Basexref_base_uri->(letpage=xref_base_uri^String.concat"/"target_locinmatchanchorwith""->page|anchor->page^"#"^anchor)|Currentpath->(letcurrent_loc=Path.for_linkingpathinletcurrent_from_common_ancestor,target_from_common_ancestor=drop_shared_prefixcurrent_loctarget_locinletrelative_target=matchcurrent_from_common_ancestorwith|[]->(* We're already on the right page *)(* If we're already on the right page, the target from our common
ancestor can't be anything other than the empty list *)assert(target_from_common_ancestor=[]);[]|[_]->(* We're already in the right dir *)target_from_common_ancestor|l->(* We need to go up some dirs *)List.map(fun_->"..")(List.tll)@target_from_common_ancestorinletremove_index_htmll=matchList.revlwith|"index.html"::rest->List.rev(""::rest)|_->linletrelative_target=if!semantic_uristhenremove_index_htmlrelative_targetelserelative_targetinmatch(relative_target,anchor)with|[],""->"#"|page,""->String.concat"/"page|page,anchor->String.concat"/"page^"#"^anchor)