1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071openOdoc_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]|Linkanchor->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];]