mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
MessageEntity#asHtmlSource
This commit is contained in:
parent
1bdcf3ae60
commit
609a474874
@ -49,10 +49,11 @@ media for present out)
|
||||
* `PhotoContent` now choose biggest photo size from its collection as `media`
|
||||
* Fix in order of media group messages which was received by webhooks
|
||||
|
||||
### 0.12.4 UpdatesPoller optimisations
|
||||
### 0.12.4
|
||||
|
||||
* Optimized preparing of media group in `UpdatesPoller`
|
||||
* Add `CommonLimiter`
|
||||
* Add `MessageEntity#asHtmlSource` and `String#toHtml`
|
||||
|
||||
## 0.11.0
|
||||
|
||||
|
@ -5,5 +5,6 @@ data class BoldTextMessageEntity(
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : TextMessageEntity() {
|
||||
override val formatSymbol: String = "*"
|
||||
override val markdownFormatSymbol: String = "*"
|
||||
override val htmlFormatTagname: String = "b"
|
||||
}
|
||||
|
@ -5,5 +5,6 @@ data class CodeTextMessageEntity(
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : TextMessageEntity() {
|
||||
override val formatSymbol: String = "`"
|
||||
override val markdownFormatSymbol: String = "`"
|
||||
override val htmlFormatTagname: String = "code"
|
||||
}
|
||||
|
@ -4,8 +4,7 @@ class EMailMessageEntity(
|
||||
override val offset: Int,
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : MessageEntity {
|
||||
override val asMarkdownSource: String by lazy {
|
||||
"[$sourceString](mailto://$sourceString)"
|
||||
}
|
||||
}
|
||||
) : LinkMessageEntity(
|
||||
sourceString,
|
||||
"mailto://$sourceString"
|
||||
)
|
||||
|
@ -5,5 +5,6 @@ data class ItalicTextMessageEntity(
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : TextMessageEntity() {
|
||||
override val formatSymbol: String = "_"
|
||||
override val markdownFormatSymbol: String = "_"
|
||||
override val htmlFormatTagname: String = "i"
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
|
||||
abstract class LinkMessageEntity(
|
||||
val linkTitle: String,
|
||||
val link: String
|
||||
) : MessageEntity {
|
||||
|
||||
override val asMarkdownSource: String by lazy {
|
||||
"[$linkTitle]($link)"
|
||||
}
|
||||
override val asHtmlSource: String by lazy {
|
||||
"<a href=\"$link\">$linkTitle</a>"
|
||||
}
|
||||
}
|
@ -4,7 +4,4 @@ class MentionMessageEntity(
|
||||
override val offset: Int,
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : MessageEntity {
|
||||
override val asMarkdownSource: String
|
||||
get() = sourceString
|
||||
}
|
||||
) : MessageEntity
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toHtml
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toMarkdown
|
||||
|
||||
interface MessageEntity {
|
||||
@ -9,4 +10,7 @@ interface MessageEntity {
|
||||
|
||||
val asMarkdownSource: String
|
||||
get() = sourceString.toMarkdown()
|
||||
|
||||
val asHtmlSource: String
|
||||
get() = sourceString.toHtml()
|
||||
}
|
||||
|
@ -5,5 +5,6 @@ data class PreTextMessageEntity(
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : TextMessageEntity() {
|
||||
override val formatSymbol: String = "```"
|
||||
override val markdownFormatSymbol: String = "```"
|
||||
override val htmlFormatTagname: String = "pre"
|
||||
}
|
||||
|
@ -5,8 +5,7 @@ data class TextLinkMessageEntity(
|
||||
override val length: Int,
|
||||
override val sourceString: String,
|
||||
val url: String
|
||||
) : MessageEntity {
|
||||
override val asMarkdownSource: String by lazy {
|
||||
"[$sourceString]($url)"
|
||||
}
|
||||
}
|
||||
) : LinkMessageEntity(
|
||||
sourceString,
|
||||
url
|
||||
)
|
||||
|
@ -7,8 +7,7 @@ class TextMentionMessageEntity(
|
||||
override val length: Int,
|
||||
override val sourceString: String,
|
||||
val user: User
|
||||
) : MessageEntity {
|
||||
override val asMarkdownSource: String by lazy {
|
||||
"[$sourceString](tg://user?id=${user.id})"
|
||||
}
|
||||
}
|
||||
) : LinkMessageEntity(
|
||||
sourceString,
|
||||
"tg://user?id=${user.id})"
|
||||
)
|
||||
|
@ -1,9 +1,14 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
|
||||
abstract class TextMessageEntity : MessageEntity {
|
||||
protected abstract val formatSymbol: String
|
||||
protected abstract val markdownFormatSymbol: String
|
||||
protected abstract val htmlFormatTagname: String
|
||||
|
||||
override val asMarkdownSource: String by lazy {
|
||||
"$formatSymbol$sourceString$formatSymbol"
|
||||
"$markdownFormatSymbol$sourceString$markdownFormatSymbol"
|
||||
}
|
||||
|
||||
override val asHtmlSource: String by lazy {
|
||||
"<$htmlFormatTagname>$sourceString</$htmlFormatTagname>"
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,9 @@ data class URLMessageEntity(
|
||||
override val offset: Int,
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : MessageEntity {
|
||||
val url: String
|
||||
get() = sourceString
|
||||
|
||||
override val asMarkdownSource: String by lazy {
|
||||
"[$sourceString]($url)"
|
||||
}
|
||||
) : LinkMessageEntity(
|
||||
sourceString,
|
||||
sourceString
|
||||
) {
|
||||
val url: String = link
|
||||
}
|
||||
|
@ -9,3 +9,17 @@ fun String.toMarkdown(): String {
|
||||
"\\_"
|
||||
)
|
||||
}
|
||||
|
||||
fun String.toHtml(): String = replace(
|
||||
"<",
|
||||
"<"
|
||||
).replace(
|
||||
">",
|
||||
">"
|
||||
).replace(
|
||||
"&",
|
||||
"&"
|
||||
).replace(
|
||||
"\"",
|
||||
"""
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user