Use `gsub` instead of `gsub!` to not modify frozen literals
This commit is contained in:
parent
3bdca34c2d
commit
c84b6a61bd
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class FlavoredMarkdown < Redcarpet::Render::HTML
|
class FlavoredMarkdown < Redcarpet::Render::HTML
|
||||||
include Rails.application.routes.url_helpers
|
include Rails.application.routes.url_helpers
|
||||||
include SharedMarkers
|
include SharedMarkers
|
||||||
|
@ -7,10 +9,9 @@ class FlavoredMarkdown < Redcarpet::Render::HTML
|
||||||
end
|
end
|
||||||
|
|
||||||
def wrap_mentions(text)
|
def wrap_mentions(text)
|
||||||
text.gsub! /(^|\s)(@[a-zA-Z0-9_]{1,16})/ do
|
text.gsub(/(^|\s)(@[a-zA-Z0-9_]{1,16})/) do
|
||||||
"#{$1}[#{$2}](#{show_user_profile_path $2.tr('@', '')})"
|
"#{$1}[#{$2}](#{show_user_profile_path $2.tr('@', '')})"
|
||||||
end
|
end
|
||||||
text
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def header(text, _header_level)
|
def header(text, _header_level)
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
class TwitteredMarkdown < Redcarpet::Render::StripDown
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class TwitteredMarkdown < Redcarpet::Render::StripDown
|
||||||
def preprocess(text)
|
def preprocess(text)
|
||||||
wrap_mentions(text)
|
wrap_mentions(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
def wrap_mentions(text)
|
def wrap_mentions(text)
|
||||||
text.gsub! /(^|\s)@([a-zA-Z0-9_]{1,16})/ do
|
text.gsub(/(^|\s)@([a-zA-Z0-9_]{1,16})/) do
|
||||||
local_user = User.find_by_screen_name($2)
|
local_user = User.find_by(screen_name: $2)
|
||||||
if local_user.nil?
|
if local_user.nil?
|
||||||
"#{$1}#{$2}"
|
"#{$1}#{$2}"
|
||||||
else
|
else
|
||||||
|
@ -18,6 +19,5 @@ class TwitteredMarkdown < Redcarpet::Render::StripDown
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
text
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue