Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

How to type code in the forum

Hi guys,

I think I've asked this about three times or so already, and I keep forgetting: how do I add code to the forum and place it in a box? I've seen that it's maybe < code> </ code> or putting " ``` " before the text, but those don't work for me.

Is there a way to have a feature where you can highlight the code in the textbox and hit a "Code Tag" button? I'm perfectly fine with writing the code myself, but I just keep forgetting the actual command to do so.

Thanks.

<strong>test</strong

<Body> <p>hello world</p> </body>

`<Body> <p>hello world</p> </body>'

<body>
  <p>hello world</p>
</body>
<body>
  <p>hello world</p>
</body>

<p>hello</p>

telnet httpbin.org 80
GET / HTTP/1.1
Host: httpbin.org

test

108 Answers

Paul Dietrich - There are 3.5 different ways to format code on the forum, here's a primer for you.

Option 1) Inline code like this code use the ` key to enclose your string of code

Option 2) Indent each line of code by one tab or 4 spaces

<Body>
  <p>hello world</p>
</body>

Option 3) Code fences, you need a blank line before your code fence

Enter this:

```
<body>
  <p>hello world</p>
</body>
```

It will give you this:

<body>
  <p>hello world</p>
</body>

Option 3b) Syntax highlighting, use the code fences and specify a language:

Enter this:

```ruby
def my_method(syntax)
  syntax.is_highlighted?
end
```

It will give you this:

def my_method(syntax)
  syntax.is_highlighted?
end
Zac Gordon
Zac Gordon
Treehouse Guest Teacher

Test 1:

<article>
  <h1><?php the_title(); ?></h1>
  <?php the_excerpt(); ?>
  <br>
</article>

Test 2:

<article>
  <h1><?php the_title(); ?></h1>
  <?php the_excerpt(); ?>
  <br>
</article>

Test code block:

var myVar;

undefined = true;
Patrick Koch
Patrick Koch
40,498 Points

Test <html> <title>Code Block Test</title> <body> </body> </html>

Patrick Koch
Patrick Koch
40,498 Points
<body>
  <p>hello world</p>
</body>

Test

CELLS = []
for x in range(0,10):
    for y in range(0,10):
        CELLS.append((x,y))
<Body>
  <p>hello world</p>
</body>

,,, Test ,,,

as in :

code?

4 spaces should the trick, although I find I have to go back and edit some lines of code, but thats probably my bad anyway!

or that ^ James Barnett ;D

Paul Dietrich - Your issue with '```' is probably you aren't putting the necessary, 1 line of white space between your text and the start of your code block.

This is how I imagine Prof Stephen Hawkins to type by default :/

Thanks much!

test
    <html>
        <title>Code Block Test</title>
        <body>
        </body>
    </html>
<html>
    <head>
           <title>Something</title>
    </head>
    <body>
        <p>Something Else</p>
    </body>
   </html>
<code>

