Revert to use string builder instead of document builder

This commit is contained in:
Alexander Nozik 2024-10-05 17:47:16 +03:00
parent 52da9fe52e
commit 0e445d4bbb

View File

@ -1,11 +1,8 @@
package space.kscience.snark.html package space.kscience.snark.html
import kotlinx.css.html
import kotlinx.html.HTML import kotlinx.html.HTML
import kotlinx.html.dom.append
import kotlinx.html.dom.document
import kotlinx.html.dom.serialize
import kotlinx.html.html import kotlinx.html.html
import kotlinx.html.stream.createHTML
import space.kscience.dataforge.data.DataSink import space.kscience.dataforge.data.DataSink
import space.kscience.dataforge.data.DataTree import space.kscience.dataforge.data.DataTree
import space.kscience.dataforge.data.wrap import space.kscience.dataforge.data.wrap
@ -19,19 +16,21 @@ public fun interface HtmlPage {
public companion object { public companion object {
private const val HTML_HEADER = "<!DOCTYPE html>\n"
public fun createHtmlString( public fun createHtmlString(
pageContext: PageContext, pageContext: PageContext,
dataSet: DataTree<*>?, dataSet: DataTree<*>?,
page: HtmlPage, page: HtmlPage,
): String = document { ): String = HTML_HEADER + createHTML(true).run {
append.html { html {
with(PageContextWithData(pageContext, dataSet ?: DataTree.EMPTY)) { with(PageContextWithData(pageContext, dataSet ?: DataTree.EMPTY)) {
with(page) { with(page) {
renderPage() renderPage()
} }
} }
} }
}.serialize(true) }
} }
} }