Skip to content

Template element has wrong parent content type #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
morki opened this issue Mar 6, 2025 · 1 comment
Open

Template element has wrong parent content type #293

morki opened this issue Mar 6, 2025 · 1 comment

Comments

@morki
Copy link

morki commented Mar 6, 2025

According to MDN, permitted parents of <template> elements are:

Any element that accepts metadata content, phrasing content, or script-supporting elements. Also allowed as a child of a element that does not have a span attribute.

But currently template {} function cannot be used inside div {} etc.

@Strydom
Copy link

Strydom commented Mar 9, 2025

I just added my own <template> tag, because for some reason i can't find it in 0.12.0 even though it's supposed to be included 🤷‍♂

@Suppress("unused")
open class TEMPLATE(initialAttributes: Map<String, String>, override val consumer: TagConsumer<*>) :
    HTMLTag(
        "template",
        consumer,
        initialAttributes,
        null,
        false,
        false
    ), HtmlBlockTag {}

@HtmlTagMarker
@OptIn(ExperimentalContracts::class)
inline fun FlowContent.template(classes: String? = null, crossinline block: TEMPLATE.() -> Unit = {}): Unit {
    contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
    TEMPLATE(attributesMapOf("class", classes), consumer).visit(block)
}

@HtmlTagMarker
@OptIn(ExperimentalContracts::class)
public inline fun <T, C : TagConsumer<T>> C.template(
    classes: String? = null, crossinline
    block: TEMPLATE.() -> Unit = {}
): T {
    contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
    return TEMPLATE(attributesMapOf("class", classes), this)
        .visitAndFinalize(this, block)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants