open Xhtml
exception Invalid_link
let parse_links file =
try
let ch = open_in file in
let parse_link () =
let e1 = input_line ch in
let e2 = try input_line ch with End_of_file -> raise Invalid_link in
let e3, eof = try input_line ch, false with End_of_file -> "", true in
assert (e1 <> "");
assert (e2 <> "");
if eof then
if e3 = "" then
(e1, e2, None), true
else
(e1, e2, Some e3), true
else
if e3 = "" then
(e1, e2, None), false
else
let eof = try ignore (input_line ch); false
with End_of_file -> true in
(e1, e2, Some e3), eof
in
let rec aux () =
try let l, eof = parse_link () in
if eof then
[l]
else
l :: aux ()
with End_of_file -> []
in
let r = aux () in
close_in ch;
r
with Sys_error _ -> []
let xml_link (vtext, url, longtext) =
match longtext with
| Some longtext -> a ~href:url ~title:longtext [text vtext]
| None -> a ~href:url ~title:vtext [text vtext]
let links_entry links =
if links = [] then
[]
else
[div ~nclass:"related-links"
[h4 ~nclass:"toggle" [text "Related links"];
ul (List.map (fun e -> [e]) (List.map xml_link links))]
]