Skip to content

Commit

Permalink
HTML: Match rendering of polymorphic variant with normal variants
Browse files Browse the repository at this point in the history
Signed-off-by: Paul-Elliot <[email protected]>
  • Loading branch information
panglesd committed Jun 8, 2023
1 parent 7fa5ddc commit 5d56924
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 57 deletions.
4 changes: 3 additions & 1 deletion src/document/generator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,9 @@ module Make (Syntax : SYNTAX) = struct
let markers = Syntax.Comment.markers in
try
let url = Url.Anchor.polymorphic_variant ~type_ident item in
let attrs = [ "def"; Url.Anchor.string_of_kind url.kind ] in
let attrs =
[ "def"; "poly-variant"; Url.Anchor.string_of_kind url.kind ]
in
let anchor = Some url in
let code = O.code (O.txt "| ") @ cstr in
let doc = match doc with None -> [] | Some doc -> doc in
Expand Down
15 changes: 12 additions & 3 deletions src/html_support_files/odoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,11 @@ div.odoc-spec,.odoc-include {
margin-bottom: 2em;
}

.spec.type .variant p, .spec.type .record p {
.spec.type .variant p, .spec.type .record p, .spec.type .poly-variant p {
margin: 5px;
}

.spec.type .variant, .spec.type .record {
.spec.type .variant, .spec.type .record, .spec.type .poly-variant {
margin-left: 2ch;
list-style: none;
display: flex;
Expand All @@ -550,12 +550,21 @@ div.odoc-spec,.odoc-include {
min-width: 40%;
}

.spec.type .poly-variant > code {
min-width: 2ch;
}
.spec.type .poly-variant > code + code {
min-width: calc(40% - 2ch - 0.6ex);
/* In polymorphic variants, the | is not included in the first code block, so we
need to accound for its size */
}

.spec.type > ol {
margin-top: 0;
margin-bottom: 0;
}

.spec.type .record > .def-doc, .spec.type .variant > .def-doc {
.spec.type .record > .def-doc, .spec.type .variant > .def-doc, .spec.type .poly-variant > .def-doc {
min-width:50%;
padding: 0.25em 0.5em;
margin-left: 10%;
Expand Down
18 changes: 9 additions & 9 deletions src/html_support_files/odoc_html_support_files.ml

Large diffs are not rendered by default.

41 changes: 22 additions & 19 deletions test/generators/html/Ocamlary.html
Original file line number Diff line number Diff line change
Expand Up @@ -1058,12 +1058,12 @@ <h4 id="advanced-type-stuff">
<span> = </span><span>[ </span>
</code>
<ol>
<li id="type-poly_variant.TagA" class="def constructor anchored">
<a href="#type-poly_variant.TagA" class="anchor"></a>
<li id="type-poly_variant.TagA" class="def poly-variant constructor
anchored"><a href="#type-poly_variant.TagA" class="anchor"></a>
<code><span>| </span></code><code><span>`TagA</span></code>
</li>
<li id="type-poly_variant.ConstrB" class="def constructor anchored">
<a href="#type-poly_variant.ConstrB" class="anchor"></a>
<li id="type-poly_variant.ConstrB" class="def poly-variant constructor
anchored"><a href="#type-poly_variant.ConstrB" class="anchor"></a>
<code><span>| </span></code>
<code><span>`ConstrB <span class="keyword">of</span> int</span></code>
</li>
Expand Down Expand Up @@ -1285,13 +1285,15 @@ <h4 id="advanced-type-stuff">
<span> = </span><span>[ </span>
</code>
<ol>
<li id="type-poly_variant_union.poly_variant" class="def type anchored">
<li id="type-poly_variant_union.poly_variant" class="def poly-variant
type anchored">
<a href="#type-poly_variant_union.poly_variant" class="anchor"></a>
<code><span>| </span></code>
<code><span><a href="#type-poly_variant">poly_variant</a></span>
</code>
</li>
<li id="type-poly_variant_union.TagC" class="def constructor anchored">
<li id="type-poly_variant_union.TagC" class="def poly-variant
constructor anchored">
<a href="#type-poly_variant_union.TagC" class="anchor"></a>
<code><span>| </span></code><code><span>`TagC</span></code>
</li>
Expand All @@ -1310,7 +1312,8 @@ <h4 id="advanced-type-stuff">
</span><span> = </span><span>[ </span>
</code>
<ol>
<li id="type-poly_poly_variant.TagA" class="def constructor anchored">
<li id="type-poly_poly_variant.TagA" class="def poly-variant
constructor anchored">
<a href="#type-poly_poly_variant.TagA" class="anchor"></a>
<code><span>| </span></code>
<code>
Expand All @@ -1331,8 +1334,8 @@ <h4 id="advanced-type-stuff">
</span><span> = </span><span>[ </span>
</code>
<ol>
<li id="type-bin_poly_poly_variant.TagA" class="def constructor
anchored">
<li id="type-bin_poly_poly_variant.TagA" class="def poly-variant
constructor anchored">
<a href="#type-bin_poly_poly_variant.TagA" class="anchor"></a>
<code><span>| </span></code>
<code>
Expand All @@ -1341,8 +1344,8 @@ <h4 id="advanced-type-stuff">
</span>
</code>
</li>
<li id="type-bin_poly_poly_variant.ConstrB" class="def constructor
anchored">
<li id="type-bin_poly_poly_variant.ConstrB" class="def poly-variant
constructor anchored">
<a href="#type-bin_poly_poly_variant.ConstrB" class="anchor"></a>
<code><span>| </span></code>
<code>
Expand Down Expand Up @@ -1463,25 +1466,25 @@ <h4 id="advanced-type-stuff">
<span> = </span><span>[ </span>
</code>
<ol>
<li id="type-nested_poly_variant.A" class="def constructor anchored">
<a href="#type-nested_poly_variant.A" class="anchor"></a>
<li id="type-nested_poly_variant.A" class="def poly-variant constructor
anchored"><a href="#type-nested_poly_variant.A" class="anchor"></a>
<code><span>| </span></code><code><span>`A</span></code>
</li>
<li id="type-nested_poly_variant.B" class="def constructor anchored">
<a href="#type-nested_poly_variant.B" class="anchor"></a>
<li id="type-nested_poly_variant.B" class="def poly-variant constructor
anchored"><a href="#type-nested_poly_variant.B" class="anchor"></a>
<code><span>| </span></code>
<code>
<span>`B <span class="keyword">of</span>
<span>[ `B1 <span>| `B2</span> ]</span>
</span>
</code>
</li>
<li id="type-nested_poly_variant.C" class="def constructor anchored">
<a href="#type-nested_poly_variant.C" class="anchor"></a>
<li id="type-nested_poly_variant.C" class="def poly-variant constructor
anchored"><a href="#type-nested_poly_variant.C" class="anchor"></a>
<code><span>| </span></code><code><span>`C</span></code>
</li>
<li id="type-nested_poly_variant.D" class="def constructor anchored">
<a href="#type-nested_poly_variant.D" class="anchor"></a>
<li id="type-nested_poly_variant.D" class="def poly-variant constructor
anchored"><a href="#type-nested_poly_variant.D" class="anchor"></a>
<code><span>| </span></code>
<code>
<span>`D <span class="keyword">of</span>
Expand Down
4 changes: 2 additions & 2 deletions test/generators/html/Recent-module-type-PolyS.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ <h1>Module type <code><span>Recent.PolyS</span></code></h1>
<span>[ </span>
</code>
<ol>
<li id="type-t.A" class="def constructor anchored">
<li id="type-t.A" class="def poly-variant constructor anchored">
<a href="#type-t.A" class="anchor"></a><code><span>| </span></code>
<code><span>`A</span></code>
</li>
<li id="type-t.B" class="def constructor anchored">
<li id="type-t.B" class="def poly-variant constructor anchored">
<a href="#type-t.B" class="anchor"></a><code><span>| </span></code>
<code><span>`B</span></code>
</li>
Expand Down
16 changes: 8 additions & 8 deletions test/generators/html/Recent.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,24 +149,24 @@ <h1>Module <code><span>Recent</span></code></h1>
<span> = </span><span>[ </span>
</code>
<ol>
<li id="type-polymorphic_variant.A" class="def constructor anchored">
<a href="#type-polymorphic_variant.A" class="anchor"></a>
<li id="type-polymorphic_variant.A" class="def poly-variant constructor
anchored"><a href="#type-polymorphic_variant.A" class="anchor"></a>
<code><span>| </span></code><code><span>`A</span></code>
</li>
<li id="type-polymorphic_variant.B" class="def constructor anchored">
<a href="#type-polymorphic_variant.B" class="anchor"></a>
<li id="type-polymorphic_variant.B" class="def poly-variant constructor
anchored"><a href="#type-polymorphic_variant.B" class="anchor"></a>
<code><span>| </span></code>
<code><span>`B <span class="keyword">of</span> int</span></code>
</li>
<li id="type-polymorphic_variant.C" class="def constructor anchored">
<a href="#type-polymorphic_variant.C" class="anchor"></a>
<li id="type-polymorphic_variant.C" class="def poly-variant constructor
anchored"><a href="#type-polymorphic_variant.C" class="anchor"></a>
<code><span>| </span></code><code><span>`C</span></code>
<div class="def-doc"><span class="comment-delim">(*</span><p>foo</p>
<span class="comment-delim">*)</span>
</div>
</li>
<li id="type-polymorphic_variant.D" class="def constructor anchored">
<a href="#type-polymorphic_variant.D" class="anchor"></a>
<li id="type-polymorphic_variant.D" class="def poly-variant constructor
anchored"><a href="#type-polymorphic_variant.D" class="anchor"></a>
<code><span>| </span></code><code><span>`D</span></code>
<div class="def-doc"><span class="comment-delim">(*</span><p>bar</p>
<span class="comment-delim">*)</span>
Expand Down
30 changes: 15 additions & 15 deletions test/generators/html/Type.html
Original file line number Diff line number Diff line change
Expand Up @@ -385,23 +385,23 @@ <h1>Module <code><span>Type</span></code></h1>
<span> = </span><span>[ </span>
</code>
<ol>
<li id="type-polymorphic_variant.A" class="def constructor anchored">
<a href="#type-polymorphic_variant.A" class="anchor"></a>
<li id="type-polymorphic_variant.A" class="def poly-variant constructor
anchored"><a href="#type-polymorphic_variant.A" class="anchor"></a>
<code><span>| </span></code><code><span>`A</span></code>
</li>
<li id="type-polymorphic_variant.B" class="def constructor anchored">
<a href="#type-polymorphic_variant.B" class="anchor"></a>
<li id="type-polymorphic_variant.B" class="def poly-variant constructor
anchored"><a href="#type-polymorphic_variant.B" class="anchor"></a>
<code><span>| </span></code>
<code><span>`B <span class="keyword">of</span> int</span></code>
</li>
<li id="type-polymorphic_variant.C" class="def constructor anchored">
<a href="#type-polymorphic_variant.C" class="anchor"></a>
<li id="type-polymorphic_variant.C" class="def poly-variant constructor
anchored"><a href="#type-polymorphic_variant.C" class="anchor"></a>
<code><span>| </span></code>
<code><span>`C <span class="keyword">of</span> int * unit</span>
</code>
</li>
<li id="type-polymorphic_variant.D" class="def constructor anchored">
<a href="#type-polymorphic_variant.D" class="anchor"></a>
<li id="type-polymorphic_variant.D" class="def poly-variant constructor
anchored"><a href="#type-polymorphic_variant.D" class="anchor"></a>
<code><span>| </span></code><code><span>`D</span></code>
</li>
</ol><code><span> ]</span></code>
Expand All @@ -416,7 +416,7 @@ <h1>Module <code><span>Type</span></code></h1>
</code>
<ol>
<li id="type-polymorphic_variant_extension.polymorphic_variant"
class="def type anchored">
class="def poly-variant type anchored">
<a href="#type-polymorphic_variant_extension.polymorphic_variant"
class="anchor">
</a><code><span>| </span></code>
Expand All @@ -425,8 +425,8 @@ <h1>Module <code><span>Type</span></code></h1>
</span>
</code>
</li>
<li id="type-polymorphic_variant_extension.E" class="def constructor
anchored">
<li id="type-polymorphic_variant_extension.E" class="def poly-variant
constructor anchored">
<a href="#type-polymorphic_variant_extension.E" class="anchor"></a>
<code><span>| </span></code><code><span>`E</span></code>
</li>
Expand All @@ -441,8 +441,8 @@ <h1>Module <code><span>Type</span></code></h1>
</span><span> = </span><span>[ </span>
</code>
<ol>
<li id="type-nested_polymorphic_variant.A" class="def constructor
anchored">
<li id="type-nested_polymorphic_variant.A" class="def poly-variant
constructor anchored">
<a href="#type-nested_polymorphic_variant.A" class="anchor"></a>
<code><span>| </span></code>
<code>
Expand All @@ -462,8 +462,8 @@ <h1>Module <code><span>Type</span></code></h1>
<span>[&gt; </span>
</code>
<ol>
<li id="type-private_extenion.polymorphic_variant" class="def type
anchored">
<li id="type-private_extenion.polymorphic_variant" class="def
poly-variant type anchored">
<a href="#type-private_extenion.polymorphic_variant" class="anchor">
</a><code><span>| </span></code>
<code>
Expand Down

0 comments on commit 5d56924

Please sign in to comment.