Kotlin / kotlin-playground-wp-plugin

WordPress plugin which allows to embed interactive Kotlin playground to any post via [kotlin] shortcode
Apache License 2.0
36 stars 10 forks source link

Indentation lost #9

Open kirill-grouchnikov opened 6 years ago

kirill-grouchnikov commented 6 years ago

Switching between "visual" and "text" tabs in WordPress editor loses all indentation in the [kotlin] block. It used to be that this WP plugin did the right indentation at render time (along with code highlighting), but that seems to be gone in the last week or so.

Is that intentional? Can this plugin do the right indentation? See code snippets at https://www.pushing-pixels.org/2018/08/07/replacing-swingworker-with-kotlin-coroutines.html for how it looks like without indentation.

AlexanderPrendota commented 6 years ago

Try to set auto-indent attribute to true value. It might helps.

kirill-grouchnikov commented 6 years ago

Doesn't seem to be working.

AlexanderPrendota commented 6 years ago

It works on Kotlin Blog. Hm. Try to write only in text mode :)

kirill-grouchnikov commented 6 years ago

Well, I can add the indentation back if I only stay in text mode, but that's far from optimal as the first switch to visual will lose the indentation inside all the [kotlin] blocks.

kirill-grouchnikov commented 6 years ago

I'm not seeing auto-indent="false" on the <pre> blocks generated from [kotlin]. Is that something that is only inserted for false value of that flag, and skipped for true?

AlexanderPrendota commented 6 years ago

Yes. That's why I recommend to use only text mode.

auto-indent it's kotlin playground attribute. for example:

[kotlin runnable=false auto-indent=true]
suspend fun <T> CompletableFuture<T>.await(): T = suspendCoroutine { cont ->
    whenComplete { value, exception ->
        when {
            exception != null -> cont.resumeWithException(exception)
            else -> cont.resume(value)
        }
    }
}
[/kotlin]
kirill-grouchnikov commented 6 years ago

Can't say I agree with this being closed as WAI. What's the point of having this attribute if the plugin expects the code to already be pre-indented?

AlexanderPrendota commented 6 years ago

Codemirror editor has the context-sensitive indentation. This attribute needs to format each of code line after playground's inited.

bodiam commented 4 years ago

I've tried this plugin too for https://www.kotlintips.com, but unfortunately, the formatting is lost, no matter if I try auto-indent=true or not.