Skip to content

Commit 6aa6016

Browse files
committed
adding a font-awesome icon for external links
Signed-off-by: Paul-Elliot <[email protected]>
1 parent a919b8b commit 6aa6016

File tree

6 files changed

+39
-21
lines changed

6 files changed

+39
-21
lines changed

src/html/generator.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ and inline ?(emph_level = 0) ~resolve (l : Inline.t) : phrasing Html.elt list =
113113
let emph_level, app_style = styled style ~emph_level in
114114
[ app_style @@ inline ~emph_level ~resolve c ]
115115
| Link (href, c) ->
116-
let a = (a :> Html_types.a_attrib Html.attrib list) in
116+
let a =
117+
(class_ ("external-link" :: t.attr)
118+
:> Html_types.a_attrib Html.attrib list)
119+
in
117120
let content = inline_nolink ~emph_level c in
118121
[ Html.a ~a:(Html.a_href href :: a) content ]
119122
| InternalLink c -> internallink ~emph_level ~resolve ~a c

src/odoc/etc/odoc.css

+10-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,16 @@ a.anchor {
298298
.xref-unresolved:hover {
299299
box-shadow: 0 1px 0 0 var(--xref-shadow);
300300
}
301-
301+
.external-link::after {
302+
display: inline-block;
303+
content: "";
304+
mask-image: url("data:image/svg+xml;utf8,<svg aria-hidden='true' focusable='false' data-prefix='fas' data-icon='up-right-from-square' class='svg-inline--fa fa-up-right-from-square' role='img' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'><path d='M384 320c-17.67 0-32 14.33-32 32v96H64V160h96c17.67 0 32-14.32 32-32s-14.33-32-32-32L64 96c-35.35 0-64 28.65-64 64V448c0 35.34 28.65 64 64 64h288c35.35 0 64-28.66 64-64v-96C416 334.3 401.7 320 384 320zM488 0H352c-12.94 0-24.62 7.797-29.56 19.75c-4.969 11.97-2.219 25.72 6.938 34.88L370.8 96L169.4 297.4c-12.5 12.5-12.5 32.75 0 45.25C175.6 348.9 183.8 352 192 352s16.38-3.125 22.62-9.375L416 141.3l41.38 41.38c9.156 9.141 22.88 11.84 34.88 6.938C504.2 184.6 512 172.9 512 160V24C512 10.74 501.3 0 488 0z'></path></svg>");
305+
-webkit-mask-image: url("data:image/svg+xml;utf8,<svg aria-hidden='true' focusable='false' data-prefix='fas' data-icon='up-right-from-square' class='svg-inline--fa fa-up-right-from-square' role='img' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'><path d='M384 320c-17.67 0-32 14.33-32 32v96H64V160h96c17.67 0 32-14.32 32-32s-14.33-32-32-32L64 96c-35.35 0-64 28.65-64 64V448c0 35.34 28.65 64 64 64h288c35.35 0 64-28.66 64-64v-96C416 334.3 401.7 320 384 320zM488 0H352c-12.94 0-24.62 7.797-29.56 19.75c-4.969 11.97-2.219 25.72 6.938 34.88L370.8 96L169.4 297.4c-12.5 12.5-12.5 32.75 0 45.25C175.6 348.9 183.8 352 192 352s16.38-3.125 22.62-9.375L416 141.3l41.38 41.38c9.156 9.141 22.88 11.84 34.88 6.938C504.2 184.6 512 172.9 512 160V24C512 10.74 501.3 0 488 0z'></path></svg>");
306+
width: 0.75em;
307+
height: 0.75em;
308+
background-color: currentColor;
309+
margin-left: 0.1em;
310+
}
302311
/* Section and document divisions.
303312
Until at least 4.03 many of the modules of the stdlib start at .h7,
304313
we restart the sequence there like h2 */

test/generators/html/Bugs.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ <h1>Module <code><span>Bugs</span></code></h1>
3333
</div>
3434
<div class="spec-doc">
3535
<p>Triggers an assertion failure when
36-
<a href="https://github.com/ocaml/odoc/issues/101">
37-
https://github.com/ocaml/odoc/issues/101
36+
<a href="https://github.com/ocaml/odoc/issues/101"
37+
class="external-link">https://github.com/ocaml/odoc/issues/101
3838
</a> is not fixed.
3939
</p>
4040
</div>

test/generators/html/Markup.html

+16-12
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ <h6 id="subparagraph"><a href="#subparagraph" class="anchor"></a>
7878
italics.
7979
</i>
8080
<i>It also work the same in
81-
<a href="#">links in italics with
81+
<a href="#" class="external-link">links in italics with
8282
<em>emphasis <em class="odd">in</em> emphasis</em>.
8383
</a>
8484
</i>
@@ -101,16 +101,20 @@ <h6 id="subparagraph"><a href="#subparagraph" class="anchor"></a>
101101
<h2 id="links-and-references">
102102
<a href="#links-and-references" class="anchor"></a>Links and references
103103
</h2>
104-
<p>This is a <a href="#">link</a>. It sends you to the top of this
105-
page. Links can have markup inside them: <a href="#"><b>bold</b></a>
106-
, <a href="#"><i>italics</i></a>, <a href="#"><em>emphasis</em></a>
107-
, <a href="#">super<sup>script</sup></a>,
108-
<a href="#">sub<sub>script</sub></a>, and
109-
<a href="#"><code>code</code></a>. Links can also be nested
110-
<em><a href="#">inside</a></em> markup. Links cannot be nested inside
111-
each other. This link has no replacement text: <a href="#">#</a>
112-
. The text is filled in by odoc. This is a shorthand link:
113-
<a href="#">#</a>. The text is also filled in by odoc in this case.
104+
<p>This is a <a href="#" class="external-link">link</a>. It sends
105+
you to the top of this page. Links can have markup inside them:
106+
<a href="#" class="external-link"><b>bold</b></a>,
107+
<a href="#" class="external-link"><i>italics</i></a>,
108+
<a href="#" class="external-link"><em>emphasis</em></a>,
109+
<a href="#" class="external-link">super<sup>script</sup></a>,
110+
<a href="#" class="external-link">sub<sub>script</sub></a>, and
111+
<a href="#" class="external-link"><code>code</code></a>. Links can
112+
also be nested <em><a href="#" class="external-link">inside</a></em>
113+
markup. Links cannot be nested inside each other. This link has
114+
no replacement text: <a href="#" class="external-link">#</a>. The
115+
text is filled in by odoc. This is a shorthand link:
116+
<a href="#" class="external-link">#</a>. The text is also filled
117+
in by odoc in this case.
114118
</p>
115119
<p>This is a reference to <a href="#val-foo"><code>foo</code></a>.
116120
References can have replacement text:
@@ -209,7 +213,7 @@ <h2 id="modules"><a href="#modules" class="anchor"></a>Modules</h2>
209213
</ul>
210214
<ul class="at-tags">
211215
<li class="see"><span class="at-tag">see</span>
212-
<a href="#" class="value">#</a> <p>this url</p>
216+
<a href="#" class="external-link value">#</a> <p>this url</p>
213217
</li>
214218
</ul>
215219
<ul class="at-tags">

test/generators/html/Module.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ <h1>Module <code><span>Module</span></code></h1><p>Foo.</p>
1919
<div class="spec-doc">
2020
<p>The module needs at least one signature item, otherwise a bug
2121
causes the compiler to drop the module comment (above). See
22-
<a href="https://caml.inria.fr/mantis/view.php?id=7701">
23-
https://caml.inria.fr/mantis/view.php?id=7701
22+
<a href="https://caml.inria.fr/mantis/view.php?id=7701"
23+
class="external-link">https://caml.inria.fr/mantis/view.php?id=7701
2424
</a>.
2525
</p>
2626
</div>

test/generators/html/Ocamlary.html

+5-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ <h1>Module <code><span>Ocamlary</span></code></h1>
7272
<div class="odoc-content">
7373
<p>You may find more information about this HTML documentation renderer
7474
at
75-
<a href="https://github.com/dsheets/ocamlary">github.com/dsheets/ocamlary
75+
<a href="https://github.com/dsheets/ocamlary" class="external-link">
76+
github.com/dsheets/ocamlary
7677
</a>.
7778
</p><p>This is some verbatim text:</p><pre>verbatim</pre>
7879
<p>This is some verbatim text:</p><pre>[][df[]]}}</pre>
@@ -455,8 +456,9 @@ <h4 id="basic-type-and-value-stuff-with-advanced-doc-comments">
455456
<div class="spec-doc">
456457
<ul class="at-tags">
457458
<li class="see"><span class="at-tag">see</span>
458-
<a href="http://ocaml.org/" class="value">http://ocaml.org/</a>
459-
<p>The OCaml Web site</p>
459+
<a href="http://ocaml.org/" class="external-link value">
460+
http://ocaml.org/
461+
</a> <p>The OCaml Web site</p>
460462
</li>
461463
</ul>
462464
</div>

0 commit comments

Comments
 (0)