123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270(*
* Copyright (c) 2016 Thomas Refis <trefis@janestreet.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)moduleUrl=Odoc_document.UrlmoduleHtml=Tyxml.Htmllethtml_of_toctoc=letopenTypesinletrecsection(section:toc)=letlink=Html.a~a:[Html.a_hrefsection.href]section.titleinmatchsection.childrenwith[]->[link]|cs->[link;sectionscs]andsectionsthe_sections=the_sections|>List.map(funthe_section->Html.li(sectionthe_section))|>Html.ulinmatchtocwith[]->[]|_->[sectionstoc]lethtml_of_search()=letsearch_bar=Html.(input~a:[a_class["search-bar"];a_placeholder"🔎 Search..."]())inletsnake=Html.(div~a:[a_class["search-snake"]][])inletsearch_result=Html.div~a:[Html.a_class["search-result"]][]inHtml.(div~a:[a_class["search-inner"]][search_bar;snake;search_result])letsidebartoc=matchtocwith|[]->[]|_->[Html.nav~a:[Html.a_class["odoc-toc"]](html_of_toctoc)]lethtml_of_breadcrumbs(breadcrumbs:Types.breadcrumblist)=letmake_navigation~up_urlrest=[Html.nav~a:[Html.a_class["odoc-nav"]]([Html.a~a:[Html.a_hrefup_url][Html.txt"Up"];Html.txt" – "]@rest);]inmatchList.revbreadcrumbswith|[]->[](* Can't happen - there's always the current page's breadcrumb. *)|[_]->[](* No parents *)|[{name="index";_};x]->(* Special case leaf pages called 'index' with one parent. This is for files called
index.mld that would otherwise clash with their parent. In particular,
dune and odig both cause this situation right now. *)letup_url="../index.html"inletparent_name=x.nameinmake_navigation~up_url[Html.txtparent_name]|current::up::bs->letspace=Html.txt" "inletsep=[space;Html.entity"#x00BB";space]inlethtml=(* Create breadcrumbs *)Utils.list_concat_map?sep:(Somesep)~f:(fun(breadcrumb:Types.breadcrumb)->[[Html.a~a:[Html.a_hrefbreadcrumb.href][Html.txtbreadcrumb.name];];])(up::bs)|>List.flatteninmake_navigation~up_url:up.href(List.revhtml@sep@[Html.txtcurrent.name])letfile_uri~config~url(base:Types.uri)file=matchbasewith|Types.Absoluteuri->uri^"/"^file|Relativeuri->letpage=Url.Path.{kind=`File;parent=uri;name=file}inLink.href~config~resolve:(Currenturl)(Url.from_pathpage)letdefault_meta_elements~config~url=lettheme_uri=Config.theme_uriconfiginletodoc_css_uri=file_uri~config~urltheme_uri"odoc.css"in[Html.meta~a:[Html.a_charset"utf-8"]();Html.link~rel:[`Stylesheet]~href:odoc_css_uri();Html.meta~a:[Html.a_name"generator";Html.a_content"odoc %%VERSION%%"]();Html.meta~a:[Html.a_name"viewport";Html.a_content"width=device-width,initial-scale=1.0";]();]letpage_creator~config~url~uses_katexheaderbreadcrumbstoccontent=lettheme_uri=Config.theme_uriconfiginletsupport_uri=Config.support_uriconfiginletsearch_uris=Config.search_urisconfiginletpath=Link.Path.for_printingurlinlethead:Html_types.headHtml.elt=lettitle_string=Printf.sprintf"%s (%s)"url.name(String.concat"."path)inletfile_uri=file_uri~config~urlinletsearch_uriuri=matchuriwith|Types.Absoluteuri->uri|Relativeuri->Link.href~config~resolve:(Currenturl)(Url.from_pathuri)inletsearch_scripts=matchsearch_uriswith|[]->[]|_->letsearch_urls=List.mapsearch_urisearch_urisinletsearch_urls=letsearch_urlname=Printf.sprintf"'%s'"nameinletsearch_urls=List.mapsearch_urlsearch_urlsin"["^String.concat","search_urls^"]"in(* The names of the search scripts are put into a js variable. Then
the code in [odoc_search.js] load them into a webworker. *)[Html.script~a:[](Html.txt(Format.asprintf{|let base_url = '%s';
let search_urls = %s;
|}(letpage=Url.Path.{kind=`File;parent=None;name=""}inLink.href~config~resolve:(Currenturl)(Url.from_pathpage))search_urls));Html.script~a:[Html.a_src(file_urisupport_uri"odoc_search.js");Html.a_defer();](Html.txt"");]inletmeta_elements=lethighlightjs_meta=lethighlight_js_uri=file_urisupport_uri"highlight.pack.js"in[Html.script~a:[Html.a_srchighlight_js_uri](Html.txt"");Html.script(Html.txt"hljs.initHighlightingOnLoad();");]inletkatex_meta=ifuses_katexthenletkatex_css_uri=file_uritheme_uri"katex.min.css"inletkatex_js_uri=file_urisupport_uri"katex.min.js"in[Html.link~rel:[`Stylesheet]~href:katex_css_uri();Html.script~a:[Html.a_srckatex_js_uri](Html.txt"");Html.script(Html.cdata_script{|
document.addEventListener("DOMContentLoaded", function () {
var elements = Array.from(document.getElementsByClassName("odoc-katex-math"));
for (var i = 0; i < elements.length; i++) {
var el = elements[i];
var content = el.textContent;
var new_el = document.createElement("span");
new_el.setAttribute("class", "odoc-katex-math-rendered");
var display = el.classList.contains("display");
katex.render(content, new_el, { throwOnError: false, displayMode: display });
el.replaceWith(new_el);
}
});
|});]else[]indefault_meta_elements~config~url@highlightjs_meta@katex_metainletmeta_elements=meta_elements@search_scriptsinHtml.head(Html.title(Html.txttitle_string))meta_elementsinletsearch_bar=matchsearch_uriswith|[]->[]|_->[Html.div~a:[Html.a_class["odoc-search"]][html_of_search()]]inletbody=html_of_breadcrumbsbreadcrumbs@search_bar@[Html.header~a:[Html.a_class["odoc-preamble"]]header]@sidebartoc@[Html.div~a:[Html.a_class["odoc-content"]]content]inlethtmlpp=Html.pp~indent:(Config.indentconfig)()inlethtml=Html.htmlhead(Html.body~a:[Html.a_class["odoc"]]body)inletcontentppf=htmlppppfhtml;(* Tyxml's pp doesn't output a newline a the end, so we force one *)Format.pp_force_newlineppf()incontentletmake~config~url~header~breadcrumbs~toc~uses_katexcontentchildren=letfilename=Link.Path.as_filename~is_flat:(Config.flatconfig)urlinletcontent=page_creator~config~url~uses_katexheaderbreadcrumbstoccontentin{Odoc_document.Renderer.filename;content;children}letpath_of_module_of_sourceppfurl=matchurl.Url.Path.parentwith|Someparent->letpath=Link.Path.for_printingparentinFormat.fprintfppf" (%s)"(String.concat"."path)|None->()letsrc_page_creator~breadcrumbs~config~url~headernamecontent=lethead:Html_types.headHtml.elt=lettitle_string=Format.asprintf"Source: %s%a"namepath_of_module_of_sourceurlinletmeta_elements=default_meta_elements~config~urlinHtml.head(Html.title(Html.txttitle_string))meta_elementsinletbody=html_of_breadcrumbsbreadcrumbs@[Html.header~a:[Html.a_class["odoc-preamble"]]header]@contentin(* We never indent as there is a bug in tyxml and it would break lines inside
a [pre] *)lethtmlpp=Html.pp~indent:false()inlethtml=Html.htmlhead(Html.body~a:[Html.a_class["odoc-src"]]body)inletcontentppf=htmlppppfhtml;(* Tyxml's pp doesn't output a newline a the end, so we force one *)Format.pp_force_newlineppf()incontentletmake_src~config~url~breadcrumbs~headertitlecontent=letfilename=Link.Path.as_filename~is_flat:(Config.flatconfig)urlinletcontent=src_page_creator~breadcrumbs~config~url~headertitlecontentin{Odoc_document.Renderer.filename;content;children=[]}