Skip to content
Extraits de code Groupes Projets
Valider a92b28b4 rédigé par MrZYX's avatar MrZYX
Parcourir les fichiers

general search and replace in markdownify (#1042)

parent c20cd538
Branches
Étiquettes
Aucune requête de fusion associée trouvée
...@@ -169,21 +169,17 @@ module ApplicationHelper ...@@ -169,21 +169,17 @@ module ApplicationHelper
def markdownify(message, options = {}) def markdownify(message, options = {})
message = h(message).html_safe message = h(message).html_safe
if !options.has_key?(:newlines) options[:newlines] = true if !options.has_key?(:newlines)
options[:newlines] = true options[:emoticons] = true if !options.has_key?(:emoticons)
end
message = process_links(message) message = process_links(message)
message = process_autolinks(message) message = process_autolinks(message)
message = process_emphasis(message) message = process_emphasis(message)
message = process_youtube(message, options[:youtube_maps]) message = process_youtube(message, options[:youtube_maps])
message = process_vimeo(message, options[:vimeo_maps]) message = process_vimeo(message, options[:vimeo_maps])
message = process_emoticons(message) if options[:emoticons]
message.gsub!(/&lt;3/, "&hearts;") message.gsub!(/\n+/, '<br />') if options[:newlines]
if options[:newlines]
message.gsub!(/\n+/, '<br />')
end
return message return message
end end
...@@ -279,6 +275,24 @@ module ApplicationHelper ...@@ -279,6 +275,24 @@ module ApplicationHelper
return processed_message return processed_message
end end
def process_emoticons(message)
map = {
"&lt;3" => "&hearts;",
":(" => "&#9785;",
":-(" => "&#9785;",
":)" => "&#9786;",
":-)" => "&#9786;",
"-&gt;" => "&rarr;",
"&lt;-" => "&larr;",
"..." => "&hellip;"
}
map.each do |search, replace|
message.gsub!(search, replace)
end
message
end
def info_text(text) def info_text(text)
image_tag 'icons/monotone_question.png', :class => 'what_is_this', :title => text image_tag 'icons/monotone_question.png', :class => 'what_is_this', :title => text
end end
......
...@@ -161,11 +161,21 @@ describe ApplicationHelper do ...@@ -161,11 +161,21 @@ describe ApplicationHelper do
end end
end end
describe "hearts" do describe "emoticons" do
it "replaces &lt;3 with &hearts;" do it "replaces &lt;3 with &hearts;" do
message = "i <3 you" message = "i <3 you"
markdownify(message).should == "i &hearts; you" markdownify(message).should == "i &hearts; you"
end end
it "replaces various things with (their) HTML entities" do
message = ":) :-) :( :-( ... -> <-"
markdownify(message).should == "&#9786; &#9786; &#9785; &#9785; &hellip; &rarr; &larr;"
end
it "skips doing it if you say so" do
message = ":) :-) :( :-( ... -> <-"
markdownify(message, :emoticons => false).should == ":) :-) :( :-( ... -&gt; &lt;-"
end
end end
describe "weak emphasis" do describe "weak emphasis" do
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter