Skip to content

Commit bca99b5

Browse files
committed
HTML generator: adding a class to distinguish external links
Signed-off-by: Paul-Elliot <peada@free.fr>
1 parent 0b1e129 commit bca99b5

File tree

7 files changed

+33
-22
lines changed

7 files changed

+33
-22
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
- Navigation for the search bar : use '/' to enter search, up and down arrows to
1212
select a result, and enter to follow the selected link. (@EmileTrotignon, #1088)
1313
- OCaml 5.2.0 compatibility (@Octachron, #1094)
14+
- Added a class to distinguish external and internal links in the html output
15+
(@panglesd, #767)
1416

1517
### Changed
1618

src/html/generator.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ and inline ~config ?(emph_level = 0) ~resolve (l : Inline.t) :
143143
let content = inline_nolink ~emph_level c in
144144
[ Html.span ~a content ]
145145
| Link (href, c) ->
146-
let a = (a :> Html_types.a_attrib Html.attrib list) in
146+
let a =
147+
(class_ ("external-link" :: t.attr)
148+
:> Html_types.a_attrib Html.attrib list)
149+
in
147150
let content = inline_nolink ~emph_level c in
148151
[ Html.a ~a:(Html.a_href href :: a) content ]
149152
| InternalLink c -> internallink ~config ~emph_level ~resolve ~a c

test/generators/html/Bugs.html

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

test/generators/html/Markup.html

+16-12
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ <h6 id="subparagraph"><a href="#subparagraph" class="anchor"></a>
103103
italics.
104104
</i>
105105
<i>It also work the same in
106-
<a href="#">links in italics with
106+
<a href="#" class="external-link">links in italics with
107107
<em>emphasis <em class="odd">in</em> emphasis</em>.
108108
</a>
109109
</i>
@@ -126,16 +126,20 @@ <h6 id="subparagraph"><a href="#subparagraph" class="anchor"></a>
126126
<h2 id="links-and-references">
127127
<a href="#links-and-references" class="anchor"></a>Links and references
128128
</h2>
129-
<p>This is a <a href="#">link</a>. It sends you to the top of this
130-
page. Links can have markup inside them: <a href="#"><b>bold</b></a>
131-
, <a href="#"><i>italics</i></a>, <a href="#"><em>emphasis</em></a>
132-
, <a href="#">super<sup>script</sup></a>,
133-
<a href="#">sub<sub>script</sub></a>, and
134-
<a href="#"><code>code</code></a>. Links can also be nested
135-
<em><a href="#">inside</a></em> markup. Links cannot be nested inside
136-
each other. This link has no replacement text: <a href="#">#</a>
137-
. The text is filled in by odoc. This is a shorthand link:
138-
<a href="#">#</a>. The text is also filled in by odoc in this case.
129+
<p>This is a <a href="#" class="external-link">link</a>. It sends
130+
you to the top of this page. Links can have markup inside them:
131+
<a href="#" class="external-link"><b>bold</b></a>,
132+
<a href="#" class="external-link"><i>italics</i></a>,
133+
<a href="#" class="external-link"><em>emphasis</em></a>,
134+
<a href="#" class="external-link">super<sup>script</sup></a>,
135+
<a href="#" class="external-link">sub<sub>script</sub></a>, and
136+
<a href="#" class="external-link"><code>code</code></a>. Links can
137+
also be nested <em><a href="#" class="external-link">inside</a></em>
138+
markup. Links cannot be nested inside each other. This link has
139+
no replacement text: <a href="#" class="external-link">#</a>. The
140+
text is filled in by odoc. This is a shorthand link:
141+
<a href="#" class="external-link">#</a>. The text is also filled
142+
in by odoc in this case.
139143
</p>
140144
<p>This is a reference to <a href="#val-foo"><code>foo</code></a>.
141145
References can have replacement text:
@@ -307,7 +311,7 @@ <h2 id="math"><a href="#math" class="anchor"></a>Math</h2>
307311
</ul>
308312
<ul class="at-tags">
309313
<li class="see"><span class="at-tag">see</span>
310-
<a href="#" class="value">#</a> <p>this url</p>
314+
<a href="#" class="external-link value">#</a> <p>this url</p>
311315
</li>
312316
</ul>
313317
<ul class="at-tags">

test/generators/html/Module.html

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

test/generators/html/Ocamlary.html

+5-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ <h1>Module <code><span>Ocamlary</span></code></h1>
7373
<div class="odoc-content">
7474
<p>You may find more information about this HTML documentation renderer
7575
at
76-
<a href="https://github.com/dsheets/ocamlary">github.com/dsheets/ocamlary
76+
<a href="https://github.com/dsheets/ocamlary" class="external-link">
77+
github.com/dsheets/ocamlary
7778
</a>.
7879
</p><p>This is some verbatim text:</p><pre>verbatim</pre>
7980
<p>This is some verbatim text:</p><pre>[][df[]]}}</pre>
@@ -484,8 +485,9 @@ <h4 id="basic-type-and-value-stuff-with-advanced-doc-comments">
484485
<div class="spec-doc">
485486
<ul class="at-tags">
486487
<li class="see"><span class="at-tag">see</span>
487-
<a href="http://ocaml.org/" class="value">http://ocaml.org/</a>
488-
<p>The OCaml Web site</p>
488+
<a href="http://ocaml.org/" class="external-link value">
489+
http://ocaml.org/
490+
</a> <p>The OCaml Web site</p>
489491
</li>
490492
</ul>
491493
</div>

test/xref2/github_issue_342.t/run.t

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ The rendered headings
3131
--
3232
<h2 id="an-url--and-with-text-in-a-title">
3333
<a href="#an-url--and-with-text-in-a-title" class="anchor"></a>An
34-
url <a href="http://ocaml.org">http://ocaml.org</a> and
35-
<a href="http://ocaml.org">with text</a> in a title
34+
url
35+
<a href="http://ocaml.org" class="external-link">http://ocaml.org</a>
3636

0 commit comments

Comments
 (0)