Skip to content

Commit ff2ff2b

Browse files
committed
rustdoc book on codeblock hash escaping
1 parent d3b4cb1 commit ff2ff2b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/doc/rustdoc/src/documentation-tests.md

+17
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,23 @@ By repeating all parts of the example, you can ensure that your example still
170170
compiles, while only showing the parts that are relevant to that part of your
171171
explanation.
172172
173+
The `#`-hiding of lines can be prevented by using two consecutive hashes
174+
`##`. This only needs to be done with with the first `#` which would've
175+
otherwise caused hiding. If we have a string literal like the following,
176+
which has a line that starts with a `#`:
177+
178+
```rust
179+
let s = "foo
180+
## bar # baz";
181+
```
182+
183+
We can document it by escaping the initial `#`:
184+
185+
```text
186+
/// let s = "foo
187+
/// ## bar # baz";
188+
```
189+
173190

174191
## Using `?` in doc tests
175192

0 commit comments

Comments
 (0)