Kotlin / kotlinx.html

Kotlin DSL for HTML
Apache License 2.0
1.63k stars 133 forks source link

Have the `h2 { }` syntax support tag params #231

Open owengray-google opened 1 year ago

owengray-google commented 1 year ago

The FlowOrHeadingContent.h1 method can accept class as an argument, but not other parameters.

In general, we want to pass through all or most parameters unchanged.
The ideal syntax that maintains back-compatability would likely be an overload

inline fun FlowOrHeadingContent.h1(classes : String? = null, crossinline block : H1.() -> Unit = {}) : Unit = H1(attributesMapOf("class", classes), consumer).visit(block)
/** New overload: */
inline fun FlowOrHeadingContent.h1(params : Map<String, String> = null, crossinline block : H1.() -> Unit = {}) : Unit = H1(params, consumer).visit(block)

We can and have just manually inlined the current h1, but I think supporting more params in what seems to be the recommended API would be more correct.

This does not just apply to headings, but to many of the functions like this.
Specifically, we have needed to do this to allow setting id attributes for headings, which is used for tables of contents and to allow the headings to work as link anchors.