All discourse-based forums use Markdown. Please see: https://commonmark.org
There is also an issue to improve this: https://youtrack.jetbrains.com/issue/KT-38551
And running code right inside a forum is a part of Markdown spec?
Ah, now i see what you mean. You don’t want just a
code block
which is created like this:
```language_name_for_highlighting
code block
```
What you want is to have the runable portion. Sorry for the missunderstanding, that’s not standard markdown.
The simplest way would be to share a link to https://play.kotlinlang.org (but i agree that’s not really cool as it takes you to a new website in a new page, bla, bla).
Whoever clicks may run it: Kotlin Playground: Edit, Run, Share Kotlin Code Online.
But what we really want is a runnable piece of code, embeded in the post:
fun main() {
println("HURRRRRR")
}
which is done as follows:
```run-kotlin
fun main() {
println("HURRRRRR")
}
```
Now the question comes to “how did i figure that out”? I looked at the raw markdown of that particular post:
-
Copy the link that you wanna check out:
https://discuss.kotlinlang.org/t/kotlin-needs-try-with-resources/214/54
.
-
Call the
raw
endpoint for that post: https://discuss.kotlinlang.org/raw/214/54?u=thebestpessimist
As for the question of “how did they do it”, i guess it’s a discourse plugin created by jetbrains which handles the code blocks with highlighting run-kotlin
, but idk for sure.
Here’s the blog post about Embedding Kotlin Playground in the forum, your own website or WordPress, and more. In the future, I’ll include this link anytime I post a runnable example so people can see how to do it themselves.
It’s a bit off-topic so maybe we should discuss further in a new site-feedback thread.
EDIT: Whoa! Topics can be split? That’s awesome!
Yeah, it’s a feature restricted to the kotlin team. While we have their attention, is there any news about the issue I linked above. Any kind of ETA when we can expect something to help new users of this site whit code formatting / runable code blocks? @ilya.gorbunov
I believe adding that button to the composer can be achieved quite easily with a theme component. All it has to do is insert
```run-kotlin
// type your code here
```
in the composer.
Would it be possible that JetBrains creates a Discourse plugin (or more likely a theme component) with run-kotlin
functionality?
I would like to use this in my own discourse instance.
I have tried adding the iframe from kotlin playground: iframe src="https://pl.kotl.in/xrwqnYnxC?theme=darcula"></iframe>
but that looks very bad in my discourse (look at how small it is compared to normal topic width):