1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-09-04 15:49:41 +00:00
This commit is contained in:
2019-01-23 12:15:57 +08:00
parent c6e7111ff5
commit a0a93646e4
5 changed files with 28 additions and 8 deletions

View File

@@ -1,10 +1,12 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toMarkdown
interface MessageEntity {
val offset: Int
val length: Int
val sourceString: String
val asMarkdownSource: String
get() = sourceString
get() = sourceString.toMarkdown()
}

View File

@@ -3,6 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.utils
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toMarkdown
fun createMarkdownText(
text: String,
@@ -12,7 +13,7 @@ fun createMarkdownText(
var offset = 0
for (entity in messageEntities) {
builder.append(
text.substring(offset until entity.offset)
text.substring(offset until entity.offset).toMarkdown()
)
builder.append(
entity.asMarkdownSource
@@ -20,7 +21,7 @@ fun createMarkdownText(
offset += entity.length
}
builder.append(
text.substring(offset)
text.substring(offset).toMarkdown()
)
return builder.toString()
}

View File

@@ -0,0 +1,11 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils.extensions
fun String.toMarkdown(): String {
return replace(
"*",
"\\*"
).replace(
"_",
"\\_"
)
}