Skip to content

Commit a77ea82

Browse files
authored
feat(docs): Centralize code block style guide (#2922)
- Moves the canonical documentation for code block annotations and language identifiers into STYLE.md. - Removes the redundant, partial documentation from GEMINI.md. - Updates GEMINI.md to instruct the AI assistant to always refer to STYLE.md for guidance. This change makes STYLE.md the single source of truth for all markdown and code style conventions, ensuring consistency for both human and AI contributors.
1 parent b183ee2 commit a77ea82

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

GEMINI.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ list of options.
7979
project tools with `cargo xtask install-tools`.
8080
- **Contributions:** Refer to `CONTRIBUTING.md` for guidelines on contributing
8181
to the project.
82-
- **Style:** Refer to `STYLE.md` for style guidelines.
82+
- **Style:** Refer to `STYLE.md` for style guidelines. When making changes to
83+
Markdown files in `src/`, always first read `STYLE.md` and follow its
84+
conventions.
8385
- **GitHub Actions:** The project uses composite GitHub Actions to simplify CI
8486
workflows. These actions should be preferred over hand-written commands.
8587
- **`apt-get-install`:** This action efficiently installs Debian packages. It
@@ -168,7 +170,3 @@ its tasks correctly.
168170
snippet, treat it as a self-contained program. Do not assume it shares a scope
169171
or context with other snippets in the same file unless the surrounding text
170172
explicitly states otherwise.
171-
- **Interpreting Annotations:** Annotations like `compile_fail`, `should_panic`,
172-
and `editable` describe how a snippet is tested. For example, `compile_fail`
173-
means the snippet is expected to fail compilation, which is useful for
174-
demonstrating common errors.

STYLE.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,36 @@ Contributors should design their slides with this interactivity in mind. The
161161
initial state of the code should be a good starting point for a live
162162
demonstration.
163163

164-
#### Code Annotations
164+
### Code Blocks
165165

166-
Use the `ignore` annotation for code snippets that are not meant to be complete,
167-
self-contained programs. Use `compile_fail` only when the goal is to demonstrate
168-
a specific compiler error that is itself the lesson.
166+
Code blocks are a critical part of the course. To ensure they are consistent and
167+
behave as expected, please follow these conventions.
168+
169+
#### Language Identifiers
170+
171+
Use the following language identifiers for fenced code blocks:
172+
173+
- **`rust`**: For Rust code examples.
174+
- **`shell`**: For shell commands. Use a `$` prompt for consistency. Omit the
175+
prompt for multi-line commands or when the output is shown.
176+
- **`bob`**: For ASCII art diagrams generated by `mdbook-bob`.
177+
- **`ignore`**: For code snippets that are not complete, self-contained programs
178+
or are for illustrative purposes only and should not be compiled.
179+
180+
#### mdbook Annotations
181+
182+
You can add annotations to Rust code blocks to control how they are tested and
183+
displayed:
184+
185+
- **`editable`**: Makes the code block an interactive playground where users can
186+
edit and run the code. This should be used for most Rust examples.
187+
- **`compile_fail`**: Indicates that the code is expected to fail compilation.
188+
This is used to demonstrate specific compiler errors.
189+
- **`should_panic`**: Indicates that the code is expected to panic when run.
190+
- **`warnunused`**: Re-enables `unused` lints for a code block. By default, the
191+
course's test runner disables lints for unused variables, imports, etc., to
192+
avoid distracting warnings. Use this annotation only when a warning is part of
193+
the lesson.
169194

170195
### Language and Tone
171196

0 commit comments

Comments
 (0)