back to

How-to: paste code snippets in forum posts


Many questions on the forum refer to pieces of code that don’t seem to work and to identify the problem users usually paste the code here so others can check it and help them.

If you paste your code as plain text (as these lines of text you are reading) there is a high chance to break its format. By breaking its format I mean that Discourse might change some characters and that will lead to an error when executing this piece of code although your code might be correct. The most common case is the quotes problem. In many cases Discourse will confuse “straight” and “curly” quotes leading to errors as mentioned above.

Use the code format button (aka Preformated text button)
To avoid the inconveniences mentioned above, when pasting pieces of code use the code format button on the edit window when creating a new topic or replying to an existing one. This button looks like this </>. This button will ensure that whatever is wrapped within its quotes will be perceived and look like code.

  • Plain text:
    This is a plain text example.

  • Preformated text
    This is a preformated text example created using the code format button.

Happy hacking

pinned globally #2