`<html> <head> <title>Something</title> </head> <body> <p>Something Else</p> </body> </html>'

Here are a few other Github-flavored markdown tricks:

You can use numbers for reference-style link definitions

You can even create reference-style links with parentheses in them


Strike through with ~~done~~

done


H1

Headers with equal signs underneath.

Alt-H1

this is only a test

<body>
  <p>hello world</p>
</body>

TEST

<html>

<!-- A < a -->

</html>

test

def my_method(syntax)

  syntax.is_highlighted?

end
<html>
  <title>
  </title>
</html>

Test

<html>
    <head attr="someValue">
    </head>
    <body>
        Some text
    </body>
</html>
test

test

<html>
    <head>
    </head>
    <body>
        <p>HELLO</p>
    </body>
</html>
<body>
    <p>Hello World</p>
</body>
<p> 
HELLOOO
</p>

Testing...

<html>
    <head>
        <title>The Grid</title>
    </head>
    <body>
        <p>
            The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? Motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day... I got in.
        </p>
    </body>
</html>
<body>
  <p>hi there, this is a test</p>
</body>
<body>
  <p>hi there, this is a test</p>
</body>

test

<body>
  <p>hi there, this is a test</p>
</body>
<body> 
       <p>Hello Test!</p>
</body>
<!DOCTYPE html>
<head>
    <title>This is only a test</title>
</head>
<body>
    <p> This is a paragraph </p>
</body>

Test 2

<?php 
    $args = array(
        'post_type' => 'work'
    );

    $the_query = new WP_Query( $args );
?>

This is a test

<body>
    <h1>This is a level 1 headline</h1>
</body>

Testing!

<p>Hello hello </p>

=-

<body>
   <p>test</p>
</body>
<body>

<p> hello world </p>

</body>

<body>

<p> hello world </p>

</body

this is a test:

<body> <h1>This is A test</h1>

Test

<h1>Hello</h1>
  <p>hello world test</p>

Test test test

<h1>I'm So Cool</h1>
    <p>Treehouse rules!</p>

TEST

SELECT movies.title, IFNULL(AVG(score),0) AS average 
FROM reviews RIGHT OUTER JOIN movies 
ON movies.id = reviews.movie_id 
GROUP BY movie_id HAVING average < 2;
<h1>Test</h1>

This is a test

@property(strong,nonatomic) NSMutableArray *arrayTest;

Awesome lol

Testing...

    #copyright {
      border-top: 8px solid;
      border-color: #2A0400;
}

One more...

    #copyright {
      border-top: 8px solid;
      border-color: #2A0400;
}

Doesn't the simple Markdown code block notation of a tab (or 4 spaces) work?

James Gill - As I noted in option 2, yes it does a tab or 4 spaces works the same way as using a single backtick. If you want to do multiple lines you need a code fence or a set of 3 backticks as I noted in option 3.

Any questions?

trying to put a block of code here...

<body>
<p>A paragraph</p>
</body>

round two <body> <p>A paragraph</p> <body>

used 4 spaces... we'll see!

????

<body>
<p>A paragraph.</p>
<body>

ahhhh... that works.

<html>
    <head>
        <title>Testing</title>
    </head>
    <body>
        <p>Here's another test.</p>
    </body>
</html>
<html>
<head>
<title>Test w/o Indentation</title>
</head>
<body>
<p>Does it look right?</p>
</body>
</html>

testing <code>code</code>

test

''' <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Smells Like Bakin' Cupcake Company</title> <link rel="stylesheet" href="css/normalize.css" type="text/css" media="screen"> <link rel="stylesheet" href="css/grid.css" type="text/css" media="screen"> </head> '''

'''html

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Smells Like Bakin' Cupcake Company</title> <link rel="stylesheet" href="css/normalize.css" type="text/css" media="screen"> <link rel="stylesheet" href="css/grid.css" type="text/css" media="screen"> </head> '''

John Schnettgoecke you need to use a backtick `. You're using a single quote.

<body>
  <p>Test</p>
</body>

Just a test!

@media screen and (max-width: 300px) {
    #myItem li:nth-child(2n+1) {
    clear: left;
  }
}

even more testing

void addTwo(){
   // float alpha = 1.11;
    float beta = 2.22;
    //float result = alpha + beta;
    printf("result is %f\n", beta);
}

test

float addTwo (float a, float b);

float addTwo (float a, float b){
return a + b;
}
         test 
       <li>
        <a href="img/summer.JPG">
            <img src="img/summer.JPG" alt="">
            <p>Summer Album</p>
        </a>
    </li> '

Just a test!

<body>
  <p>hello world</p>
</body>

Test

<html>
<body>
  <div>
    <p>Hello!</p>
  </div>
</body>
</html>

Testing again test test

'''html <body> <p>hello world</p> </body> ''''

This is a Venezuelan Test!

            <p>This is code!</p>

ok, got it!

    h1 {
        color:blue;
    }
  <p>Testing World</p>

<Body> <p>hello world</p> </body>

def my_method(syntax)
  syntax.is_highlighted?
end

test

def my_method(syntax)
  syntax.is_highlighted?
end

test

def my_method(syntax)
  syntax.is_highlighted?
end

<p>hello</p>

def my_method(syntax)
  syntax.is_highlighted?
end

This is an example link ```ruby def my_method(syntax) syntax.is_highlighted? end

This is an example link

def my_method(syntax)
  syntax.is_highlighted?
end
<!DOCTYPE html>
<html>
</html>
<p> test code</p>
<p> this is just a test </p>

<p>Test</p>

Test

<body>
  <p>hello world</p>
</body>

This is a test.

shopping_list = []

def show_help():
  print("What should we pick up at the store?")
  print("Enter DONE to stop. Enter HELP for this help. Enter SHOW to show list")

def add_to_list(item):
  shopping_list.append(item)
  print("Added! List has {} items.".format(len(shopping_list)))


def show_list():
  print("Here's you list:")
  for item in shopping_list:
    print(item)

hope it works.

<button type="button">Test</button>

Testing.

<body>
    <p>Test</p>
</body>

' <body> <p>Test</p> </body> '

var userNumber = prompt("write down one number");
parseInt(userNumber);
var sve = Math.random()*userNumber;
Math.floor(sve);
alert(Math.random()*userNumber);

'test <li> <a href="img/summer.JPG"> <img src="img/summer.JPG" alt=""> <p>Summer Album</p> </a> <'

String firstName = "Gordon";

// string lastName = "Sumner";

// console.printf("Hello %s", firstName)

// band = console.readLine("Which band?  ");

^ was just practicing

<p>Test</p>
<?php
require "vendor/autoload.php";

  date_default_timezone_set("America/Cancun");

  use Monolog\Logger;
  use Monolog\Handler\StreamHandler;

  $log = new Logger('name');
  $log->pushHandler(new StreamHandler('app.txt', Logger::WARNING));

  $log->addWarning('Warning!.');

  echo "Hello World!";
<p></p>
var a = "hello";

testing`

