rustdoc: Write indexes in output
This commit is contained in:
parent
3ed6f6520f
commit
87b9d67b66
|
@ -223,6 +223,9 @@ fn write_mod_contents(
|
||||||
) {
|
) {
|
||||||
write_brief(ctxt, doc.brief());
|
write_brief(ctxt, doc.brief());
|
||||||
write_desc(ctxt, doc.desc());
|
write_desc(ctxt, doc.desc());
|
||||||
|
if option::is_some(doc.index) {
|
||||||
|
write_index(ctxt, option::get(doc.index));
|
||||||
|
}
|
||||||
|
|
||||||
for itemtag in doc.items {
|
for itemtag in doc.items {
|
||||||
alt itemtag {
|
alt itemtag {
|
||||||
|
@ -251,6 +254,35 @@ fn should_write_crate_description() {
|
||||||
assert str::contains(markdown, "this is the crate");
|
assert str::contains(markdown, "this is the crate");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write_index(ctxt: ctxt, index: doc::index) {
|
||||||
|
if vec::is_empty(index.entries) {
|
||||||
|
ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
for entry in index.entries {
|
||||||
|
let header = header_text_(entry.kind, entry.name);
|
||||||
|
let id = entry.link;
|
||||||
|
ctxt.w.write_line(#fmt("* [%s](#%s)", header, id));
|
||||||
|
}
|
||||||
|
ctxt.w.write_line("");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_write_index() {
|
||||||
|
let markdown = test::render("mod a { } mod b { }");
|
||||||
|
assert str::contains(
|
||||||
|
markdown,
|
||||||
|
"\n\n* [Module `a`](#module-a)\n\
|
||||||
|
* [Module `b`](#module-b)\n\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_not_write_index_if_no_entries() {
|
||||||
|
let markdown = test::render("");
|
||||||
|
assert !str::contains(markdown, "\n\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
fn write_nmod(ctxt: ctxt, doc: doc::nmoddoc) {
|
fn write_nmod(ctxt: ctxt, doc: doc::nmoddoc) {
|
||||||
write_header(ctxt, h1, doc::nmodtag(doc));
|
write_header(ctxt, h1, doc::nmodtag(doc));
|
||||||
|
|
||||||
|
@ -905,6 +937,8 @@ mod test {
|
||||||
#debug("doc (path): %?", doc);
|
#debug("doc (path): %?", doc);
|
||||||
let doc = attr_pass::mk_pass().f(srv, doc);
|
let doc = attr_pass::mk_pass().f(srv, doc);
|
||||||
#debug("doc (attr): %?", doc);
|
#debug("doc (attr): %?", doc);
|
||||||
|
let doc = markdown_index_pass::mk_pass().f(srv, doc);
|
||||||
|
#debug("doc (index): %?", doc);
|
||||||
(srv, doc)
|
(srv, doc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue