HTML tag replacement tool for Kotlin (Java).
Required dependencies:
Example usage:
import kotlinx.html.*
htmlReplace(
html = """
<p>Allo, <q>Mars</q></p>
""".trimIndent(),
cssQuery = ":containsOwn(Mars)" to {
a {
href = "https://www.mars.com"
unsafe {
raw(it.outerHtml())
}
}
}
)
Output:
<p>Allo, <a href="https://mars.com"><q>Mars</q></a></p>
How to use:
- define
cssQuery
using JSoup syntax; - (optional) access original element properties:
it.attributes()
,it.html()
.