class SimpleFormat::Converter

Public Class Methods

new(emoji=nil) click to toggle source
# File lib/simple_format.rb, line 8
def initialize(emoji=nil)
  @emoji = emoji if emoji.is_a?(SimpleFormat::Emoji)
end

Public Instance Methods

emoji_with(string) click to toggle source
# File lib/simple_format.rb, line 21
def emoji_with(string) # 表情符 转 <img>
  emoji.replace_emoji_with_images(string)
end
html_with(html, options = {}) click to toggle source
# File lib/simple_format.rb, line 25
def html_with(html, options = {})
  options = { elements: sanitized_allowed_tags, attributes: { all: sanitized_allowed_attributes } } if options.empty?
  Sanitize.clean(html, options)
end
nl2br(string) click to toggle source
# File lib/simple_format.rb, line 34
def nl2br(string) # 回车 转 <br />
  if string
    string.gsub("\n\r","<br />").gsub("\r", "").gsub("\n", "<br />")
  end
end
rich_with(string) click to toggle source
# File lib/simple_format.rb, line 12
def rich_with(string) # 转 富文本
  return string unless string
  string = emoji_with(string)
  string = nl2br(string).to_str
  string = auto_link(string)
  string = html_with(string)
  return string
end
text_with(string) click to toggle source
# File lib/simple_format.rb, line 30
def text_with(string) # 清除 html
  Sanitize.clean(string, {elements: [], attributes: { all: [] }})
end

Private Instance Methods

emoji() click to toggle source
# File lib/simple_format.rb, line 47
def emoji
  @emoji || Emoji.new
end
sanitized_allowed_attributes() click to toggle source
# File lib/simple_format.rb, line 55
def sanitized_allowed_attributes
  ['shape', 'coords', 'target', 'href', 'muted', 'volume', 'name', 'class', 'title', 'border', 'poster', 'loop', 'autoplay', 'allowfullscreen', 'fullscreen', 'align' , 'quality', 'allowscriptaccess', 'wmode', 'flashvars', 'webkit-playsinline', 'x-webkit-airplay', 'data-original', 'src', 'controls', 'preload', 'type', 'width', 'height', 'size', 'alt']
end
sanitized_allowed_tags() click to toggle source
# File lib/simple_format.rb, line 51
def sanitized_allowed_tags
  ['a', 'p', 'br', 'img', 'abbr', 'mark', 'm', 'fieldset', 'legend', 'label', 'summary', 'details', 'address', 'map', 'area', 'td', 'tr', 'th', 'thead', 'tbody', 'tfoot', 'caption', 'table', 'h4', 'h5', 'h6', 'hr', 'span', 'em', 'dl', 'dt', 'dd', 'b', 'del', 'ins', 'small', 'pre', 'blockquote', 'strong', 'audio', 'video', 'source', 'ul', 'ol', 'li', 'i', 'embed', 'sub', 'sup']
end