This commit is contained in:
r888888888
2014-02-27 13:41:36 -08:00
parent e53f19d9dd
commit 165e3a4efa
4 changed files with 36 additions and 3 deletions

View File

@@ -19,7 +19,18 @@
}
Danbooru.Comment.quote_message = function(data) {
var stripped_body = data["body"].replace(/\[quote\](?:.|\n|\r)+?\[\/quote\](?:\r\n|\r|\n)*/gm, "");
var blocks = data["body"].match(/\[\/?quote\]|./gm);
var n = 0;
var stripped_body = "";
$.each(blocks, function(i, block) {
if (block === "[quote]") {
n += 1;
} else if (block == "[/quote]") {
n -= 1;
} else if (n === 0) {
stripped_body += block;
}
});
return "[quote]\n" + data["creator_name"] + " said:\n\n" + stripped_body + "\n[/quote]\n\n";
}

View File

@@ -10,6 +10,28 @@ class DText
CGI.escapeHTML(string)
end
def self.strip_blocks(string, tag)
blocks = string.scan(/\[\/?#{tag}\]|.+?(?=\[\/?#{tag}\]|$)/m)
n = 0
stripped = ""
blocks.each do |block|
case block
when "[#{tag}]"
n += 1
when "[/#{tag}]"
n -= 1
else
if n == 0
stripped += block
end
end
end
stripped.strip
end
def self.parse_inline(str, options = {})
str.gsub!(/&/, "&")
str.gsub!(/</, "&lt;")

View File

@@ -149,7 +149,7 @@ class ForumPost < ActiveRecord::Base
end
def quoted_response
stripped_body = body.gsub(/\[quote\](?:.|\n|\r)+?\[\/quote\][\n\r]*/m, "")
stripped_body = DText.strip_blocks(body, "quote")
"[quote]\n#{creator_name} said:\n\n#{stripped_body}\n[/quote]\n\n"
end

View File

@@ -547,7 +547,7 @@ class Post < ActiveRecord::Base
end
def has_dup_tag?
has_tag?("duplicate") ? true : false
has_tag?("duplicate")
end
def tag_categories