Skip to content

Commit 0bce14a

Browse files
committed
---
yaml --- r: 14598 b: refs/heads/try c: 87b9d67 h: refs/heads/master v: v3
1 parent 218786d commit 0bce14a

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 3ed6f6520f56204f1c7c799ec8fa231bef0fb4d1
5+
refs/heads/try: 87b9d67b66daa43393f150a66158a71a8cd99a4a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rustdoc/markdown_pass.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ fn write_mod_contents(
223223
) {
224224
write_brief(ctxt, doc.brief());
225225
write_desc(ctxt, doc.desc());
226+
if option::is_some(doc.index) {
227+
write_index(ctxt, option::get(doc.index));
228+
}
226229

227230
for itemtag in doc.items {
228231
alt itemtag {
@@ -251,6 +254,35 @@ fn should_write_crate_description() {
251254
assert str::contains(markdown, "this is the crate");
252255
}
253256

257+
fn write_index(ctxt: ctxt, index: doc::index) {
258+
if vec::is_empty(index.entries) {
259+
ret;
260+
}
261+
262+
for entry in index.entries {
263+
let header = header_text_(entry.kind, entry.name);
264+
let id = entry.link;
265+
ctxt.w.write_line(#fmt("* [%s](#%s)", header, id));
266+
}
267+
ctxt.w.write_line("");
268+
}
269+
270+
#[test]
271+
fn should_write_index() {
272+
let markdown = test::render("mod a { } mod b { }");
273+
assert str::contains(
274+
markdown,
275+
"\n\n* [Module `a`](#module-a)\n\
276+
* [Module `b`](#module-b)\n\n"
277+
);
278+
}
279+
280+
#[test]
281+
fn should_not_write_index_if_no_entries() {
282+
let markdown = test::render("");
283+
assert !str::contains(markdown, "\n\n\n");
284+
}
285+
254286
fn write_nmod(ctxt: ctxt, doc: doc::nmoddoc) {
255287
write_header(ctxt, h1, doc::nmodtag(doc));
256288

@@ -905,6 +937,8 @@ mod test {
905937
#debug("doc (path): %?", doc);
906938
let doc = attr_pass::mk_pass().f(srv, doc);
907939
#debug("doc (attr): %?", doc);
940+
let doc = markdown_index_pass::mk_pass().f(srv, doc);
941+
#debug("doc (index): %?", doc);
908942
(srv, doc)
909943
}
910944
}

0 commit comments

Comments
 (0)