Merge mentions quote-stripping code into DText quote-stripping code.

This commit is contained in:
evazion
2017-04-24 19:34:51 -05:00
parent 76eefd0ffe
commit 18424531fa
2 changed files with 11 additions and 26 deletions

View File

@@ -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