Skip to content

Commit 7a70ec1

Browse files
committed
rustdoc: hardcode each header as a link.
This avoids having to include JS in the guide/tutorial/manual pages just to get the headers being links. The on-hover behaviour showing the little section marker § is preserved, because that gives a useful hint that the heading is a link.
1 parent f22c96c commit 7a70ec1

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

src/librustdoc/html/markdown.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ pub fn render(w: &mut io::Writer, s: &str, print_toc: bool) -> fmt::Result {
209209
};
210210

211211
// Render the HTML
212-
let text = format!(r#"<h{lvl} id="{id}">{sec_len,plural,=0{}other{{sec} }}{}</h{lvl}>"#,
212+
let text = format!(r#"<h{lvl} id="{id}"><a
213+
href="\#{id}">{sec_len,plural,=0{}other{{sec} }}{}</a></h{lvl}>"#,
213214
s, lvl = level, id = id,
214215
sec_len = sec.len(), sec = sec);
215216

src/librustdoc/html/render.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,8 @@ fn item_module(w: &mut Writer, cx: &Context,
10641064
clean::ForeignStaticItem(..) => ("ffi-statics", "Foreign Statics"),
10651065
clean::MacroItem(..) => ("macros", "Macros"),
10661066
};
1067-
try!(write!(w, "<h2 id='{}'>{}</h2>\n<table>", short, name));
1067+
try!(write!(w, "<h2 id='{id}'><a href=\"\\#{id}\">{name}</a></h2>\n<table>",
1068+
id = short, name = name));
10681069
}
10691070

10701071
match myitem.inner {

src/librustdoc/html/static/main.css

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,16 @@ pre.rust .string { color: #718C00; }
320320
pre.rust .lifetime { color: #C13928; }
321321
pre.rust .attribute, pre.rust .attribute .ident { color: #C82829; }
322322

323-
h1 a.anchor,
324-
h2 a.anchor,
325-
h3 a.anchor { display: none; }
326-
h1:hover a.anchor,
327-
h2:hover a.anchor,
328-
h3:hover a.anchor { display: inline-block; }
323+
h1:hover a:after,
324+
h2:hover a:after,
325+
h3:hover a:after,
326+
h4:hover a:after,
327+
h5:hover a:after,
328+
h6:hover a:after {
329+
content: ' § ';
330+
}
331+
332+
h1.fqn:hover a:after,
333+
:hover a.fnname:after {
334+
content: none;
335+
}

src/librustdoc/html/static/main.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,4 @@
600600

601601
initSearch(searchIndex);
602602

603-
$.each($('h1, h2, h3'), function(idx, element) {
604-
if ($(element).attr('id') != undefined) {
605-
$(element).append('<a href="#' + $(element).attr('id') + '" ' +
606-
'class="anchor"> § </a>');
607-
}
608-
});
609603
}());

0 commit comments

Comments
 (0)