Merge mentions quote-stripping code into DText quote-stripping code.
This commit is contained in:
@@ -13,10 +13,16 @@ class DText
|
||||
end
|
||||
|
||||
def self.strip_blocks(string, tag)
|
||||
blocks = string.scan(/\[\/?#{tag}\]|.+?(?=\[\/?#{tag}\]|$)/m)
|
||||
n = 0
|
||||
stripped = ""
|
||||
blocks.each do |block|
|
||||
string = string.dup
|
||||
|
||||
string.gsub!(/\s*\[#{tag}\](?!\])\s*/m, "\n\n[#{tag}]\n\n")
|
||||
string.gsub!(/\s*\[\/#{tag}\]\s*/m, "\n\n[/#{tag}]\n\n")
|
||||
string.gsub!(/(?:\r?\n){3,}/, "\n\n")
|
||||
string.strip!
|
||||
|
||||
string.split(/\n{2}/).each do |block|
|
||||
case block
|
||||
when "[#{tag}]"
|
||||
n += 1
|
||||
@@ -26,7 +32,7 @@ class DText
|
||||
|
||||
else
|
||||
if n == 0
|
||||
stripped += block
|
||||
stripped << "#{block}\n\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,31 +16,10 @@ module Mentionable
|
||||
end
|
||||
end
|
||||
|
||||
def strip_quote_blocks(str)
|
||||
stripped = ""
|
||||
str.gsub!(/\s*\[quote\](?!\])\s*/m, "\n\n[quote]\n\n")
|
||||
str.gsub!(/\s*\[\/quote\]\s*/m, "\n\n[/quote]\n\n")
|
||||
str.gsub!(/(?:\r?\n){3,}/, "\n\n")
|
||||
str.strip!
|
||||
nest = 0
|
||||
str.split(/\n{2}/).each do |block|
|
||||
if block == "[quote]"
|
||||
nest += 1
|
||||
|
||||
elsif block == "[/quote]"
|
||||
nest -= 1
|
||||
|
||||
elsif nest == 0
|
||||
stripped << "#{block}\n"
|
||||
end
|
||||
end
|
||||
|
||||
stripped
|
||||
end
|
||||
|
||||
def queue_mention_messages
|
||||
from_id = read_attribute(self.class.mentionable_option(:user_field))
|
||||
text = strip_quote_blocks(read_attribute(self.class.mentionable_option(:message_field)))
|
||||
text = read_attribute(self.class.mentionable_option(:message_field))
|
||||
text = DText.strip_blocks(text, "quote")
|
||||
|
||||
names = text.scan(DText::MENTION_REGEXP).map do |mention|
|
||||
mention.gsub!(/(?:^\s*@)|(?:[:;,.!?\)\]<>]$)/, "")
|
||||
|
||||
Reference in New Issue
Block a user