This commit is contained in:
2026-07-29 21:09:11 +03:00
parent 12ad115720
commit 4d9a6aa4d6
2 changed files with 6 additions and 4 deletions
@@ -6,7 +6,7 @@ import ru.shadowsparky.chat.domain.TextToken
@Factory
class MovieTextParser : ChatTextParser {
private val regex = Regex("\\*\\*(.*?)\\*\\*")
private val regex = Regex("«(.*?)»|\"(.*?)\"")
override fun parse(content: String): List<TextToken> {
val tokens = mutableListOf<TextToken>()
@@ -15,10 +15,12 @@ class MovieTextParser : ChatTextParser {
if (matchResult.range.first > lastIndex) {
tokens.add(TextToken.Plain(content.substring(lastIndex, matchResult.range.first)))
}
val movieTitle = matchResult.groupValues[1]
val movieTitle = matchResult.groupValues[1].takeIf { it.isNotEmpty() }
?: matchResult.groupValues[2]
tokens.add(TextToken.Link(text = movieTitle))
lastIndex = matchResult.range.last + 1
}
if (lastIndex < content.length) {
tokens.add(TextToken.Plain(content.substring(lastIndex)))
}