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 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 { dependencies {
api(projects.snarkCore) 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("org.jetbrains.kotlin-wrappers:kotlin-css")
api("io.ktor:ktor-utils:$ktorVersion") api("io.ktor:ktor-utils:$ktorVersion")
api("space.kscience:dataforge-io-yaml:$dataforgeVersion") api("space.kscience:dataforge-io-yaml:$dataforgeVersion")
api("org.jetbrains:markdown:0.3.1") api("org.jetbrains:markdown:0.3.5")
} }
readme { readme {

View File

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

View File

@ -29,7 +29,7 @@ public fun interface TextProcessor {
*/ */
public object BasicTextProcessor : 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 -> context(WebPage) override fun process(text: String): String = text.replace(regex) { match ->
when (match.groups[1]!!.value) { when (match.groups[1]!!.value) {