Skip to content

Commit ba41342

Browse files
committed
rustdoc: Add gen::subsection for managing header levels
1 parent ab86642 commit ba41342

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/rustdoc/gen.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,16 @@ fn write_header(ctxt: ctxt, title: str) {
2525
ctxt.w.write_line(#fmt("%s %s", hashes, title));
2626
}
2727

28+
fn subsection(ctxt: ctxt, f: fn&()) {
29+
ctxt.depth += 1u;
30+
f();
31+
ctxt.depth -= 1u;
32+
}
33+
2834
fn write_crate(
2935
ctxt: ctxt,
3036
doc: doc::cratedoc
3137
) {
32-
ctxt.depth = 1u;
3338
write_header(ctxt, #fmt("Crate %s", doc.topmod.name));
3439
write_top_module(ctxt, doc.topmod);
3540
}
@@ -53,19 +58,22 @@ fn write_mod_contents(
5358
moddoc: doc::moddoc
5459
) {
5560
for fndoc in *moddoc.fns {
56-
write_fn(ctxt, fndoc);
61+
subsection(ctxt) {||
62+
write_fn(ctxt, fndoc);
63+
}
5764
}
5865

5966
for moddoc in *moddoc.mods {
60-
write_mod(ctxt, moddoc);
67+
subsection(ctxt) {||
68+
write_mod(ctxt, moddoc);
69+
}
6170
}
6271
}
6372

6473
fn write_fn(
6574
ctxt: ctxt,
6675
doc: doc::fndoc
6776
) {
68-
ctxt.depth = 2u;
6977
write_header(ctxt, #fmt("Function `%s`", doc.name));
7078
alt doc.brief {
7179
some(brief) {

0 commit comments

Comments
 (0)