How to share your code

To share your code with others, you can simply link to your repl or paste and format the code into your post!

Linking to a repl

The easiest way to share your code is by linking to your repl. You can find the link by clicking on your repl title, clicking on :eye: Cover page, and clicking the :link: button to copy the URL.
NOTE: only share repl join links or use the invite button with people you trust!

Sharing short code samples

Share a snippet of your code by wrapping it in backticks: `. This is especially useful when sharing the name of variables or short lines of code.

Example:
someVarName

Raw
`someVarName`

Sharing blocks of code

There are 2 ways to do share longer blocks of code:

The first way (preferred) is with ```. You can even add language abbreviations like js for Javascript and py for Python to enable syntax highlighting.

Example:

console.log("Hello World!")
Raw
```js
console.log("Hello World!")
```

The other way to format large blocks of code are indent it by 4 spaces at the minimum. For example:

console.log("Hello World")
Raw
    console.log("Hello World")
8 Likes

Iā€™m wondering about code syntax highlightingā€¦ According to the docs on code blocks (which is referenced in this post), there should be syntax highlighting for languages, but there isnā€™tā€¦ there is some syntax highlighting if no language is specified, but if the language is specified, there is no highlighting at allā€¦

1 Like

Code highlighting has always been weird on discourse and I never fully figured it out.

There is a setting to enable and disable code hightlighting for different languages. @IanAtCSTeach can you share a screenshot of that and update the guide accordingly?

Discourse automatically detects the language and highlights it as such.

Sometimes there is sometimes there is not.

console.log("test")

When I make an edit to improve formatting I may just do the wrong abbreviation after the first backticks making it so there is no highlighting. If you notice I did that going on feel free to send me a message and I will fix it.

3 Likes

Hmmā€¦ actually it seems that code formatting is working fine, itā€™s just that despite the fact that the docs state js should work for syntax highlighting, it doesnā€™tā€¦

js:

console.log(123);

javascript:

console.log(123);

Same with Python actually:
py:

print(123)

python:

print(123)

It seems the shortcut names which are supposed to work donā€™tā€¦
Actually, not even the shortcut names, it just seems only certain names work, like for C++ only c++ seems to work, not cpp or cplusplus as stated in the docs, and for C# only csharp works, not csā€¦

1 Like

hmmā€¦ Let me look if there is some stuff on meta about code hightlighting.

1 Like

@MattDESTROYER I found this meta post and these docs on what supported languages areĀ¹ and what the aliases are. For example python, py and gyp should all work for Python. And javascript, js and jsx should all work for Javascript. I can ask over on meta if you want me to.

Ā¹Not all are supported due to the setting.

3 Likes

Itā€™s not necessary to click Cover Page, is it?

1 Like

No, but if you just copied while focusing on a tab with a file then it would link directly to that file instead of the usual cover page.

Also the post originally said ā€œspotlight pageā€ so I just changed it to ā€œcover pageā€

Yeah, but you could view main file or even just get rid of after the # in the URLā€¦

200 replies* with this! :partying_face:

*total posts

4 Likes

Is it right that everyone has read access to my code if I donā€™t have Premium and disable it?

1 Like

If by this you mean that you are on the free plan, then yes, this is correct.

3 Likes

You canā€™t make your Repls private without Core.

2 Likes