Kotlin
About 309 wordsAbout 1 min
2024-04-22
Overview
The theme provides Kotlin code demonstrations, supporting online execution of Kotlin code.
Important
This feature works by submitting code to a server for compilation and execution, and only a single code file can be submitted at a time.
Therefore, please do not use this feature to execute overly complex code, and avoid making execution requests too frequently.
Configuration
This feature is disabled by default. You can enable it through configuration.
export default defineUserConfig({
theme: plumeTheme({
markdown: {
repl: {
kotlin: true,
},
},
})
})Usage
Use the ::: kotlin-repl container syntax to wrap Kotlin code blocks. The theme will inspect the code block and add an execution button.
Read-Only Code Demo
Kotlin code demos are read-only by default and cannot be edited.
::: kotlin-repl title="Custom Title"
```kotlin
// your kotlin code
```
:::Editable Code Demo
If you need online editing and execution, wrap the code block in the ::: kotlin-repl editable container syntax.
::: kotlin-repl editable title="Custom Title"
```kotlin
// your kotlin code
```
:::Examples
Print Content
Input:
::: kotlin-repl
```kotlin
class Contact(val id: Int, var email: String)
fun main(args: Array<String>) {
val contact = Contact(1, "mary@gmail.com")
println(contact.id)
}
```
:::Output:
kotlin playground
class Contact(val id: Int, var email: String)
fun main(args: Array<String>) {
val contact = Contact(1, "mary@gmail.com")
println(contact.id)
}Computation
kotlin playground
fun mul(a: Int, b: Int): Int {
return a * b
}
fun main(args: Array<String>) {
print(mul(-2, 4))
}Editable Code Demo
Input:
::: kotlin-repl editable
```kotlin
class Contact(val id: Int, var email: String)
fun main(args: Array<String>) {
val contact = Contact(1, "mary@gmail.com")
println(contact.id)
}
```
:::Output:
kotlin playground
class Contact(val id: Int, var email: String)
fun main(args: Array<String>) {
val contact = Contact(1, "mary@gmail.com")
println(contact.id)
}Contributors
Changelog
97a5b-docs: fix typoon38505-docs: update en docs (#708)on4d236-feat(theme)!: add collections support (#704)onb0742-refactor(plugin-md-power): improve md plugins (#562)on0fd6c-refactor(theme): improve types and flat config (#524)on5addb-feat(plugin-md-power): 支持可编辑的代码演示on428b8-docs: update code online repl docon
