All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.moe.tlaster.ktml.dom.Node.kt Maven / Gradle / Ivy

There is a newer version: 0.0.7
Show newest version
package moe.tlaster.ktml.dom

interface Node {
    val name: String
}

interface Element : Node {
    val attributes: Map
    val children: List
    val parent: Element?
//    val innerHTML: String
//    val outerHTML: String
    val innerText: String
    val namespace: String
}

data class HtmlElement(
    override val name: String,
    override val namespace: String = "",
    override val parent: Element? = null,
) : Element {
    override val attributes = linkedMapOf()
    override val children = arrayListOf()
//    override var innerHTML: String = ""
//    override val outerHTML: String
//        get() = "<$name${attributes.map { "${it.key}=${it.value}" }.joinToString(" ")}>$innerHTML"
    override val innerText: String
        get() = children.joinToString("") {
            when (it) {
                is Text -> it.text
                is Element -> it.innerText
                else -> ""
            }
        }
}

data class Text(
    val text: String,
    override val name: String = "#text",
) : Node {
    override fun toString(): String {
        return text
    }
}

data class Comment(
    val text: String,
    override val name: String = "#comment",
) : Node {
    override fun toString(): String {
        return ""
    }
}

data class Doctype(
    override val name: String,
) : Node {
    override fun toString(): String {
        return ""
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy