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, selecting “Spotlight” and then copying the spotlight URL.
NOTE: only share repl join links or use the invite button with people you trust!

Kapture 2022-06-23 at 16.51.07

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")
3 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. @IanAtReplit 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.

2 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