let html_of_doc (options : Common_utils.t_html_options) (doc : Doc_types.tr_doc) : string =
try
let exml:Xml.xml = Compiler_of_doc.exml_of_tr_doc (Common_utils.exml_options_of_html_options options) doc in
let doc_class : Common_utils.t_doc_class = Common_utils.class_of_tr_doc doc in
let html:Xml.xml = Html_utils.html_of_exml doc_class exml in
let html_string:string = Xml_right.to_string_fmt html in
let title:string =
match doc.fld_doc_title with
|None -> String.concat "" ["<title>";"untitled";"</title>"]
|Some (Cs_title s) -> String.concat "" ["<title>";s;"</title>"]
in
let authors:string =
match doc.fld_doc_authors with
|None -> ""
|Some (Cs_authors (author_list : Doc_types.ts_author list)) ->
let map (author : Doc_types.ts_author) : string =
match author with
|Cs_author s -> String.concat "" ["<meta name=\"author\" content=\"";s;"\">"]
in String.concat "\n" (List.map map author_list)
in
let lang_attr : string = (" lang=\"" ^ options.lang ^ "\"") in
let margin_left : string =
match options.margin with
|Some m -> (string_of_int m) ^ "rem"
|None -> Html_utils.margin_left_of_tr_doc doc
in
let internal_css: string = ("<style>\n" ^ (Html_utils.internal_css "6ch" margin_left) ^ "\n</style>") in
let external_css: string =
let map (uri : string) : string = ("<link rel=\"stylesheet\" href=\"" ^ uri ^ "\">\n") in
String.concat "" (List.map map options.css)
in
let intro : string = (
"<!DOCTYPE html>\n" ^
"<html" ^ lang_attr ^ ">\n" ^
"<head>\n" ^
"<meta charset=\"UTF-8\">\n" ^
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" ^
title ^ "\n" ^
authors ^ "\n" ^
internal_css ^ "\n" ^
external_css ^
"</head>\n" ^
"<body>\n"
)
in
let outro : string = (
"\n</body>\n" ^
"</html>"
)
in
(intro ^ html_string ^ outro)
with
|Common_utils.Error e -> raise (Error (String.concat " " ["Common_utils.Error:"; e]))
|Html_utils.Error e -> raise (Error (String.concat " " ["Html_utils.Error:"; e]))
|Compiler_of_doc.Error e -> raise (Error (String.concat " " ["Compiler_of_doc.Error:"; e]))
|Xml_right.Error e -> raise (Error (String.concat " " ["Xml_right.Error:"; e]))