Make text processor work on initial text, not on processed one.

This commit is contained in:
Alexander Nozik 2022-12-21 23:25:32 +03:00
parent 16ca24d329
commit 62da832db1
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
4 changed files with 11 additions and 13 deletions

View File

@ -1,3 +1,3 @@
kotlin.code.style=official
toolsVersion=0.12.1-kotlin-1.7.20-Beta
toolsVersion=0.13.1-kotlin-1.7.20

View File

@ -9,13 +9,13 @@ val ktorVersion = space.kscience.gradle.KScienceVersions.ktorVersion
dependencies {
api(projects.snarkCore)
api("org.jetbrains.kotlinx:kotlinx-html:0.7.5")
api("org.jetbrains.kotlinx:kotlinx-html:0.8.0")
api("org.jetbrains.kotlin-wrappers:kotlin-css")
api("io.ktor:ktor-utils:$ktorVersion")
api("space.kscience:dataforge-io-yaml:$dataforgeVersion")
api("org.jetbrains:markdown:0.3.1")
api("org.jetbrains:markdown:0.3.5")
}
readme {

View File

@ -48,16 +48,14 @@ internal object SnarkMarkdownParser : SnarkTextParser<HtmlFragment>() {
private val markdownFlavor = CommonMarkFlavourDescriptor()
private val markdownParser = MarkdownParser(markdownFlavor)
override fun parseText(text: String, meta: Meta): HtmlFragment {
val parsedTree = markdownParser.buildMarkdownTreeFromString(text)
val htmlString = HtmlGenerator(text, parsedTree, markdownFlavor).generateHtml()
override fun parseText(text: String, meta: Meta): HtmlFragment = HtmlFragment { page ->
val transformedText = SnarkHtmlParser.transformText(text, meta, page)
val parsedTree = markdownParser.buildMarkdownTreeFromString(transformedText)
val htmlString = HtmlGenerator(transformedText, parsedTree, markdownFlavor).generateHtml()
return HtmlFragment { page ->
div {
unsafe {
+SnarkHtmlParser.transformText(htmlString, meta, page)
}
div {
unsafe {
+htmlString
}
}
}

View File

@ -29,7 +29,7 @@ public fun interface TextProcessor {
*/
public object BasicTextProcessor : TextProcessor {
private val regex = """\$\{([\w.]*)(?>\("([\w.]*)"\))?}""".toRegex()
private val regex = """\$\{([\w.]*)(?>\("(.*)"\))?}""".toRegex()
context(WebPage) override fun process(text: String): String = text.replace(regex) { match ->
when (match.groups[1]!!.value) {