Skip to content

Commit e7f6289

Browse files
committedDec 29, 2013
auto merge of #11185 : huonw/rust/doc-ignore, r=alexcrichton
Currently any line starting with `#` is filtered from the output, including line like `#[deriving]`; this patch makes it so lines are only filtered when followed by a space similar to the current behaviour of the tutorial/manual tester.
2 parents afe8f6e + ff805f3 commit e7f6289

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed
 

‎doc/rustdoc.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@ specifiers that can be used to dictate how a code block is tested:
132132
~~~
133133

134134
Rustdoc also supplies some extra sugar for helping with some tedious
135-
documentation examples. If a line is prefixed with a `#` character, then the
136-
line will not show up in the HTML documentation, but it will be used when
137-
testing the code block.
135+
documentation examples. If a line is prefixed with `# `, then the line
136+
will not show up in the HTML documentation, but it will be used when
137+
testing the code block (NB. the space after the `#` is required, so
138+
that one can still write things like `#[deriving(Eq)]`).
138139

139140
~~~
140141
```rust

‎src/librustdoc/html/markdown.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn render(w: &mut io::Writer, s: &str) {
101101
vec::raw::buf_as_slice((*text).data, (*text).size as uint, |text| {
102102
let text = str::from_utf8(text);
103103
let mut lines = text.lines().filter(|l| {
104-
!l.trim().starts_with("#")
104+
!l.trim().starts_with("# ")
105105
});
106106
let text = lines.to_owned_vec().connect("\n");
107107

@@ -169,7 +169,9 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
169169
vec::raw::buf_as_slice((*text).data, (*text).size as uint, |text| {
170170
let tests: &mut ::test::Collector = intrinsics::transmute(opaque);
171171
let text = str::from_utf8(text);
172-
let mut lines = text.lines().map(|l| l.trim_chars(&'#'));
172+
let mut lines = text.lines().map(|l| {
173+
if l.starts_with("# ") {l.slice_from(2)} else {l}
174+
});
173175
let text = lines.to_owned_vec().connect("\n");
174176
tests.add_test(text, ignore, shouldfail);
175177
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTDOC) --test foo.rs
5+
$(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs
6+
cp verify.sh $(TMPDIR)
7+
$(call RUN,verify.sh) $(TMPDIR)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#[crate_id="foo#0.1"];
2+
3+
/// The '# ' lines should be removed from the output, but the #[deriving] should be
4+
/// retained.
5+
///
6+
/// ```rust
7+
/// # #[deriving(Eq)] // invisible
8+
/// # struct Foo; // invisible
9+
///
10+
/// #[deriving(Eq)] // Bar
11+
/// struct Bar(Foo);
12+
/// let x = Bar(Foo);
13+
/// assert!(x == x);
14+
/// ```
15+
pub fn foo() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
file = "$1/doc/foo/fn.foo.html"
4+
5+
grep -v 'invisible' $file &&
6+
grep '#\[deriving(Eq)\] // Bar' $file
7+
8+
exit $?

0 commit comments

Comments
 (0)
Please sign in to comment.