From e2ef4b1c5b0bc2735ea6ee9dfbebeafaf96bea28 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 28 Sep 2024 15:56:22 +0300 Subject: [PATCH] fix build for documents --- examples/document/data/loremIpsum/chapter1.md | 4 +--- examples/document/src/jvmMain/kotlin/main.kt | 17 +++++++++++++++++ .../space/kscience/snark/html/HtmlPage.kt | 15 ++++++++++----- .../space/kscience/snark/html/MarkdownReader.kt | 2 -- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/examples/document/data/loremIpsum/chapter1.md b/examples/document/data/loremIpsum/chapter1.md index c6d41a4..255c692 100644 --- a/examples/document/data/loremIpsum/chapter1.md +++ b/examples/document/data/loremIpsum/chapter1.md @@ -14,9 +14,7 @@ Curabitur hendrerit hendrerit rutrum. Nullam elementum libero a nisi viverra ali Paragraph -$$ - \int_a^b {f(x)} = const -$$ +$ \int_a^b {f(x)} = const $ ### Section ${section(2)} diff --git a/examples/document/src/jvmMain/kotlin/main.kt b/examples/document/src/jvmMain/kotlin/main.kt index 4e0f22a..b6c2bf0 100644 --- a/examples/document/src/jvmMain/kotlin/main.kt +++ b/examples/document/src/jvmMain/kotlin/main.kt @@ -6,6 +6,7 @@ import io.ktor.server.engine.embeddedServer import kotlinx.html.ScriptCrossorigin import kotlinx.html.link import kotlinx.html.script +import kotlinx.html.unsafe import space.kscience.snark.html.document.allDocuments import space.kscience.snark.ktor.snarkApplication @@ -32,6 +33,22 @@ fun Application.renderAllDocuments() = snarkApplication { crossorigin = ScriptCrossorigin.anonymous attributes["onload"] = "renderMathInElement(document.body);" } + script { + unsafe { + +""" + document.addEventListener("DOMContentLoaded", function() { + renderMathInElement(document.body, { + delimiters: [ + {left: '$$', right: '$$', display: true}, + {left: '$', right: '$', display: false}, + ], + throwOnError : false + }); + }); + + """.trimIndent() + } + } } ) } diff --git a/snark-html/src/jvmMain/kotlin/space/kscience/snark/html/HtmlPage.kt b/snark-html/src/jvmMain/kotlin/space/kscience/snark/html/HtmlPage.kt index e192dbb..d1069fb 100644 --- a/snark-html/src/jvmMain/kotlin/space/kscience/snark/html/HtmlPage.kt +++ b/snark-html/src/jvmMain/kotlin/space/kscience/snark/html/HtmlPage.kt @@ -1,8 +1,11 @@ package space.kscience.snark.html +import kotlinx.css.html import kotlinx.html.HTML -import kotlinx.html.stream.createHTML -import kotlinx.html.visitTagAndFinalize +import kotlinx.html.dom.append +import kotlinx.html.dom.document +import kotlinx.html.dom.serialize +import kotlinx.html.html import space.kscience.dataforge.data.DataSink import space.kscience.dataforge.data.DataTree import space.kscience.dataforge.data.wrap @@ -15,20 +18,22 @@ public fun interface HtmlPage { public fun renderPage() public companion object { + public fun createHtmlString( pageContext: PageContext, dataSet: DataTree<*>?, page: HtmlPage, - ): String = createHTML().run { - HTML(kotlinx.html.emptyMap, this, null).visitTagAndFinalize(this) { + ): String = document { + append.html { with(PageContextWithData(pageContext, dataSet ?: DataTree.EMPTY)) { with(page) { renderPage() } } } - } + }.serialize(true) } + } diff --git a/snark-html/src/jvmMain/kotlin/space/kscience/snark/html/MarkdownReader.kt b/snark-html/src/jvmMain/kotlin/space/kscience/snark/html/MarkdownReader.kt index 875837e..d440323 100644 --- a/snark-html/src/jvmMain/kotlin/space/kscience/snark/html/MarkdownReader.kt +++ b/snark-html/src/jvmMain/kotlin/space/kscience/snark/html/MarkdownReader.kt @@ -9,11 +9,9 @@ import org.intellij.markdown.ast.findChildOfType import org.intellij.markdown.ast.getTextInNode import org.intellij.markdown.flavours.commonmark.CommonMarkFlavourDescriptor import org.intellij.markdown.flavours.gfm.GFMFlavourDescriptor -import org.intellij.markdown.flavours.space.SFMFlavourDescriptor import org.intellij.markdown.html.* import org.intellij.markdown.parser.LinkMap import org.intellij.markdown.parser.MarkdownParser -import space.kscience.snark.SnarkReader private class SnarkInlineLinkGeneratingProvider( baseURI: URI?,