Detail 04 / Sheet 04 of 08

Code blocks

Show code exactly as you typed it, inline in a sentence or in a fenced block that keeps every line break.

Backticks turn off every other rule. What sits between them reaches the reader exactly as you typed it, spacing included. Use inline code for a word in a sentence and a fenced block for anything with a line break.

Inline code

Use one backtick on each side for a command, a variable, or a short expression inside a sentence. The backticks vanish, and the text keeps its monospace face.

You type
`npm run dev`
Discord shows
npm run dev
One backtick per side keeps the command literal inside a sentence.

Inline code stays on one line. If the code itself contains a backtick, wrap the span in two backticks instead, so the inner one stays literal.

Fenced blocks

Put three backticks on a line of their own, then the code, then three more backticks on a line of their own. The fence lines vanish, and the lines between keep their breaks and indentation.

You type
```
const total = price * quantity
console.log(total)
```
Discord shows
const total = price * quantity
console.log(total)
The two fence lines are structural; they never reach the reader.

Everything inside is literal. Bold markers, mention tokens, and spoiler bars all stay as characters. You can put a fenced block above or below ordinary text in the same message; the fence only governs the lines between its markers. A blank line inside the block is part of the code, not the end of it.

Language tags

Put a language id immediately after the opening fence, on the same line. The id selects the highlighter and is not part of the code. Use lowercase; it is the form the highlighter expects. The syntax highlighting sheet lists the ids this guide uses.

You type
```bash
pnpm install
pnpm dev
```
Discord shows
pnpm install
pnpm dev
The id after the fence selects the highlighter; it is not part of the code.

Without an id the block still renders; it has no colour. An id the highlighter does not recognise also leaves the block plain.

Backticks inside a fence

A fence closes at the first run of three backticks. If the code itself contains that run, open and close with four backticks instead. The extra one is structural and does not appear in the code. Use the same number on both ends so the block closes where you expect.

If your client shows the extra backtick as part of the code, show the sample as inline code instead.

Watch out

An unclosed fence swallows the rest of the message. Every line after the opening fence stays inside the block until you close it, and a blank line does not end it. A missing final fence turns the remainder of your message into code. If a message looks like it never ends, add the closing fence at the bottom.