12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273openOdoc_document.TypesopenTyxmllethtml_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@@List.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])inspan~a:[]@@List.concat@@List.map(doc_to_html~is_in_a:false)docsletcount_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_lines=function|[]->0|hd::tl->count_lines_in_spanhd+count_linestlletrecline_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];]