Skip to content

Commit ac6f154

Browse files
committed
auto merge of #7130 : huonw/rust/rustdoc-highlight, r=thestinger
This means that type definitions and function signatures have pretty colours.
2 parents 6df66c1 + d361802 commit ac6f154

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/librustdoc/markdown_pass.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -402,19 +402,17 @@ fn write_fnlike(
402402
fn write_sig(ctxt: &Ctxt, sig: Option<~str>) {
403403
match sig {
404404
Some(sig) => {
405-
ctxt.w.put_line(code_block_indent(sig));
405+
ctxt.w.put_line(code_block(sig));
406406
ctxt.w.put_line(~"");
407407
}
408408
None => fail!("unimplemented")
409409
}
410410
}
411411

412-
fn code_block_indent(s: ~str) -> ~str {
413-
let mut indented = ~[];
414-
for str::each_line_any(s) |line| {
415-
indented.push(fmt!(" %s", line));
416-
}
417-
indented.connect("\n")
412+
fn code_block(s: ~str) -> ~str {
413+
fmt!("~~~ {.rust}
414+
%s
415+
~~~", s)
418416
}
419417

420418
fn write_const(
@@ -754,17 +752,17 @@ mod test {
754752
#[test]
755753
fn should_write_the_function_signature() {
756754
let markdown = render(~"#[doc = \"f\"] fn a() { }");
757-
assert!(markdown.contains("\n fn a()\n"));
755+
assert!(markdown.contains("\n~~~ {.rust}\nfn a()\n"));
758756
}
759757

760758
#[test]
761759
fn should_insert_blank_line_after_fn_signature() {
762760
let markdown = render(~"#[doc = \"f\"] fn a() { }");
763-
assert!(markdown.contains("fn a()\n\n"));
761+
assert!(markdown.contains("fn a()\n~~~\n\n"));
764762
}
765763

766764
#[test]
767-
fn should_correctly_indent_fn_signature() {
765+
fn should_correctly_bracket_fn_signature() {
768766
let doc = create_doc(~"fn a() { }");
769767
let doc = doc::Doc{
770768
pages: ~[
@@ -781,13 +779,13 @@ mod test {
781779
]
782780
};
783781
let markdown = write_markdown_str(doc);
784-
assert!(markdown.contains(" line 1\n line 2"));
782+
assert!(markdown.contains("~~~ {.rust}\nline 1\nline 2\n~~~"));
785783
}
786784

787785
#[test]
788786
fn should_leave_blank_line_between_fn_header_and_sig() {
789787
let markdown = render(~"fn a() { }");
790-
assert!(markdown.contains("Function `a`\n\n fn a()"));
788+
assert!(markdown.contains("Function `a`\n\n~~~ {.rust}\nfn a()"));
791789
}
792790

793791
#[test]
@@ -887,7 +885,7 @@ mod test {
887885
#[test]
888886
fn should_write_trait_method_signature() {
889887
let markdown = render(~"trait i { fn a(&self); }");
890-
assert!(markdown.contains("\n fn a(&self)"));
888+
assert!(markdown.contains("\n~~~ {.rust}\nfn a(&self)"));
891889
}
892890

893891
#[test]
@@ -927,7 +925,7 @@ mod test {
927925
fn should_write_impl_method_signature() {
928926
let markdown = render(
929927
~"impl int { fn a(&mut self) { } }");
930-
assert!(markdown.contains("\n fn a(&mut self)"));
928+
assert!(markdown.contains("~~~ {.rust}\nfn a(&mut self)"));
931929
}
932930

933931
#[test]
@@ -946,7 +944,7 @@ mod test {
946944
#[test]
947945
fn should_write_type_signature() {
948946
let markdown = render(~"type t = int;");
949-
assert!(markdown.contains("\n\n type t = int\n\n"));
947+
assert!(markdown.contains("\n\n~~~ {.rust}\ntype t = int\n~~~\n"));
950948
}
951949

952950
#[test]

0 commit comments

Comments
 (0)