Class: CnMdEmoji::Render
- Inherits:
-
Redcarpet::Render::HTML
- Object
- Redcarpet::Render::HTML
- CnMdEmoji::Render
- Defined in:
- lib/cn_md_emoji/render.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Render
constructor
A new instance of Render.
- #list_item(text, list_type) ⇒ Object
- #paragraph(text) ⇒ Object
-
#replace_emoji(text) ⇒ Object
Replaces valid emoji characters, ie :smile:, with img tags.
Constructor Details
#initialize(options = {}) ⇒ Render
Returns a new instance of Render.
3 4 5 6 |
# File 'lib/cn_md_emoji/render.rb', line 3 def initialize(={}) @options = .merge(:no_intra_emphasis => true) super @options end |
Instance Method Details
#list_item(text, list_type) ⇒ Object
14 15 16 |
# File 'lib/cn_md_emoji/render.rb', line 14 def list_item(text, list_type) "<li>#{replace_emoji(text)}</li>" end |
#paragraph(text) ⇒ Object
8 9 10 11 12 |
# File 'lib/cn_md_emoji/render.rb', line 8 def paragraph(text) text.gsub!("\n", "<br>\n") if @options[:hard_wrap] "<p>#{replace_emoji(text)}</p>\n" end |
#replace_emoji(text) ⇒ Object
Replaces valid emoji characters, ie :smile:, with img tags
Valid emoji charaters are listed in MdEmoji::EMOJI
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cn_md_emoji/render.rb', line 21 def replace_emoji(text) text.gsub(/\[(\S+?)\]/) do |emoji| emoji_code = emoji emoji = emoji_code.gsub(/[\[\]]/, "") filename = nil if CnMdEmoji::CN_MOJI.include?(emoji) emoji = CnMdEmoji::CN_EN[emoji] file_name = "#{emoji}.gif" end if CnMdEmoji::EMOJI.include?(emoji) file_name = "#{emoji}.png" end if file_name default_size = %{height="22" width="22"} %{<img src="/assets/emojis/#{file_name}" class="emoji" } + %{title="#{emoji_code}" alt="#{emoji_code}" #{default_size}>} else emoji_code end end end |