kotlin-playground-wp-plugin icon indicating copy to clipboard operation
kotlin-playground-wp-plugin copied to clipboard

Indentation lost

Open kirill-grouchnikov opened this issue 6 years ago • 9 comments

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.

kirill-grouchnikov avatar Sep 16 '18 20:09 kirill-grouchnikov

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

AlexanderPrendota avatar Sep 17 '18 06:09 AlexanderPrendota

Doesn't seem to be working.

kirill-grouchnikov avatar Sep 17 '18 12:09 kirill-grouchnikov

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

AlexanderPrendota avatar Sep 17 '18 13:09 AlexanderPrendota

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 avatar Sep 17 '18 13:09 kirill-grouchnikov

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?

kirill-grouchnikov avatar Sep 17 '18 13:09 kirill-grouchnikov

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]

AlexanderPrendota avatar Sep 17 '18 13:09 AlexanderPrendota

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?

kirill-grouchnikov avatar Sep 17 '18 13:09 kirill-grouchnikov

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

AlexanderPrendota avatar Sep 17 '18 13:09 AlexanderPrendota

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.

bodiam avatar Jan 12 '20 04:01 bodiam