2024-09-28 11:48:25 +03:00
|
|
|
package center.sciprog.snark.documents
|
|
|
|
|
2024-04-16 17:46:00 +03:00
|
|
|
import io.ktor.server.application.Application
|
2024-10-12 11:51:11 +03:00
|
|
|
import io.ktor.server.application.call
|
2024-04-16 17:46:00 +03:00
|
|
|
import io.ktor.server.cio.CIO
|
|
|
|
import io.ktor.server.engine.embeddedServer
|
2024-10-12 11:51:11 +03:00
|
|
|
import io.ktor.server.response.respondRedirect
|
|
|
|
import io.ktor.server.routing.get
|
|
|
|
import io.ktor.server.routing.routing
|
2024-04-30 19:00:37 +03:00
|
|
|
import kotlinx.html.ScriptCrossorigin
|
|
|
|
import kotlinx.html.link
|
|
|
|
import kotlinx.html.script
|
2024-09-28 15:56:22 +03:00
|
|
|
import kotlinx.html.unsafe
|
2024-04-30 19:00:37 +03:00
|
|
|
import space.kscience.snark.html.document.allDocuments
|
2024-09-28 11:48:25 +03:00
|
|
|
import space.kscience.snark.ktor.snarkApplication
|
2024-04-16 17:46:00 +03:00
|
|
|
|
|
|
|
@Suppress("unused")
|
2024-04-30 19:00:37 +03:00
|
|
|
fun Application.renderAllDocuments() = snarkApplication {
|
|
|
|
allDocuments(
|
|
|
|
headers = {
|
2024-10-12 11:51:11 +03:00
|
|
|
//add katex headers
|
2024-04-30 19:00:37 +03:00
|
|
|
link {
|
|
|
|
rel = "stylesheet"
|
|
|
|
href = "https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/katex.min.css"
|
|
|
|
attributes["integrity"] = "sha384-wcIxkf4k558AjM3Yz3BBFQUbk/zgIYC2R0QpeeYb+TwlBVMrlgLqwRjRtGZiK7ww"
|
|
|
|
attributes["crossorigin"] = "anonymous"
|
|
|
|
}
|
|
|
|
script {
|
|
|
|
defer = true
|
|
|
|
src = "https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/katex.min.js"
|
|
|
|
integrity = "sha384-hIoBPJpTUs74ddyc4bFZSM1TVlQDA60VBbJS0oA934VSz82sBx1X7kSx2ATBDIyd"
|
|
|
|
crossorigin = ScriptCrossorigin.anonymous
|
|
|
|
}
|
|
|
|
script {
|
|
|
|
defer = true
|
|
|
|
src = "https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/contrib/auto-render.min.js"
|
|
|
|
integrity = "sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk"
|
|
|
|
crossorigin = ScriptCrossorigin.anonymous
|
|
|
|
attributes["onload"] = "renderMathInElement(document.body);"
|
|
|
|
}
|
2024-10-12 11:51:11 +03:00
|
|
|
// Auto-render latex expressions with katex
|
2024-09-28 15:56:22 +03:00
|
|
|
script {
|
|
|
|
unsafe {
|
|
|
|
+"""
|
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
|
|
renderMathInElement(document.body, {
|
|
|
|
delimiters: [
|
|
|
|
{left: '$$', right: '$$', display: true},
|
|
|
|
{left: '$', right: '$', display: false},
|
|
|
|
],
|
|
|
|
throwOnError : false
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
""".trimIndent()
|
|
|
|
}
|
|
|
|
}
|
2024-04-30 19:00:37 +03:00
|
|
|
}
|
|
|
|
)
|
2024-10-12 11:51:11 +03:00
|
|
|
|
|
|
|
routing {
|
|
|
|
get("/"){
|
|
|
|
call.respondRedirect("lorem/ipsum")
|
|
|
|
}
|
|
|
|
}
|
2024-04-16 17:46:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun main() {
|
2024-09-28 11:48:25 +03:00
|
|
|
embeddedServer(CIO, module = Application::renderAllDocuments).start(true)
|
2024-04-16 17:46:00 +03:00
|
|
|
}
|