In this story
Where: Stories → All stories → The story editor
Open this page: admin.<your-site>/articles (replace <your-site> with your site address). Then open the one you want.
Steps
- Open the story in the editor.
- Put the cursor where the code should go.
- Open the Insert menu and choose More blocks, then Code block.
- Paste or type the code.
- Choose the language from the language list so the colours are right. Choose Plain text if you do not want colours.
- Publish the story.
For the full list of block options, see Code and maths.
Good to know
- Languages you can pick: Plain text, Bash, C, C++, C#, CSS, Dart, Diff, Dockerfile, Go, GraphQL, HTML, INI, Java, JavaScript, JSON, Kotlin, Less, Lua, Makefile, Markdown, Objective-C, Perl, PHP, PowerShell, Python, R, Ruby, Rust, SCSS, Shell session, SQL, Swift, TOML, TypeScript, XML and YAML.
- Copy code. On the website, each code block has a Copy code button. It shows up when the reader's browser allows copying.
- Inline code. For one word or a short command inside a sentence, use the Inline code mark in the toolbar instead.
- You can put a code block inside a Callout, a Toggle or a Column.
- Don't paste secrets. Never put passwords, keys or tokens in a story. Readers can see everything you publish.
Questions
Frequently asked questions
Can readers run the code?
No. The block only shows and copies code.
Can I keep the code out of search snippets?
Yes. Blocks have a "no snippet" choice in the block actions. See Story SEO.