Class: ChatSDK::Discord::FormatConverter

Inherits:
Format::Converter
  • Object
show all
Defined in:
lib/chat_sdk/discord/format_converter.rb

Instance Method Summary collapse

Instance Method Details

#from_markdown(markdown) ⇒ Object

Markdown → Discord (mostly pass-through since Discord uses standard markdown)



28
29
30
31
32
33
# File 'lib/chat_sdk/discord/format_converter.rb', line 28

def from_markdown(markdown)
  text = markdown.to_s
  return "" if text.empty?

  text
end

#to_markdown(platform_text) ⇒ Object

Discord → Markdown



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/chat_sdk/discord/format_converter.rb', line 7

def to_markdown(platform_text)
  text = platform_text.to_s
  return "" if text.empty?

  # Convert user mentions: <@123456> → @123456
  text = text.gsub(/<@!?(\d+)>/, '@\1')

  # Convert channel mentions: <#123456> → #123456
  text = text.gsub(/<#(\d+)>/, '#\1')

  # Convert animated custom emoji: <a:name:id> → :name:
  text = text.gsub(/<a:(\w+):\d+>/, ':\1:')

  # Convert custom emoji: <:name:id> → :name:
  text = text.gsub(/<:(\w+):\d+>/, ':\1:')

  # Strip spoiler markers: ||text|| → text
  text.gsub(/\|\|(.+?)\|\|/m, '\1')
end