Skip to content

Commit

Permalink
support emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Sep 30, 2012
1 parent 4821f9b commit f61c7e9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions misc/style/gfm/gfm_style.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8; -*-
#
# gfm_style.rb: "GitHub Flavored Markdown" (GFM) style for tDiary 2.x format.
#
Expand Down Expand Up @@ -125,6 +126,12 @@ def to_html(string)
# plugin
r.gsub!(/\{\{(.+?)\}\}/) { "<%=#{CGI.unescapeHTML($1)}%>" }

# emoji
r.gsub!(/:([a-z0-9_+-]+):/) do |emoji|
emoji.gsub!(":", "")
"<img src='http://www.emoji-cheat-sheet.com/graphics/emojis/#{emoji}.png' width='20' height='20' title='#{emoji}' alt='#{emoji}' class='emoji' />"
end

# my syntax
r.gsub!(/\((.*?)\)\[(\d{4}|\d{6}|\d{8}|\d{8}-\d+)[^\d]*?#?([pct]\d+)?\]/) {
unless $1.empty?
Expand Down
21 changes: 21 additions & 0 deletions spec/core/style/gfm_style_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,27 @@ def class
<span class="vi">@foo</span> <span class="o">=</span> <span class="s1">&#39;bar&#39;</span>
<span class="k">end</span>
</pre></div><%=section_leave_proc( Time.at( 1041346800 ) )%>
</div>
EOF
end
it { @diary.to_html.should eq @html }
end

describe 'emoji' do
before do
source = <<-'EOF'
# subTitle
:sushi: は美味しい
EOF
@diary.append(source)

@html = <<-'EOF'
<div class="section">
<%=section_enter_proc( Time.at( 1041346800 ) )%>
<h3><%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %></h3>
<p><img src='http://www.emoji-cheat-sheet.com/graphics/emojis/sushi.png' width='20' height='20' title='sushi' alt='sushi' class='emoji' /> は美味しい</p>
<%=section_leave_proc( Time.at( 1041346800 ) )%>
</div>
EOF
end
Expand Down

0 comments on commit f61c7e9

Please sign in to comment.