mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-04 15:49:41 +00:00
0.8.5
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
@@ -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()
|
||||
}
|
||||
|
@@ -0,0 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.utils.extensions
|
||||
|
||||
fun String.toMarkdown(): String {
|
||||
return replace(
|
||||
"*",
|
||||
"\\*"
|
||||
).replace(
|
||||
"_",
|
||||
"\\_"
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user