123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081openOdoc_utilsmoduleHLink=LinkopenOdoc_document.TypesopenTyxmlmoduleLink=HLinklethtml_of_doc~config~resolvedocs=letopenHtmlinleta:([<Html_types.a_attrib],[<Html_types.span_content_fun],[>Html_types.span])star=Unsafe.node"a"(* Makes it possible to use <a> inside span. Although this is not standard (see
https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories)
it is validated by the {{:https://validator.w3.org/nu/#textarea}W3C}. *)in(* [a] tags should not contain in other [a] tags. If this happens, browsers
start to be really weird. If PPX do bad things, such a situation could
happen. We manually avoid this situation. *)letrecdoc_to_html~is_in_adoc=matchdocwith|Source_page.Plain_codes->[txts]|Tagged_code(info,docs)->(letis_in_a=matchinfowithLink_->true|_->is_in_ainletchildren=List.concat_map(doc_to_html~is_in_a)docsinmatchinfowith|Syntaxtok->[span~a:[a_class[tok]]children](* Currently, we do not render links to documentation *)|Link{documentation=_;implementation=None}->children|Link{documentation=_;implementation=Someanchor}->lethref=Link.href~config~resolveanchorin[a~a:[a_hrefhref]children]|Anchorlbl->[span~a:[a_idlbl]children])inletspan_content=List.concat_map(doc_to_html~is_in_a:false)docsinspan~a:[]span_contentletcount_lines_in_strings=letn=ref0inString.iter(function'\n'->incrn|_->())s;!n(** Traverse the doc to count the number of lines. *)letreccount_lines_in_span=function|Source_page.Plain_codes->count_lines_in_strings|Tagged_code(_,docs)->count_linesdocsandcount_linesl=letrecinnerlacc=matchlwith|[]->acc|hd::tl->innertl(count_lines_in_spanhd+acc)ininnerl0letrecline_numbersaccn=letopenHtmlinifn<1thenaccelseletl=string_of_intninletanchor=a~a:[a_id("L"^l);a_class["source_line"];a_href("#L"^l)][txtl]inline_numbers(anchor::txt"\n"::acc)(n-1)lethtml_of_doc~config~resolvedocs=letopenHtmlinpre~a:[a_class["source_container"]][code~a:[a_class["source_line_column"]](line_numbers[](count_linesdocs));code~a:[a_class["source_code"]][html_of_doc~config~resolvedocs];]