KotlinRunCode demo

Automatic initialization

For instance you have following block of Kotlin code:

fun sum(a: Int, b: Int): Int {
  return a + b
}

Just add <script> tag into the page and specify code blocks selector to attach via data-selector HTML attribute.

<script src="https://unpkg.com/kotlin-runcode/dist/runcode.min.js" data-selector=".kotlin-code"></script>

You will get:

fun sum(a: Int, b: Int): Int {
  return a + b
}

Manual initialization

<script src="https://unpkg.com/kotlin-runcode/dist/runcode.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
  runcode('.code-blocks-selector');
});
</script>

//sampleStart
fun sum(a: Int, b: Int): Int {
  return a + b
}
//sampleEnd

fun main(args: Array<String>) {
  printSum(-1, 8)
}