class Kramdown::Converter::Slack

Converts a Kramdown::Document to Slack. api.slack.com/docs/message-formatting

Constants

SMART_QUOTES
TYPOGRAPHIC_SYMBOLS

Attributes

bullet[R]

Public Instance Methods

__convert_todo(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 129
def __convert_todo(el)
  inner(el)
end
convert(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 8
def convert(el)
  if el.type == :html_element
    converter = :"convert_html_#{el.value}"
    converter = :convert_html_element unless respond_to? converter
  else
    converter = :"convert_#{el.type}"
  end
  send(converter, el)
end
convert_a(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 72
def convert_a(el)
  content = inner(el)
  return el.attr["href"] if content.nil? || content == ""
  "<#{el.attr["href"]}|#{content}>"
end
Also aliased as: convert_html_a
convert_abbreviation(el)
Alias for: convert_text
convert_blank(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 32
def convert_blank(el)
  ""
end
Also aliased as: convert_br, convert_comment
convert_blockquote(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 64
def convert_blockquote(el)
  "> #{inner(el)}"
end
convert_br(el)
Alias for: convert_blank
convert_codeblock(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 68
def convert_codeblock(el)
  "```\n#{el.value}```\n\n"
end
convert_codespan(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 59
def convert_codespan(el)
  "`#{el.value}`"
end
Also aliased as: convert_html_code
convert_comment(el)
Alias for: convert_blank
convert_dd(el)

The following are all tags converted by Kramdown::Converter::Html

Alias for: __convert_todo
convert_del(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 54
def convert_del(el)
  "~#{inner(el)}~"
end
Also aliased as: convert_html_del
convert_dl(el)
Alias for: __convert_todo
convert_dt(el)
Alias for: __convert_todo
convert_em(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 48
def convert_em(el)
  "_#{inner(el)}_"
end
Also aliased as: convert_html_i, convert_html_em
convert_entity(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 123
def convert_entity(el)
  el.value.char
end
convert_footnote(el)
Alias for: __convert_todo
convert_header(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 101
def convert_header(el)
  "\n\n#{convert_strong(el)}\n"
end
convert_hr(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 111
def convert_hr(el)
  "----------------------------------------------\n\n"
end
convert_html_a(el)
Alias for: convert_a
convert_html_b(el)
Alias for: convert_strong
convert_html_br(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 38
def convert_html_br(el)
  "\n"
end
convert_html_code(el)
Alias for: convert_codespan
convert_html_del(el)
Alias for: convert_del
convert_html_element(el)
Alias for: __convert_todo
convert_html_em(el)
Alias for: convert_em
convert_html_h1(el)
Alias for: convert_header
convert_html_h2(el)
Alias for: convert_header
convert_html_h3(el)
Alias for: convert_header
convert_html_h4(el)
Alias for: convert_header
convert_html_h5(el)
Alias for: convert_header
convert_html_h6(el)
Alias for: convert_header
convert_html_i(el)
Alias for: convert_em
convert_html_img(el)
Alias for: convert_img
convert_html_li(el)
Alias for: convert_li
convert_html_ol(el)
Alias for: convert_ol
convert_html_strong(el)
Alias for: convert_strong
convert_html_ul(el)
Alias for: convert_ul
convert_img(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 79
def convert_img(el)
  el.attr["src"]
end
Also aliased as: convert_html_img
convert_li(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 96
def convert_li(el)
  "  #{bullet.next} #{inner(el).strip}\n"
end
Also aliased as: convert_html_li
convert_math(el)
Alias for: __convert_todo
convert_ol(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 90
def convert_ol(el)
  @bullet = OlBulletGenerator.new
  "#{inner(el)}\n"
end
Also aliased as: convert_html_ol
convert_p(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 23
def convert_p(el)
  "#{inner(el).strip.gsub(/\n/, " ")}\n\n"
end
convert_raw(el)
Alias for: __convert_todo
convert_root(el)
Alias for: inner
convert_smart_quote(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 115
def convert_smart_quote(el)
  SMART_QUOTES.fetch(el.value)
end
convert_strong(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 42
def convert_strong(el)
  "*#{inner(el)}*"
end
convert_table(el)
Alias for: __convert_todo
convert_tbody(el)
Alias for: __convert_todo
convert_td(el)
Alias for: __convert_todo
convert_text(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 27
def convert_text(el)
  el.value
end
Also aliased as: convert_abbreviation
convert_tfoot(el)
Alias for: __convert_todo
convert_thead(el)
Alias for: __convert_todo
convert_tr(el)
Alias for: __convert_todo
convert_typographic_sym(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 119
def convert_typographic_sym(el)
  TYPOGRAPHIC_SYMBOLS.fetch(el.value)
end
convert_ul(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 84
def convert_ul(el)
  @bullet = UlBulletGenerator.new
  "#{inner(el)}\n"
end
Also aliased as: convert_html_ul
convert_xml_comment(el)
Alias for: __convert_todo
convert_xml_pi(el)
Alias for: __convert_todo
inner(el) click to toggle source
# File lib/kramdown/converter/slack.rb, line 18
def inner(el)
  el.children.map { |el| convert(el) }.join
end
Also aliased as: convert_root