logoalt Hacker News

flossly • today at 11:15 AM • 1 reply • view on HN

I kinda like kotlinx.html in Kotlin; it's an eDSL for writing HTML in actual Kotlin. So I can put break points in my template code. It's a tiny bit slower than string-with-some-interpolation type of template libraries; but it's so little that it's a price I'm willing to pay. Also there's more impact on compile times than with string-with-some-interpolation type of template libraries.

The typesafety you get is what you already have in Kotlin, and there a little extra in that you cannot nest certain HTML-elements in certain other elements (adhering to the HTML spec). You can come up with your own elements and attributes, but the ones that are in the HMTL-spec are usually available in kotlinx.html as well (and thus can be auto-completed).

A large part of this library is generated from the actual HTML spec.

Claude Code seems to have not problem writing it (I barely write templates myself these days).

https://github.com/kotlin/kotlinx.html

https://dzone.com/articles/modern-type-safe-template-engines...


Replies

giancarlostoro • today at 1:04 PM

I wish Kotlin was given more attention by JetBrains than the AI nonsense they keep trying to build into, its clear they are going to lose in the AI space at this rate, but Kotlin has so much more potential and its nearly ten years old at this point? Oh its 15 whoops!