Codeblocks
The PostHog website has a custom codeblock component that comes with a number of useful features built-in:
Basic codeblock
Codeblocks in PostHog are created by enclosing your snippet using three backticks (```) or three tildes (~~~), as shown below:
This will produce the following codeblock:
Adding syntax highlighting
Syntax highlighting can be added by specifying a language for the codeblock, which is done by appending the name of the language directly after the opening backticks or tildes as shown below.
This will produce the following output:
Supported languages
Here is a list of all the languages that are supported in codeblocks:
Frontend
| HTML | html | 
| CSS / SCSS / LESS | css/less | 
| JavaScript | js | 
| JSX | jsx | 
| TypeScript | ts | 
| TSX | tsx | 
| Swift | swift | 
| Dart | dart | 
| Objective-C | objectivec | 
Backend
| Node.js | node | 
| Elixir | elixir | 
| Golang | go | 
| Java | java | 
| PHP | php | 
| Ruby | ruby | 
| Python | python | 
| C / C++ | c/cpp | 
Misc.
| Terminal | bashorshell | 
| JSON | json | 
| XML | xml | 
| SQL | sql | 
| GraphQL | graphql | 
| Markdown | markdown | 
| MDX | mdx | 
| YAML | yaml | 
| Git | git | 
Note: If you want syntax highlighting for a snippet in another language, feel free to add your language to the imports here and open a PR.
Multiple code snippets in one block
With PostHog's MultiLanguage component, it's possible to group multiple code snippets together into a single block.
Note: Make sure to include empty lines between all your code snippets, as well as above and below the
MultiLanguagetag
This will render the following codeblock:
Specifying which file a snippet is from
You can specify a filename that a code snippet belongs to using the file parameter, which will be displayed in the top bar of the block.
Note: Make sure not to surround your filename in quotes. Each parameter-value pair is delimited by spaces.
This produces the following codeblock: