Skip to main content

Code Blocks

Docusaurus utilizes prism for code highlighting and syntax definition.

Language Specification

The base prism installation supports very few languages by default. If your code block utilizes an unsupported language, you can add support for it via the prism object in the docusaurus.config.ts file. We've already added support for a few additional languages, including Solidity, Bash, and JSON.

To add a language specification to a code block, simply put the language name after the opening code block ticks.

For example, the following code block utilizes the bash language specification:

```bash
echo 'example'
```

Which renders as:

echo 'example'

Code Highlighting

prism provides succinct syntax for highlighting individual lines within a code block.

The following example highlights lines 1 and 3 of the code block:

```js {1,3}
const example = 'example';
const string = 'string';
const number = 1;
```

Which renders as:

const example = 'example';
const string = 'string';
const number = 1;