about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-06-22 16:50:39 +0800
committerGitHub <noreply@github.com>2018-06-22 16:50:39 +0800
commit8ef9e2c260647ca58d5ad80affd5b09184b87dc1 (patch)
tree2930de7bedd93efc61735b2671dd16d80408eae9
parent7dae5c0e06f10042fc3b29a55bf6285e539c06db (diff)
parent8f8a7b9a7b236ba02afc1589901acc6b125d6fec (diff)
downloadrust-8ef9e2c260647ca58d5ad80affd5b09184b87dc1.tar.gz
rust-8ef9e2c260647ca58d5ad80affd5b09184b87dc1.zip
Rollup merge of #51158 - ogham:patch-1, r=steveklabnik
Mention spec and indented blocks in doctest docs

Fixes #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!
-rw-r--r--src/doc/rustdoc/src/documentation-tests.md24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/doc/rustdoc/src/documentation-tests.md b/src/doc/rustdoc/src/documentation-tests.md
index cb233cc84cb..7639537fc55 100644
--- a/src/doc/rustdoc/src/documentation-tests.md
+++ b/src/doc/rustdoc/src/documentation-tests.md
@@ -305,3 +305,27 @@ environment that has no network access.
 compiles, then the test will fail. However please note that code failing
 with the current Rust release may work in a future release, as new features
 are added.
+
+## Syntax reference
+
+The *exact* syntax for code blocks, including the edge cases, can be found
+in the [Fenced Code Blocks](https://spec.commonmark.org/0.28/#fenced-code-blocks)
+section of the CommonMark specification.
+
+Rustdoc also accepts *indented* code blocks as an alternative to fenced
+code blocks: instead of surrounding your code with three backticks, you
+can indent each line by four or more spaces.
+
+``````markdown
+    let foo = "foo";
+    assert_eq!(foo, "foo");
+``````
+
+These, too, are documented in the CommonMark specification, in the
+[Indented Code Blocks](https://spec.commonmark.org/0.28/#indented-code-blocks)
+section.
+
+However, it's preferable to use fenced code blocks over indented code blocks.
+Not only are fenced code blocks considered more idiomatic for Rust code,
+but there is no way to use directives such as `ignore` or `should_panic` with
+indented code blocks.