Skip to content

Commit ebe28f7

Browse files
authored
Rollup merge of #81389 - ehuss:rustdoc-cmark-extensions, r=GuillaumeGomez
rustdoc: Document CommonMark extensions. This updates the rustdoc book to include some documentation on the CommonMark extensions that rustdoc supports.
2 parents acbd101 + 1c0a52d commit ebe28f7

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

src/doc/rustdoc/src/how-to-write-documentation.md

+65-1
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,73 @@ and finally provides a code example.
153153

154154
## Markdown
155155

156-
`rustdoc` uses the [commonmark markdown specification]. You might be
156+
`rustdoc` uses the [CommonMark markdown specification]. You might be
157157
interested into taking a look at their website to see what's possible to do.
158158
- [commonmark quick reference]
159159
- [current spec]
160160

161+
In addition to the standard CommonMark syntax, `rustdoc` supports several
162+
extensions:
163+
164+
### Strikethrough
165+
166+
Text may be rendered with a horizontal line through the center by wrapping the
167+
text with two tilde characters on each side:
168+
169+
```text
170+
An example of ~~strikethrough text~~.
171+
```
172+
173+
This example will render as:
174+
175+
> An example of ~~strikethrough text~~.
176+
177+
This follows the [GitHub Strikethrough extension][strikethrough].
178+
179+
### Footnotes
180+
181+
A footnote generates a small numbered link in the text which when clicked
182+
takes the reader to the footnote text at the bottom of the item. The footnote
183+
label is written similarly to a link reference with a caret at the front. The
184+
footnote text is written like a link reference definition, with the text
185+
following the label. Example:
186+
187+
```text
188+
This is an example of a footnote[^note].
189+
190+
[^note]: This text is the contents of the footnote, which will be rendered
191+
towards the bottom.
192+
```
193+
194+
This example will render as:
195+
196+
> This is an example of a footnote[^note].
197+
>
198+
> [^note]: This text is the contents of the footnote, which will be rendered
199+
> towards the bottom.
200+
201+
The footnotes are automatically numbered based on the order the footnotes are
202+
written.
203+
204+
### Tables
205+
206+
Tables can be written using pipes and dashes to draw the rows and columns of
207+
the table. These will be translated to HTML table matching the shape. Example:
208+
209+
```text
210+
| Header1 | Header2 |
211+
|---------|---------|
212+
| abc | def |
213+
```
214+
215+
This example will render similarly to this:
216+
217+
> | Header1 | Header2 |
218+
> |---------|---------|
219+
> | abc | def |
220+
221+
See the specification for the [GitHub Tables extension][tables] for more
222+
details on the exact syntax supported.
161223

162224
[`backtrace`]: https://docs.rs/backtrace/0.3.50/backtrace/
163225
[commonmark markdown specification]: https://commonmark.org/
@@ -170,3 +232,5 @@ interested into taking a look at their website to see what's possible to do.
170232
[standard library]: https://doc.rust-lang.org/stable/std/index.html
171233
[current spec]: https://spec.commonmark.org/current/
172234
[`std::env`]: https://doc.rust-lang.org/stable/std/env/index.html#functions
235+
[strikethrough]: https://github.github.com/gfm/#strikethrough-extension-
236+
[tables]: https://github.github.com/gfm/#tables-extension-

0 commit comments

Comments
 (0)