fix build for documents

This commit is contained in:
Alexander Nozik 2024-09-28 15:56:22 +03:00
parent 3adadd5bd7
commit e2ef4b1c5b
4 changed files with 28 additions and 10 deletions

View File

@ -14,9 +14,7 @@ Curabitur hendrerit hendrerit rutrum. Nullam elementum libero a nisi viverra ali
Paragraph Paragraph
$$ $ \int_a^b {f(x)} = const $
\int_a^b {f(x)} = const
$$
### Section ${section(2)} ### Section ${section(2)}

View File

@ -6,6 +6,7 @@ import io.ktor.server.engine.embeddedServer
import kotlinx.html.ScriptCrossorigin import kotlinx.html.ScriptCrossorigin
import kotlinx.html.link import kotlinx.html.link
import kotlinx.html.script import kotlinx.html.script
import kotlinx.html.unsafe
import space.kscience.snark.html.document.allDocuments import space.kscience.snark.html.document.allDocuments
import space.kscience.snark.ktor.snarkApplication import space.kscience.snark.ktor.snarkApplication
@ -32,6 +33,22 @@ fun Application.renderAllDocuments() = snarkApplication {
crossorigin = ScriptCrossorigin.anonymous crossorigin = ScriptCrossorigin.anonymous
attributes["onload"] = "renderMathInElement(document.body);" 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()
}
}
} }
) )
} }

View File

@ -1,8 +1,11 @@
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.stream.createHTML import kotlinx.html.dom.append
import kotlinx.html.visitTagAndFinalize 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.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
@ -15,20 +18,22 @@ public fun interface HtmlPage {
public fun renderPage() public fun renderPage()
public companion object { public companion object {
public fun createHtmlString( public fun createHtmlString(
pageContext: PageContext, pageContext: PageContext,
dataSet: DataTree<*>?, dataSet: DataTree<*>?,
page: HtmlPage, page: HtmlPage,
): String = createHTML().run { ): String = document {
HTML(kotlinx.html.emptyMap, this, null).visitTagAndFinalize(this) { append.html {
with(PageContextWithData(pageContext, dataSet ?: DataTree.EMPTY)) { with(PageContextWithData(pageContext, dataSet ?: DataTree.EMPTY)) {
with(page) { with(page) {
renderPage() renderPage()
} }
} }
} }
} }.serialize(true)
} }
} }

View File

@ -9,11 +9,9 @@ import org.intellij.markdown.ast.findChildOfType
import org.intellij.markdown.ast.getTextInNode import org.intellij.markdown.ast.getTextInNode
import org.intellij.markdown.flavours.commonmark.CommonMarkFlavourDescriptor import org.intellij.markdown.flavours.commonmark.CommonMarkFlavourDescriptor
import org.intellij.markdown.flavours.gfm.GFMFlavourDescriptor import org.intellij.markdown.flavours.gfm.GFMFlavourDescriptor
import org.intellij.markdown.flavours.space.SFMFlavourDescriptor
import org.intellij.markdown.html.* import org.intellij.markdown.html.*
import org.intellij.markdown.parser.LinkMap import org.intellij.markdown.parser.LinkMap
import org.intellij.markdown.parser.MarkdownParser import org.intellij.markdown.parser.MarkdownParser
import space.kscience.snark.SnarkReader
private class SnarkInlineLinkGeneratingProvider( private class SnarkInlineLinkGeneratingProvider(
baseURI: URI?, baseURI: URI?,