Skip to content

Commit 5a4aaf9

Browse files
committed
---
yaml --- r: 14766 b: refs/heads/try c: 4bbe33c h: refs/heads/master v: v3
1 parent be54156 commit 5a4aaf9

File tree

2 files changed

+67
-22
lines changed

2 files changed

+67
-22
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: 78d539927a20476206476847943c48f1a2f99e12
5+
refs/heads/try: 4bbe33c8ebab97b03d85bc3b1aa93884cf8555c4
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rustdoc/markdown_pass.rs

Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,15 @@ fn write_markdown(
9191
}
9292

9393
fn write_page(ctxt: ctxt, page: doc::page) {
94+
write_title(ctxt, page);
9495
alt page {
9596
doc::cratepage(doc) {
9697
write_crate(ctxt, doc);
9798
}
9899
doc::itempage(doc) {
99-
write_item(ctxt, doc);
100+
// We don't write a header for item's pages because their
101+
// header in the html output is created by the page title
102+
write_item_no_header(ctxt, doc);
100103
}
101104
}
102105
ctxt.w.write_done();
@@ -117,6 +120,45 @@ fn should_request_new_writer_for_each_page() {
117120
}
118121
}
119122

123+
fn write_title(ctxt: ctxt, page: doc::page) {
124+
ctxt.w.write_line(#fmt("%% %s", make_title(page)));
125+
ctxt.w.write_line("");
126+
}
127+
128+
fn make_title(page: doc::page) -> str {
129+
let item = alt page {
130+
doc::cratepage(cratedoc) {
131+
doc::modtag(cratedoc.topmod)
132+
}
133+
doc::itempage(itemtag) {
134+
itemtag
135+
}
136+
};
137+
let title = markdown_pass::header_text(item);
138+
let title = str::replace(title, "`", "");
139+
ret title;
140+
}
141+
142+
#[test]
143+
fn should_write_title_for_each_page() {
144+
let (writer_factory, po) = markdown_writer::future_writer_factory();
145+
let (srv, doc) = test::create_doc_srv(
146+
"#[link(name = \"core\")]; mod a { }");
147+
let doc = page_pass::mk_pass(config::doc_per_mod).f(srv, doc);
148+
write_markdown(doc, writer_factory);
149+
iter::repeat(2u) {||
150+
let (page, markdown) = comm::recv(po);
151+
alt page {
152+
doc::cratepage(_) {
153+
assert str::contains(markdown, "% Crate core");
154+
}
155+
doc::itempage(_) {
156+
assert str::contains(markdown, "% Module a");
157+
}
158+
}
159+
}
160+
}
161+
120162
enum hlvl {
121163
h1 = 1,
122164
h2 = 2,
@@ -210,7 +252,6 @@ fn write_crate(
210252
ctxt: ctxt,
211253
doc: doc::cratedoc
212254
) {
213-
write_header(ctxt, h1, doc::modtag(doc.topmod));
214255
write_top_module(ctxt, doc.topmod);
215256
}
216257

@@ -225,7 +266,6 @@ fn write_mod(
225266
ctxt: ctxt,
226267
moddoc: doc::moddoc
227268
) {
228-
write_header(ctxt, h1, doc::modtag(moddoc));
229269
write_mod_contents(ctxt, moddoc);
230270
}
231271

@@ -294,6 +334,18 @@ fn write_mod_contents(
294334
}
295335

296336
fn write_item(ctxt: ctxt, doc: doc::itemtag) {
337+
write_item_(ctxt, doc, true);
338+
}
339+
340+
fn write_item_no_header(ctxt: ctxt, doc: doc::itemtag) {
341+
write_item_(ctxt, doc, false);
342+
}
343+
344+
fn write_item_(ctxt: ctxt, doc: doc::itemtag, write_header: bool) {
345+
if write_header {
346+
write_item_header(ctxt, doc);
347+
}
348+
297349
alt doc {
298350
doc::modtag(moddoc) { write_mod(ctxt, moddoc) }
299351
doc::nmodtag(nmoddoc) { write_nmod(ctxt, nmoddoc) }
@@ -307,6 +359,17 @@ fn write_item(ctxt: ctxt, doc: doc::itemtag) {
307359
}
308360
}
309361

362+
fn write_item_header(ctxt: ctxt, doc: doc::itemtag) {
363+
write_header(ctxt, item_header_lvl(doc), doc);
364+
}
365+
366+
fn item_header_lvl(doc: doc::itemtag) -> hlvl {
367+
alt doc {
368+
doc::modtag(_) | doc::nmodtag(_) { h1 }
369+
_ { h2 }
370+
}
371+
}
372+
310373
#[test]
311374
fn should_write_crate_description() {
312375
let markdown = test::render("#[doc = \"this is the crate\"];");
@@ -354,7 +417,6 @@ fn should_not_write_index_if_no_entries() {
354417
}
355418

356419
fn write_nmod(ctxt: ctxt, doc: doc::nmoddoc) {
357-
write_header(ctxt, h1, doc::nmodtag(doc));
358420
write_common(ctxt, doc.desc(), doc.sections());
359421

360422
for fndoc in doc.fns {
@@ -379,7 +441,6 @@ fn write_fn(
379441
ctxt: ctxt,
380442
doc: doc::fndoc
381443
) {
382-
write_header(ctxt, h2, doc::fntag(doc));
383444
write_fnlike(
384445
ctxt,
385446
doc.sig,
@@ -463,7 +524,6 @@ fn write_const(
463524
ctxt: ctxt,
464525
doc: doc::constdoc
465526
) {
466-
write_header(ctxt, h2, doc::consttag(doc));
467527
write_sig(ctxt, doc.sig);
468528
write_common(ctxt, doc.desc(), doc.sections());
469529
}
@@ -486,7 +546,6 @@ fn write_enum(
486546
ctxt: ctxt,
487547
doc: doc::enumdoc
488548
) {
489-
write_header(ctxt, h2, doc::enumtag(doc));
490549
write_common(ctxt, doc.desc(), doc.sections());
491550
write_variants(ctxt, doc.variants);
492551
}
@@ -566,7 +625,6 @@ fn should_write_variant_list_with_signatures() {
566625
}
567626

568627
fn write_res(ctxt: ctxt, doc: doc::resdoc) {
569-
write_header(ctxt, h2, doc::restag(doc));
570628
write_sig(ctxt, doc.sig);
571629
write_common(ctxt, doc.desc(), doc.sections());
572630
}
@@ -584,7 +642,6 @@ fn should_write_resource_signature() {
584642
}
585643

586644
fn write_iface(ctxt: ctxt, doc: doc::ifacedoc) {
587-
write_header(ctxt, h2, doc::ifacetag(doc));
588645
write_common(ctxt, doc.desc(), doc.sections());
589646
write_methods(ctxt, doc.methods);
590647
}
@@ -631,7 +688,6 @@ fn should_write_iface_method_signature() {
631688
}
632689

633690
fn write_impl(ctxt: ctxt, doc: doc::impldoc) {
634-
write_header(ctxt, h2, doc::impltag(doc));
635691
write_common(ctxt, doc.desc(), doc.sections());
636692
write_methods(ctxt, doc.methods);
637693
}
@@ -673,7 +729,6 @@ fn write_type(
673729
ctxt: ctxt,
674730
doc: doc::tydoc
675731
) {
676-
write_header(ctxt, h2, doc::tytag(doc));
677732
write_sig(ctxt, doc.sig);
678733
write_common(ctxt, doc.desc(), doc.sections());
679734
}
@@ -759,16 +814,6 @@ mod test {
759814
ret tuple::second(comm::recv(po));
760815
}
761816

762-
#[test]
763-
fn write_markdown_should_write_crate_header() {
764-
astsrv::from_str("") {|srv|
765-
let doc = extract::from_srv(srv, "belch");
766-
let doc = attr_pass::mk_pass().f(srv, doc);
767-
let markdown = write_markdown_str(doc);
768-
assert str::contains(markdown, "# Crate `belch`");
769-
}
770-
}
771-
772817
#[test]
773818
fn write_markdown_should_write_mod_headers() {
774819
let markdown = render("mod moo { }");

0 commit comments

Comments
 (0)