cs-icon.svg

Code Blocks

The JSON RTE in Contentstack offers a powerful way to manage and display rich content, including formatted code blocks. This feature is ideal for developers creating technical documentation, blogs, or any content requiring clear, structured code blocks.

To add a code block within your JSON RTE, log in to your Contentstack account and perform the steps given below:

  1. Navigate to the desired stack, then click the Entries icon in the left navigation panel.
  2. Create a new entry or open an existing one containing a JSON RTE field.
  3. In the JSON RTE field, click the Format icon in the toolbar.
  4. From the dropdown menu, select Code snippet.

Apply Language Formatting to Code Blocks

Contentstack provides built-in syntax highlighting for over 60 programming languages, including JavaScript, HTML, Python, and more. Follow these steps to apply language-specific formatting:

  1. Click the inserted code block in the JSON RTE.
  2. Select a programming language from the dropdown menu.
  3. To move to the next line within the code block, press Enter.
  4. To exit the code block, press Shift + Enter.

Best Practices for Code Blocks

Ensure your code blocks are readable and functional by following these tips:

  • Use Proper Indentation: Well-indented code improves readability.
  • Limit Code Length: For long blocks, split across multiple blocks or add comments for clarity.
  • Choose the Right Language: Use the appropriate language selector for accurate syntax highlighting.
  • Test Code Blocks: Always test the code to ensure it works as intended before adding it to your content.

Using code blocks in the JSON RTE allows developers to effectively manage technical content within Contentstack. Proper formatting ensures code is clear and easy to read, while language-specific syntax highlighting boosts readability and user engagement. Follow the best practices to get the most out of code blocks in your documentation and blogs.

Was this article helpful?
^