Kill trailing whitespace in ruby files
This commit is contained in:
@@ -5,11 +5,11 @@ class DText
|
||||
def self.u(string)
|
||||
CGI.escape(string)
|
||||
end
|
||||
|
||||
|
||||
def self.h(string)
|
||||
CGI.escapeHTML(string)
|
||||
end
|
||||
|
||||
|
||||
def self.parse_inline(str, options = {})
|
||||
str.gsub!(/&/, "&")
|
||||
str.gsub!(/</, "<")
|
||||
@@ -25,7 +25,7 @@ class DText
|
||||
str = parse_id_links(str)
|
||||
str
|
||||
end
|
||||
|
||||
|
||||
def self.parse_links(str)
|
||||
str.gsub(/("[^"]+":(https?:\/\/|\/)[^\s\r\n<>]+|https?:\/\/[^\s\r\n<>]+)+/) do |url|
|
||||
if url =~ /^"([^"]+)":(.+)$/
|
||||
@@ -34,7 +34,7 @@ class DText
|
||||
else
|
||||
text = url
|
||||
end
|
||||
|
||||
|
||||
if url =~ /([;,.!?\)\]<>])$/
|
||||
url.chop!
|
||||
ch = $1
|
||||
@@ -45,7 +45,7 @@ class DText
|
||||
'<a href="' + url + '">' + text + '</a>' + ch
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.parse_aliased_wiki_links(str)
|
||||
str.gsub(/\[\[([^\|\]]+)\|([^\]]+)\]\]/m) do
|
||||
text = CGI.unescapeHTML($2)
|
||||
@@ -53,7 +53,7 @@ class DText
|
||||
%{<a href="/wiki_pages/show_or_new?title=#{u(title)}">#{h(text)}</a>}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.parse_wiki_links(str)
|
||||
str.gsub(/\[\[([^\]]+)\]\]/) do
|
||||
text = CGI.unescapeHTML($1)
|
||||
@@ -61,14 +61,14 @@ class DText
|
||||
%{<a href="/wiki_pages/show_or_new?title=#{u(title)}">#{h(text)}</a>}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.parse_post_links(str)
|
||||
str.gsub(/\{\{([^\}]+)\}\}/) do
|
||||
tags = CGI.unescapeHTML($1)
|
||||
%{<a href="/posts?tags=#{u(tags)}">#{h(tags)}</a>}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.parse_id_links(str)
|
||||
str = str.gsub(/\bpost #(\d+)/i, %{<a href="/posts/\\1">post #\\1</a>})
|
||||
str = str.gsub(/\bforum #(\d+)/i, %{<a href="/forum_posts/\\1">forum #\\1</a>})
|
||||
@@ -76,7 +76,7 @@ class DText
|
||||
str = str.gsub(/\bpool #(\d+)/i, %{<a href="/pools/\\1">pool #\\1</a>})
|
||||
str = str.gsub(/\buser #(\d+)/i, %{<a href="/users/\\1">user #\\1</a>})
|
||||
end
|
||||
|
||||
|
||||
def self.parse_list(str, options = {})
|
||||
html = ""
|
||||
layout = []
|
||||
@@ -115,27 +115,27 @@ class DText
|
||||
|
||||
def self.parse(str, options = {})
|
||||
return "" if str.blank?
|
||||
|
||||
|
||||
# Make sure quote tags are surrounded by newlines
|
||||
|
||||
|
||||
unless options[:inline]
|
||||
str.gsub!(/\s*\[quote\]\s*/m, "\n\n[quote]\n\n")
|
||||
str.gsub!(/\s*\[\/quote\]\s*/m, "\n\n[/quote]\n\n")
|
||||
str.gsub!(/\s*\[spoilers?\](?!\])\s*/m, "\n\n[spoiler]\n\n")
|
||||
str.gsub!(/\s*\[\/spoilers?\]\s*/m, "\n\n[/spoiler]\n\n")
|
||||
end
|
||||
|
||||
|
||||
str.gsub!(/(?:\r?\n){3,}/, "\n\n")
|
||||
str.strip!
|
||||
blocks = str.split(/(?:\r?\n){2}/)
|
||||
stack = []
|
||||
|
||||
|
||||
html = blocks.map do |block|
|
||||
case block
|
||||
when /^(h[1-6])\.\s*(.+)$/
|
||||
tag = $1
|
||||
content = $2
|
||||
|
||||
content = $2
|
||||
|
||||
if options[:inline]
|
||||
"<h6>" + parse_inline(content, options) + "</h6>"
|
||||
else
|
||||
@@ -144,7 +144,7 @@ class DText
|
||||
|
||||
when /^\s*\*+ /
|
||||
parse_list(block, options)
|
||||
|
||||
|
||||
when "[quote]"
|
||||
if options[:inline]
|
||||
""
|
||||
@@ -152,7 +152,7 @@ class DText
|
||||
stack << "blockquote"
|
||||
"<blockquote>"
|
||||
end
|
||||
|
||||
|
||||
when "[/quote]"
|
||||
if options[:inline]
|
||||
""
|
||||
@@ -166,7 +166,7 @@ class DText
|
||||
when /\[spoilers?\](?!\])/
|
||||
stack << "div"
|
||||
'<div class="spoiler">'
|
||||
|
||||
|
||||
when /\[\/spoilers?\]/
|
||||
if stack.last == "div"
|
||||
stack.pop
|
||||
@@ -177,7 +177,7 @@ class DText
|
||||
'<p>' + parse_inline(block) + "</p>"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
stack.reverse.each do |tag|
|
||||
if tag == "blockquote"
|
||||
html << "</blockquote>"
|
||||
@@ -188,10 +188,10 @@ class DText
|
||||
|
||||
sanitize(html.join("")).html_safe
|
||||
end
|
||||
|
||||
|
||||
def self.sanitize(text)
|
||||
text.gsub!(/<( |-|\Z)/, "<\\1")
|
||||
|
||||
|
||||
Sanitize.clean(
|
||||
text,
|
||||
:elements => %w(code center tn h1 h2 h3 h4 h5 h6 a span div blockquote br p ul li ol em strong small big b i font u s),
|
||||
|
||||
Reference in New Issue
Block a user