Use fenced code blocks by enclosing code in three backticks. Code blocks are copyable, and if you have the assistant enabled, users can ask AI to explain the code.Specify the programming language for syntax highlighting and to enable meta options. Add any meta options, like a title or icon, after the language.
HelloWorld.java
Copy
Ask AI
class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); }}
Enable syntax highlighting by specifying the programming language after the opening backticks of a code block.We use Shiki for syntax highlighting and support all available languages. See the full list of languages in Shiki’s documentation.
Copy
Ask AI
class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); }}
Enable text wrapping for long lines using wrap. This prevents horizontal scrolling and makes long lines easier to read.
Wrap Example
Copy
Ask AI
const greeting = "Hello, World! I am a long line of text that will wrap to the next line.";function sayHello() { console.log(greeting);}sayHello();
Copy
Ask AI
```javascript Wrap Example wrapconst greeting = "Hello, World! I am a long line of text that will wrap to the next line.";function sayHello() { console.log(greeting);}sayHello();```
Show a visual diff of added or removed lines in your code blocks. Added lines are highlighted in green and removed lines are highlighted in red.To create diffs, add these special comments at the end of lines in your code block:
// [!code ++]: Mark a line as added (green highlight).
// [!code --]: Mark a line as removed (red highlight).
For multiple consecutive lines, specify the number of lines after a colon:
// [!code ++:3]: Mark the current line plus the next two lines as added.
// [!code --:5]: Mark the current line plus the next four lines as removed.
The comment syntax must match your programming language (for example, // for JavaScript or # for Python).