Using Code Blocks

Jake Peters Updated by Jake Peters

HelpDocs comes loaded with automatic code blocks with syntax highlighting. There's nothing to set up or configure—it'll automatically highlight your code based on the language you insert.

Code Blocks look different depending on the template you're using

Adding Code Blocks

  1. In the article editor click Blocks
  2. Select Code Block
  3. Paste the code into the code block
  4. Click Automatic to select a language or leave it for us to decide
  5. Hit Save Changes

Now your code will look beautiful and readable to all those developers out there 😍 Here's an example:

function randomString() {
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
length = 32,
result = '';
for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
return result;
}
Code Blocks are only highlighted when your articles are viewed not when they're written. Don't worry when they look plain and boring in the article editor!

Manually Override the Syntax Highlighting Language

Code Blocks are usually pretty smart when it comes to detecting the language, but sometimes it does get it wrong. Luckily, there's a way to manually override the syntax highlighting language.

  1. Head to the Code Block
  2. In the upper right corner you'll see a dropdown
  3. Select the desired language (e.g. Javascript)
  4. Press Save

What did you think of this doc?

Embedding Audio Files

Getting Started with Content Blocks

Get in touch