Code blocks and includes
Markdown fenced code blocks (we will call them code examples as well) are inserted between two code fences (e.g. sets of triple backticks), with an optional info string (a.k.a. attributes ) after the first backtick group:
```rust
fn main() {}
```
mdbook allows including files into your book via include statements. mdbook interprets included files as Markdown. Since the include syntax is usually used for inserting code snippets and examples, it is often wrapped between two sets of backticks.
```rust
{{# include file.rs}}
```
An include path is relative to the Markdown file containing the directive.
mdBook also supports selecting a line or line range, or the content between
matching ANCHOR and ANCHOR_END markers. A :2:5 selector includes lines
2 through 5, while :setup selects the content inside the setup anchor.
See the mdBook include reference for the complete syntax.
The mdbook-utils markdown extract-code-examples command writes each fenced
Rust block to a deterministic file beneath the requested output directory.
The chapter’s source-relative path is retained in the output path, and blocks
are numbered in source order (block-000.rs, block-001.rs, and so on). This
prevents same-named chapters from overwriting each other’s examples. The
companion replace-code-examples-by-includes command uses the same mapping to
refer back to those files.