Skip to content

Commit ddf0972

Browse files
committed
Fix reference urls to sections
It was using the wrong parent (which defines the containing page).
1 parent 2dad3bf commit ddf0972

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

src/document/url.ml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ module Anchor = struct
144144
let add_suffix ~kind { page; anchor; _ } suffix =
145145
{ page; anchor = anchor ^ "." ^ suffix; kind }
146146

147+
let mk ~kind parent str_name =
148+
let page = Path.from_identifier parent in
149+
Ok { page; anchor = str_name; kind }
150+
147151
let rec from_identifier : Identifier.t -> (t, Error.t) result =
148152
let open Error in
149153
function
@@ -230,16 +234,15 @@ module Anchor = struct
230234
let kind = "field" in
231235
let suffix = FieldName.to_string name in
232236
Ok (add_suffix ~kind page suffix)
233-
| `Label (parent, anchor') -> (
234-
let anchor = LabelName.to_string anchor' in
235-
from_identifier (parent :> Identifier.t) >>= function
236-
| { page; anchor = _; kind } ->
237-
(* Really ad-hoc and shitty, but it works. *)
238-
if kind = "page" then Ok { page; anchor; kind }
239-
else Ok { page; anchor; kind = "" })
240-
241-
(* | _ ->
242-
Error (Unexpected_anchor ("label " ^ anchor)) *)
237+
| `Label (parent, anchor) -> (
238+
let str_name = LabelName.to_string anchor in
239+
(* [Identifier.LabelParent.t] contains datatypes. [`CoreType] can't
240+
happen, [`Type] may not happen either but just in case, use the
241+
grand-parent. *)
242+
match parent with
243+
| #Path.source as parent -> mk ~kind:"section" parent str_name
244+
| `CoreType _ -> Error (Unexpected_anchor "core_type label parent")
245+
| `Type (gp, _) -> mk ~kind:"section" gp str_name)
243246

244247
let polymorphic_variant ~type_ident elt =
245248
let name_of_type_constr te =

test/html/expect/test_package+ml/Ocamlary/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,7 +1922,7 @@ <h2 id="section-title-splicing">
19221922
<code>{!section:SuperSig.SubSigA.subSig}</code> : <code>SuperSig</code>.SubSigA.subSig
19231923
</li>
19241924
<li>
1925-
<code>{!Aliases.incl}</code> : <a href="#incl"><code>Aliases:incl</code></a>
1925+
<code>{!Aliases.incl}</code> : <a href="Aliases/index.html#incl"><code>Aliases:incl</code></a>
19261926
</li>
19271927
</ul>
19281928
<p>
@@ -1939,7 +1939,7 @@ <h2 id="section-title-splicing">
19391939
<code>{{!section:SuperSig.SubSigA.subSig}C}</code> : <span class="xref-unresolved">C</span>
19401940
</li>
19411941
<li>
1942-
<code>{{!Aliases.incl}D}</code> : <a href="#incl">D</a>
1942+
<code>{{!Aliases.incl}D}</code> : <a href="Aliases/index.html#incl">D</a>
19431943
</li>
19441944
</ul>
19451945
<h2 id="new-reference-syntax">

test/html/expect/test_package+re/Ocamlary/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ <h2 id="section-title-splicing">
19391939
<code>{!section:SuperSig.SubSigA.subSig}</code> : <code>SuperSig</code>.SubSigA.subSig
19401940
</li>
19411941
<li>
1942-
<code>{!Aliases.incl}</code> : <a href="#incl"><code>Aliases:incl</code></a>
1942+
<code>{!Aliases.incl}</code> : <a href="Aliases/index.html#incl"><code>Aliases:incl</code></a>
19431943
</li>
19441944
</ul>
19451945
<p>
@@ -1956,7 +1956,7 @@ <h2 id="section-title-splicing">
19561956
<code>{{!section:SuperSig.SubSigA.subSig}C}</code> : <span class="xref-unresolved">C</span>
19571957
</li>
19581958
<li>
1959-
<code>{{!Aliases.incl}D}</code> : <a href="#incl">D</a>
1959+
<code>{{!Aliases.incl}D}</code> : <a href="Aliases/index.html#incl">D</a>
19601960
</li>
19611961
</ul>
19621962
<h2 id="new-reference-syntax">

test/xref2/labels.t/run.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ There are two references in N, one should point to a local label and the other t
5454
</nav>
5555
<div class="odoc-content">
5656
<h2 id="B"><a href="#B" class="anchor"></a>An other conflicting label</h2>
57-
<p><a href="../index.html#B">An other conflicting label</a>
58-
<a href="../index.html#B"><code>M:B</code></a>
57+
<p><a href="#B">An other conflicting label</a>
58+
<a href="../M/index.html#B"><code>M:B</code></a>
5959
</p>
6060
</div>
6161
</body>

0 commit comments

Comments
 (0)