diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2013-12-30 16:31:24 +1100 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2013-12-30 16:55:49 +1100 |
| commit | dedc29f128e2c87237ba4dea2dd0337e00f1320c (patch) | |
| tree | bd87f4cb9af3a6259cb802045469b7a156205aa8 /src | |
| parent | 582ad8ffc28429714b84d2dd8f01c780afb00b15 (diff) | |
| download | rust-dedc29f128e2c87237ba4dea2dd0337e00f1320c.tar.gz rust-dedc29f128e2c87237ba4dea2dd0337e00f1320c.zip | |
rustdoc: Unify the handling of the hidden example lines.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/html/markdown.rs | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index f445e11aa02..5da087eedbd 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -94,15 +94,26 @@ extern { } +/// Returns Some(code) if `s` is a line that should be stripped from +/// documentation but used in example code. `code` is the portion of +/// `s` that should be used in tests. (None for lines that should be +/// left as-is.) +fn stripped_filtered_line<'a>(s: &'a str) -> Option<&'a str> { + let trimmed = s.trim(); + if trimmed.starts_with("# ") { + Some(trimmed.slice_from(2)) + } else { + None + } +} + pub fn render(w: &mut io::Writer, s: &str) { extern fn block(ob: *buf, text: *buf, lang: *buf, opaque: *libc::c_void) { unsafe { let my_opaque: &my_opaque = cast::transmute(opaque); vec::raw::buf_as_slice((*text).data, (*text).size as uint, |text| { let text = str::from_utf8(text); - let mut lines = text.lines().filter(|l| { - !l.trim().starts_with("# ") - }); + let mut lines = text.lines().filter(|l| stripped_filtered_line(*l).is_none()); let text = lines.to_owned_vec().connect("\n"); let buf = buf { @@ -169,9 +180,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) { vec::raw::buf_as_slice((*text).data, (*text).size as uint, |text| { let tests: &mut ::test::Collector = intrinsics::transmute(opaque); let text = str::from_utf8(text); - let mut lines = text.lines().map(|l| { - if l.starts_with("# ") {l.slice_from(2)} else {l} - }); + let mut lines = text.lines().map(|l| stripped_filtered_line(l).unwrap_or(l)); let text = lines.to_owned_vec().connect("\n"); tests.add_test(text, ignore, shouldfail); }) |
