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.
Report incorrect code
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.Customize code block themes globally using styling.codeblocks in your docs.json file. Set simple themes like system or dark, or configure custom Shiki themes for light and dark modes. See Settings for configuration options.
Report incorrect code
Copy
Ask AI
class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); }}
In JavaScript and TypeScript code blocks, use twoslash to enable interactive type information. Users can hover over variables, functions, and parameters to see types and errors like in an IDE.
Report incorrect code
Copy
Ask AI
typePet = "cat" | "dog" | "hamster";functionadoptPet(name: string, type:Pet) { return `${name} the ${type} is now adopted!`;}// Hover to see the inferred typesconstmessage =adoptPet("Mintie", "cat");
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).