Using Markdown for Code Snippets

Table of Contents

  1. Inline Code
  2. Code Blocks

To display code directly in your post, use Discourse’s Markdown syntax:

Inline Code

To format a short piece of code inline with your text, just wrap the code with single backticks (`).

For example:

Use the print() function to display output.

inline code example screenshot

Code Blocks

For larger code blocks, use triple backticks (```) before and after the code.

For example:

code blocks example screenshot

Tips: To enable syntax highlighting, specify the language after the opening triple backticks. Discourse supports popular languages like Python, JavaScript, HTML, and more.

For example:

def add(a, b):
    return a + b

syntax highlighting example screenshot