<test> hello </test>

testing 1, 2, 3
public class Game {
  private String mAnswer;
  /// final means cannot be changed alcaps MAS_MISSES means constant\\\\\
  public static final int MAX_MISSES =7;
  private String mMisses;
  private String mHits;
  //constructor\\\
  public Game(String answer)  {
    mAnswer = answer;
    mHits = "";
    mMisses = "";
    }
  // private method\\\
  private char validateGuess (char letter) {
  if (! Character.isLetter(letter)) {
    throw new IllegalArgumentException("A letter is required");
    }
    letter = Character.toLowerCase(letter);
    if (mMisses.indexOf(letter) >= 0 || mHits.indexOf(letter) >=0) {
      throw new IllegalArgumentException(letter + "has already been guessed");
     }
        return letter;    
  }              
  ///method\\\
  public boolean applyGuess(char letter) {
    letter = validateLetter(letter);
    boolean isHit = mAnswer.indexOf(letter) >=0;
        if (isHit) {
        mHits += letter; 
   } else {
     mMisses += letter;
   }
   return isHit;
  }
public String getCurrentProgress() {
 String progress ="";
  for (char letter: mAnswer.toCharArray()) {
    char display = '-';
    if (mHits.indexOf(letter) >= 0) {
      display = letter;
  }
    progress += display;
    }
    return progress;
  }

  public int getRemainingTries() {
  return MAX_MISSES - mMisses.length(); 
  }

        }

'' test ''

'' test ''

´´´´´gdfgdfg´´´´

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Objects</title>
  <link rel="stylesheet" href="css/styles.css">
</head>
<body>
<h1>Objects</h1>
<div id="output">

</div>
<script src="js/object.js"></script>
</body>
</html>

Test

<body>
<p>hello world</p>
</body>

test '''

HI

'''

test

angular.js
angular.module("todoListApp",[])

.controller("mainCtrl", function($scope, dataService){

    $scope.addTerm = function(){ };

    dataService.getCloudTerms(
        function(response) {            
            console.log(response.data);
            $scope.cloudTerms = response.data;
            console.log($scope.cloudTerms);
        }
    );

})

.service("dataService", function($http){

    this.getCloudTerms = function(callback){
        $http.get('data/cloudTerms.json')
        .then(callback);
    }

})
TEST

'<p>This is only a test</p>'

I think they really need to include the Markdown Cheatsheet link into the dialogue box when you are trying to start a thread from a video's question section. That would be a (seemingly) easy, huge improvement to the site's functionality.

'''python

test = this_is_a

'''

test

do
{
     System.out.println("Please enter your name: ");
     name = ScannerObject.nextln();

     if(!(name.matches["a-zA-Z+"]))
      {
      System.out.println("Sorry, the name can only consist of alphabetical characters... please try again");
      }
}while(!(name.matches["a-zA-Z+"]))// this while loop 

Hi there this is just another html test:

<body>
<p>Hello world I am a paragraph just like those Lorem ipsums</p>
<ul>
 <li>tomatoes</li>
 <li>oranges</li>
</ul>
</body>

'''java

this is test '''java

' ikkk '

... <body> <p>testing<p> ...

... <body> <p>Hello world I am a paragraph just like those Lorem ipsums</p> <ul> <li>tomatoes</li> <li>oranges</li> </ul> </body> ...

<p>This is code!<p>

just a test ...

<body>
<p>"Hello"</p>
</body>

Just for practice.

<!DOCTYPE html> 
<html>
  <head>
    <title>The Moon</title>
  </head>
  <body>
  <figure>
    <img src="img/moon.jpg" alt="Hello snitch">
    <figcaption>Hello snitch</figcaption>
  </figure>
  </body>
</html>