chat_sdk-telegram 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/chat_sdk/telegram/format_converter.rb +1 -8
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f873b2a03fd234639c59a872229bcd2942abc6169b1c970023ceaa16cb239062
|
|
4
|
+
data.tar.gz: 9e41b3269dc1116e2bc7169b146770337e8f9bbb6020b85f7f36c575828cf678
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 331146db0c5788c64ce2c7da1a097ff0ae54d2ad946d471be832fdb8123439db92feb7e3db213c023bed0f61cc3121822e6cf26560fc1ec6bd8962ec0082fbe3
|
|
7
|
+
data.tar.gz: 9843eee8e48fab1a345487035beac68a014bc558e343346dc1cfe6a170f7799b9170f9cff2e10d9bc8fdb738c4cc73fa118731558508baf8970509e54aeea3e2
|
|
@@ -4,7 +4,6 @@ module ChatSDK
|
|
|
4
4
|
module Telegram
|
|
5
5
|
class FormatConverter < ChatSDK::Format::Converter
|
|
6
6
|
SPECIAL_CHARS = %w[_ * [ ] ( ) ~ \\ ` > # + - = | { } . !].freeze
|
|
7
|
-
ESCAPE_RE = Regexp.union(SPECIAL_CHARS).freeze
|
|
8
7
|
|
|
9
8
|
# Telegram MarkdownV2 → standard Markdown
|
|
10
9
|
def to_markdown(platform_text)
|
|
@@ -30,18 +29,12 @@ module ChatSDK
|
|
|
30
29
|
text = markdown.to_s
|
|
31
30
|
return "" if text.empty?
|
|
32
31
|
|
|
33
|
-
parts =
|
|
32
|
+
parts = split_code_blocks(text)
|
|
34
33
|
parts.map.with_index { |part, i| i.odd? ? part : escape_special_chars(part) }.join
|
|
35
34
|
end
|
|
36
35
|
|
|
37
36
|
private
|
|
38
37
|
|
|
39
|
-
# Splits text into alternating [text, code, text, code, ...] segments.
|
|
40
|
-
# Odd-indexed segments are code blocks/inline code and are NOT escaped.
|
|
41
|
-
def split_code_segments(text)
|
|
42
|
-
text.split(/(```[\s\S]*?```|`[^`]+`)/)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
38
|
# Escape Telegram MarkdownV2 special chars outside of markdown syntax.
|
|
46
39
|
# Preserves bold (**), italic (*), strikethrough (~~), links, etc.
|
|
47
40
|
def escape_special_chars(text)
|