varabyte / kobweb

A modern framework for full stack web apps in Kotlin, built upon Compose HTML
https://kobweb.varabyte.com
Apache License 2.0
1.52k stars 67 forks source link

Add builder support for the markdown handlers #287

Open bitspittle opened 1 year ago

bitspittle commented 1 year ago

Right now, markdown handlers work by returning strings.

This works in easy cases but gets ugly in complex situations, where you have to manage indents and newlines yourself. Look at the html handler for example!

Instead, it might be nice to have a builder concept which you just add nodes to and, when finished, just call elementBuilder.toString()

So html can go from

sb.appendLine("$indent$elementName {")
for (child in children) { sb.appendLine($indent + 1, render(child)) }
sb.appendLine("$indent}"

return sb.toString()

to

elementBuilder.open(elementName)
for (child in children) { elementBuilder.add(child) }
elementBuilder.close()

return elementBuilder.toString()
bitspittle commented 1 year ago

Doesn't strictly have to be done before 1.0 but it would be a nice to have, to lock down markdown in case more and more people start using it / copying my code.