Skip to content

Commit 8ef9e2c

Browse files
authored
Rollup merge of rust-lang#51158 - ogham:patch-1, r=steveklabnik
Mention spec and indented blocks in doctest docs Fixes rust-lang#49717. This commit adds a new section to the Documentation Test docs, which briefly mentions indented code blocks, and links to the CommonMark specification for both. I’m not sure about saying "fenced code blocks the more popular choice in the Rust community” because it seems like I’m speaking for everyone, but I can’t think of a better way to phrase it!
2 parents 7dae5c0 + 8f8a7b9 commit 8ef9e2c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,27 @@ environment that has no network access.
305305
compiles, then the test will fail. However please note that code failing
306306
with the current Rust release may work in a future release, as new features
307307
are added.
308+
309+
## Syntax reference
310+
311+
The *exact* syntax for code blocks, including the edge cases, can be found
312+
in the [Fenced Code Blocks](https://spec.commonmark.org/0.28/#fenced-code-blocks)
313+
section of the CommonMark specification.
314+
315+
Rustdoc also accepts *indented* code blocks as an alternative to fenced
316+
code blocks: instead of surrounding your code with three backticks, you
317+
can indent each line by four or more spaces.
318+
319+
``````markdown
320+
let foo = "foo";
321+
assert_eq!(foo, "foo");
322+
``````
323+
324+
These, too, are documented in the CommonMark specification, in the
325+
[Indented Code Blocks](https://spec.commonmark.org/0.28/#indented-code-blocks)
326+
section.
327+
328+
However, it's preferable to use fenced code blocks over indented code blocks.
329+
Not only are fenced code blocks considered more idiomatic for Rust code,
330+
but there is no way to use directives such as `ignore` or `should_panic` with
331+
indented code blocks.

0 commit comments

Comments
 (0)