commonMain.moe.tlaster.ktml.dom.Node.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ktml-jvm Show documentation
Show all versions of ktml-jvm Show documentation
Html parser for Kotlin Multiplatform
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$name>"
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