1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
open Result
let resolve url_to_string directories reference =
let resolver =
Resolver.create ~important_digests:false ~directories ~open_modules:[]
in
let reference =
let open Odoc_model in
let warnings_options = { Error.warn_error = true; print_warnings = true } in
Semantics.parse_reference reference
|> Error.handle_errors_and_warnings ~warnings_options
in
match reference with
| Error e -> Error e
| Ok reference -> (
let environment = Resolver.build_env_for_reference resolver in
let resolved_reference =
Odoc_xref2.Ref_tools.resolve_reference environment reference
|> Odoc_model.Error.raise_warnings
in
match resolved_reference with
| Error e ->
let error =
Format.asprintf "%a"
Odoc_xref2.Errors.Tools_error.pp_reference_lookup_error e
in
Error (`Msg error)
| Ok resolved_reference -> (
let identifier =
Odoc_model.Paths.Reference.Resolved.identifier resolved_reference
in
let url =
Odoc_document.Url.from_identifier ~stop_before:false identifier
in
match url with
| Error e -> Error (`Msg (Odoc_document.Url.Error.to_string e))
| Ok url ->
let href = url_to_string url in
print_endline href;
Ok ()))
let reference_to_url_html { Html_page.html_config = config; _ } root_url =
let url_to_string url =
let base =
match root_url with
| None | Some "" -> ""
| Some base ->
if base.[String.length base - 1] = '/' then base else base ^ "/"
in
Odoc_html.Link.(href ~config ~resolve:(Base base) url)
in
resolve url_to_string
let reference_to_url_latex =
let url_to_string url = Odoc_latex.Generator.Link.label url in
resolve url_to_string