Skip to content

Commit 43022d2

Browse files
committed
Add code blocks information to style guide
1 parent 6c12d54 commit 43022d2

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

docs/contributing/index.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,46 @@ They stand out better from the main text, and can be collapsed by default if nee
228228
This note is collapsed, because it uses `???`.
229229

230230
If an admonition is collapsed by default, it should have a title.
231+
232+
### Code blocks
233+
234+
Use [code blocks](https://squidfunk.github.io/mkdocs-material/reference/code-blocks/) when you want to display monospace text in a programming language, terminal output, configuration files etc.
235+
The documentation uses [pygments](https://pygments.org) for highlighting.
236+
See [list of available lexers](https://pygments.org/docs/lexers/#) for the languages that you can use for code blocks.
237+
238+
Use [`console`](https://pygments.org/docs/lexers/#pygments.lexers.shell.BashSessionLexer) for interactive sessions with prompt-output pairs:
239+
````markdown
240+
```console title="Hello, world!"
241+
$ echo "Hello, world!"
242+
Hello, world!
243+
```
244+
````
245+
246+
The above becomes:
247+
248+
```console title="Hello, world!"
249+
$ echo "Hello, world!"
250+
Hello, world!
251+
```
252+
253+
!!! warning
254+
`terminal` is not a valid lexer, but MkDocs or pygments will not warn about using it as a language.
255+
The text will be rendered without highlighting.
256+
257+
Note the use of `title=...`, which will give the code block a heading.
258+
259+
!!! tip
260+
Include a title whenever possible to describe what the code block does or is.
261+
262+
If you want to display commands without that can easily be copied, use `bash` as the language.
263+
````markdown
264+
```bash title="Hello, world!"
265+
echo "Hello, world!"
266+
```
267+
````
268+
269+
The above becomes:
270+
271+
```bash title="Hello, world!"
272+
echo "Hello, world!"
273+
```

0 commit comments

Comments
 (0)