Markdown code blocks
One backtick either side gives inline code. Three backticks on their own line open and close a block, and a language name after the opening fence turns on highlighting.
Run `npm install` first.Run npm install first.
```ts
export function render(source: string) {
return marked.parse(source);
}
```export function render(source: string) {
return marked.parse(source);
}
four spaces of indent
also makes a code blockfour spaces of indent
also makes a code block
Works, but you cannot set a language, and it breaks the moment someone reformats the file.
``a literal ` backtick``
````
```
A fenced block inside a fenced block
```
````a literal ` backtick
```
A fenced block inside a fenced block
```
Use more backticks on the outside than appear on the inside.
What usually goes wrong
- The closing fence must have at least as many backticks as the opening one, and nothing else on the line.
- Inside a list, a fenced block has to be indented to line up with the item's text or it ends the list.
- A language name is free text. An unknown one is not an error, it simply gets no colours.
- Tildes work as a fence too (
~~~), which is handy when the code itself is full of backticks.
Where it behaves differently
| Platform | Behaviour |
|---|---|
| GitHub | Around 500 languages, plus diff, mermaid and math as special cases. |
| Discord | Fenced blocks with a language work and are highlighted. |
| Slack | Fenced blocks work; the language name is ignored. |