Class: ChatSDK::Slack::FormatConverter

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

Instance Method Summary collapse

Instance Method Details

#from_markdown(markdown) ⇒ Object

Standard Markdown -> Slack mrkdwn



15
16
17
18
19
20
# File 'lib/chat_sdk/slack/format_converter.rb', line 15

def from_markdown(markdown)
  return "" if markdown.nil? || markdown.empty?

  parts = split_code_blocks(markdown)
  parts.map.with_index { |part, i| i.odd? ? part : convert_md_to_mrkdwn(part) }.join
end

#to_markdown(mrkdwn) ⇒ Object

Slack mrkdwn -> standard Markdown



7
8
9
10
11
12
# File 'lib/chat_sdk/slack/format_converter.rb', line 7

def to_markdown(mrkdwn)
  return "" if mrkdwn.nil? || mrkdwn.empty?

  parts = split_code_blocks(mrkdwn)
  parts.map.with_index { |part, i| i.odd? ? part : convert_mrkdwn_to_md(part) }.join
end