[How to] Post correctly formatted and colorized code on the forum?

Continuing the discussion from Ruby backtick returns nothing!:

Triple backtick delimiter lines.

  • image

Backquote character key on US keyboard.

If it is error message text (or some other plain text that contains <, >, #, or other characters that can confuse Discourse markdown,) then specify “text” as a lexing language:

paste error message here

If it is Ruby, then:

# code here

If it is Javascript, then:

/* js code here */

If it is HTML, then:

<!-- html here -->

If it is C, then:

// C code here

… etc. (Discourse code lexer recognizes the major programming languages.)

# Test
module Eneroth3::TestSyntaxHighlight
  def self.method_name
    puts "String"
    yield false
    return true

I had no idea this forum supported syntax highlighting :open_mouth: .


Yep! Discourse processes your post’s text through a Markdown language formatter, and implements this feature of Markdown. The Markdown formatter is also why posts of error messages and code can get so screwed up if people don’t use the triple backtick syntax!


Welcome Dylan … the wikipedia page (linked below) explains what markdown is in detail.

But it is basically a simple, human-readable text code that can be used to nicely format posting on the web or documents.

The forum system should have sent you a message explaining the basics of using markdown on the forum.
(Click your avatar menu at the top right, see if the welcome message from the system is there.)

1 Like