Formatting Code Samples in Community

If you need to include code blocks in your posts, formatting them properly makes it easier for all to read.

If you post JSON as straight text, you get something like this:
[
{
“Contacts”: [
“First”,
“Last”,
“Street”,
“City”,
“Zip”
]
}
]

When in edit mode, you see indents, but they don’t carry over to the published topic.

Markdown formatting uses three backticks ``` to enclose code blocks. You can type them before your code snippet and after to get the code formatting.

 [
    {
        "Contacts": [
            "First",
            "Last",
            "Street",
            "City",
            "Zip"
        ]
    }
]

Alternately, you select your code snippet and use the preformatted text option in the toolbar ( </>) to get another type of formatting:

[
    {
        "Contacts": [
            "First",
            "Last",
            "Street",
            "City",
            "Zip"
        ]
    }
]

Either option makes it easier for others to read code snippets.

2 Likes