The how-to wiki

Formatting with Markdown, part 2 - Code

The markdown for code can also be used for any pre-formatted text, including all your finest ASCII art.

Inline Code

Type this (those are back ticks, not single quotes):

Sample text `some code` more text.

To get this:

Sample text some code more text.

:arrow_up: Back to the top


Code Blocks

Triple ticks can be used to start and end a block of code.

Type this:

```
for each pseudo-code {
    do function;
}
```

To get this:

for each pseudo-code {
    do function;
}

:arrow_up: Back to the top


Code Highlighters

Many languages will be auto-detected. You can also specify a particular one to override the default.

Typing this highlights the PHP, but not the HTML:

```php
<div>
    <h3>A Title</h3>
    <?php
        if ( $suck == TRUE  ) {
            echo "you suck";
        } else {
            echo "no suck";
        }
    ?>
</div>
```

Like this:

<div>
    <h3>A Title</h3>
    <?php
        if ( $suck == TRUE  ) {
            echo "you suck";
        } else {
            echo "no suck";
        }
    ?>
</div>

:arrow_up: Back to the top

1 Like