general search and replace in markdownify (#1042)
This commit is contained in:
parent
c20cd5381e
commit
a92b28b4bf
2 changed files with 33 additions and 9 deletions
|
|
@ -169,21 +169,17 @@ module ApplicationHelper
|
|||
def markdownify(message, options = {})
|
||||
message = h(message).html_safe
|
||||
|
||||
if !options.has_key?(:newlines)
|
||||
options[:newlines] = true
|
||||
end
|
||||
options[:newlines] = true if !options.has_key?(:newlines)
|
||||
options[:emoticons] = true if !options.has_key?(:emoticons)
|
||||
|
||||
message = process_links(message)
|
||||
message = process_autolinks(message)
|
||||
message = process_emphasis(message)
|
||||
message = process_youtube(message, options[:youtube_maps])
|
||||
message = process_vimeo(message, options[:vimeo_maps])
|
||||
message = process_emoticons(message) if options[:emoticons]
|
||||
|
||||
message.gsub!(/<3/, "♥")
|
||||
|
||||
if options[:newlines]
|
||||
message.gsub!(/\n+/, '<br />')
|
||||
end
|
||||
message.gsub!(/\n+/, '<br />') if options[:newlines]
|
||||
|
||||
return message
|
||||
end
|
||||
|
|
@ -279,6 +275,24 @@ module ApplicationHelper
|
|||
return processed_message
|
||||
end
|
||||
|
||||
def process_emoticons(message)
|
||||
map = {
|
||||
"<3" => "♥",
|
||||
":(" => "☹",
|
||||
":-(" => "☹",
|
||||
":)" => "☺",
|
||||
":-)" => "☺",
|
||||
"->" => "→",
|
||||
"<-" => "←",
|
||||
"..." => "…"
|
||||
}
|
||||
|
||||
map.each do |search, replace|
|
||||
message.gsub!(search, replace)
|
||||
end
|
||||
message
|
||||
end
|
||||
|
||||
def info_text(text)
|
||||
image_tag 'icons/monotone_question.png', :class => 'what_is_this', :title => text
|
||||
end
|
||||
|
|
|
|||
|
|
@ -161,11 +161,21 @@ describe ApplicationHelper do
|
|||
end
|
||||
end
|
||||
|
||||
describe "hearts" do
|
||||
describe "emoticons" do
|
||||
it "replaces <3 with ♥" do
|
||||
message = "i <3 you"
|
||||
markdownify(message).should == "i ♥ you"
|
||||
end
|
||||
|
||||
it "replaces various things with (their) HTML entities" do
|
||||
message = ":) :-) :( :-( ... -> <-"
|
||||
markdownify(message).should == "☺ ☺ ☹ ☹ … → ←"
|
||||
end
|
||||
|
||||
it "skips doing it if you say so" do
|
||||
message = ":) :-) :( :-( ... -> <-"
|
||||
markdownify(message, :emoticons => false).should == ":) :-) :( :-( ... -> <-"
|
||||
end
|
||||
end
|
||||
|
||||
describe "weak emphasis" do
|
||||
|
|
|
|||
Loading…
Reference in a new issue