Module: FlowChat::Renderers::MarkdownSupport

Included in:
Intercom::Renderer, Messenger::Renderer, Telegram::Renderer, Whatsapp::Renderer
Defined in:
lib/flow_chat/renderers/markdown_support.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



34
35
36
# File 'lib/flow_chat/renderers/markdown_support.rb', line 34

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#sanitize_html(html) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/flow_chat/renderers/markdown_support.rb', line 14

def sanitize_html(html)
  sanitized = self.class.sanitizer.sanitize(
    html,
    tags: allowed_tags,
    attributes: allowed_attributes
  )

  post_process_html(sanitized)
end

#to_html(text) ⇒ Object



7
8
9
10
11
12
# File 'lib/flow_chat/renderers/markdown_support.rb', line 7

def to_html(text)
  return "" if text.nil?

  html = Kramdown::Document.new(text.to_s, **kramdown_options).to_html.strip
  sanitize_html(html)
end

#to_plain_text(text) ⇒ Object

Markdown rendered as plain text, for platforms with no rich text at all. Messenger and Instagram both fall here: they display exactly the characters sent, so any leftover markup is noise the user reads.



27
28
29
30
31
32
# File 'lib/flow_chat/renderers/markdown_support.rb', line 27

def to_plain_text(text)
  return "" if text.nil?

  html = Kramdown::Document.new(text.to_s, **kramdown_options).to_html.strip
  html_to_plain_text(html)
end