Skip to content

Commit 564bfab

Browse files
committed
---
yaml --- r: 97232 b: refs/heads/dist-snap c: dedc29f h: refs/heads/master v: v3
1 parent 2487711 commit 564bfab

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 582ad8ffc28429714b84d2dd8f01c780afb00b15
9+
refs/heads/dist-snap: dedc29f128e2c87237ba4dea2dd0337e00f1320c
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustdoc/html/markdown.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,26 @@ extern {
9494

9595
}
9696

97+
/// Returns Some(code) if `s` is a line that should be stripped from
98+
/// documentation but used in example code. `code` is the portion of
99+
/// `s` that should be used in tests. (None for lines that should be
100+
/// left as-is.)
101+
fn stripped_filtered_line<'a>(s: &'a str) -> Option<&'a str> {
102+
let trimmed = s.trim();
103+
if trimmed.starts_with("# ") {
104+
Some(trimmed.slice_from(2))
105+
} else {
106+
None
107+
}
108+
}
109+
97110
pub fn render(w: &mut io::Writer, s: &str) {
98111
extern fn block(ob: *buf, text: *buf, lang: *buf, opaque: *libc::c_void) {
99112
unsafe {
100113
let my_opaque: &my_opaque = cast::transmute(opaque);
101114
vec::raw::buf_as_slice((*text).data, (*text).size as uint, |text| {
102115
let text = str::from_utf8(text);
103-
let mut lines = text.lines().filter(|l| {
104-
!l.trim().starts_with("# ")
105-
});
116+
let mut lines = text.lines().filter(|l| stripped_filtered_line(*l).is_none());
106117
let text = lines.to_owned_vec().connect("\n");
107118

108119
let buf = buf {
@@ -169,9 +180,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
169180
vec::raw::buf_as_slice((*text).data, (*text).size as uint, |text| {
170181
let tests: &mut ::test::Collector = intrinsics::transmute(opaque);
171182
let text = str::from_utf8(text);
172-
let mut lines = text.lines().map(|l| {
173-
if l.starts_with("# ") {l.slice_from(2)} else {l}
174-
});
183+
let mut lines = text.lines().map(|l| stripped_filtered_line(l).unwrap_or(l));
175184
let text = lines.to_owned_vec().connect("\n");
176185
tests.add_test(text, ignore, shouldfail);
177186
})

0 commit comments

Comments
 (0)