Permalink
Browse files

format_text support emoji.

  • Loading branch information...
1 parent ebb4666 commit 084906eb54ca21a82c580cda4a33c638dcadff38 @chloerei committed Mar 17, 2012
Showing with 27 additions and 2 deletions.
  1. +1 −0 Gemfile
  2. +4 −0 Gemfile.lock
  3. +2 −1 app/assets/javascripts/editor.js
  4. +20 −1 app/helpers/application_helper.rb
View
@@ -20,6 +20,7 @@ gem 'http_accept_language'
gem 'rails-i18n'
gem 'jquery-rails'
gem 'highlight_js-rails'
+gem 'md_emoji'
# Gems used only for assets and not required
# in production environments by default.
View
@@ -95,6 +95,9 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
+ md_emoji (0.0.6)
+ rails (>= 3.1.0)
+ redcarpet (>= 2.0)
mime-types (1.17.2)
mongo (1.6.1)
bson (~> 1.6.1)
@@ -186,6 +189,7 @@ DEPENDENCIES
http_accept_language
jquery-rails
kaminari
+ md_emoji
mongoid
rails (= 3.2.2)
rails-i18n
@@ -1,5 +1,6 @@
//= require wmd/wmd
-//= require wmd/showdown
+//= require showdown
+//= require wmd/showdown.emoji
//= require jquery.tagEditor
$(function(){
@@ -11,7 +11,26 @@ def format_text(text, options = {})
sanitize markdown(link_mentions(text.to_s, options[:mention_names]))
end
- @@html_render = Redcarpet::Render::HTML.new :hard_wrap => true, :no_styles => true
+ class HtmlRender < Redcarpet::Render::HTML
+ @@emoji_render = MdEmoji::Render.new
+
+ def initialize(options={})
+ @options = options
+ super options
+ end
+
+ def paragraph(text)
+ text.gsub!("\n", "<br>\n") if @options[:hard_wrap]
+
+ "<p>#{@@emoji_render.replace_emoji(text)}</p>\n"
+ end
+
+ def list_item(text, list_type)
+ "<li>#{@@emoji_render.replace_emoji(text)}</li>"
+ end
+ end
+
+ @@html_render = HtmlRender.new :hard_wrap => true, :no_styles => true
@@markdown = Redcarpet::Markdown.new @@html_render, :autolink => true, :no_intra_emphasis => true
def markdown(text)
@@markdown.render(text)

0 comments on commit 084906e

Please sign in to comment.