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@1/dist/runcode.min.js" data-selector=".kotlin-code"></script>
For instance following block of Kotlin code:
fun sum(a: Int, b: Int): Int {
return a + b
}
Turns into:
fun sum(a: Int, b: Int): Int {
return a + b
}
If you want to init KotlinRunCode manually - omit data-selector
attribute and call it when it's needed:
<script src="https://unpkg.com/kotlin-runcode@1/dist/runcode.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
KotlinRunCode.default('.code-blocks-selector');
});
</script>
//sampleStart
fun sum(a: Int, b: Int): Int {
return a + b
}
//sampleEnd
fun main(args: Array<String>) {
printSum(-1, 8)
}