Merge pull request #3223 from evazion/fix-remove-dtext

Remove ruby DText implementation (#3206).
This commit is contained in:
Albert Yi
2017-07-19 17:59:59 -07:00
committed by GitHub
40 changed files with 47 additions and 582 deletions

View File

@@ -1,5 +1,5 @@
class DtextPreviewsController < ApplicationController
def create
render :inline => "<%= format_text(params[:body], :ragel => true) %>"
render :inline => "<%= format_text(params[:body]) %>"
end
end

View File

@@ -49,20 +49,12 @@ module ApplicationHelper
raw %{<a href="#{h(url)}" #{attributes}>#{text}</a>}
end
def format_text(text, ragel: true, **options)
if ragel
raw DTextRagel.parse(text, **options)
else
DText.parse(text)
end
def format_text(text, **options)
raw DTextRagel.parse(text, **options)
end
def strip_dtext(text, options = {})
if options[:ragel]
raw(DTextRagel.parse_strip(text))
else
DText.parse_strip(text)
end
def strip_dtext(text)
raw(DTextRagel.parse_strip(text))
end
def error_messages_for(instance_name)

View File

@@ -4,7 +4,7 @@ module PostAppealsHelper
html << '<ul>'
post.appeals.each do |appeal|
reason = DText.parse_inline(appeal.reason).html_safe
reason = format_text(appeal.reason, inline: true)
user = link_to_user(appeal.creator)
if CurrentUser.is_moderator?
ip = "(#{link_to_ip(appeal.creator_ip_addr)})"

View File

@@ -5,7 +5,7 @@ module PostFlagsHelper
post.flags.each do |flag|
html << '<li>'
html << DText.parse_inline(flag.reason).html_safe
html << format_text(flag.reason, inline: true)
if CurrentUser.can_view_flagger?(flag.creator_id)
html << " - #{link_to_user(flag.creator)}"

View File

@@ -3,14 +3,6 @@ require 'uri'
class DText
MENTION_REGEXP = /(?<=^| )@\S+/
def self.u(string)
CGI.escape(string)
end
def self.h(string)
CGI.escapeHTML(string)
end
def self.quote(message, creator_name)
stripped_body = DText.strip_blocks(message, "quote")
@@ -45,330 +37,6 @@ class DText
stripped.strip
end
def self.parse_inline(str, options = {})
str.gsub!(/&/, "&amp;")
str.gsub!(/</, "&lt;")
str.gsub!(/>/, "&gt;")
str.gsub!(/\n/m, "<br>") unless options[:ignore_newlines]
str.gsub!(/\[b\](.+?)\[\/b\]/i, '<strong>\1</strong>')
str.gsub!(/\[i\](.+?)\[\/i\]/i, '<em>\1</em>')
str.gsub!(/\[s\](.+?)\[\/s\]/i, '<s>\1</s>')
str.gsub!(/\[u\](.+?)\[\/u\]/i, '<u>\1</u>')
str.gsub!(/\[tn\](.+?)\[\/tn\]/i, '<p class="tn">\1</p>')
str = parse_mentions(str, options)
str = parse_links(str)
str = parse_aliased_wiki_links(str)
str = parse_wiki_links(str)
str = parse_post_links(str)
str = parse_id_links(str)
str
end
def self.parse_mentions(str, options = {})
return if options[:disable_mentions]
str.gsub!(MENTION_REGEXP) do |name|
next name unless name =~ /[a-z0-9]/i
if name =~ /([:;,.!?\)\]<>])$/
name.chop!
ch = $1
else
ch = ""
end
'<a href="/users?name=' + u(CGI.unescapeHTML(name[1..-1])) + '">' + name + '</a>' + ch
end
str
end
def self.parse_table_elements(str)
str = parse_inline(str, :ignore_newlines => true)
str.gsub!(/\[(\/?(?:tr|td|th|thead|tbody))\]/, '<\1>')
str
end
def self.parse_links(str)
str.gsub(/("[^"]+":(https?:\/\/|\/)[^\s\r\n<>]+|https?:\/\/[^\s\r\n<>]+|"[^"]+":\[(https?:\/\/|\/)[^\s\r\n<>\]]+\])+/) do |url|
ch = ""
if url =~ /^"([^"]+)":\[(.+)\]$/
text = $1
url = $2
else
if url =~ /^"([^"]+)":(.+)$/
text = $1
url = $2
else
text = url
end
if url =~ /([;,.!?\)\]<>])$/
url.chop!
ch = $1
end
end
'<a href="' + url + '">' + text + '</a>' + ch
end
end
def self.parse_aliased_wiki_links(str)
str.gsub(/\[\[([^\|\]]+)\|([^\]]+)\]\]/m) do
text = CGI.unescapeHTML($2)
title = CGI.unescapeHTML($1).tr(" ", "_").downcase
%{<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)
title = text.tr(" ", "_").downcase
%{<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 rel="nofollow" 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>})
str = str.gsub(/\btopic #(\d+)(?!\/p\d|\d)/i, %{<a href="/forum_topics/\\1">topic #\\1</a>})
str = str.gsub(/\btopic #(\d+)\/p(\d+)/i, %{<a href="/forum_topics/\\1?page=\\2">topic #\\1/p\\2</a>})
str = str.gsub(/\bcomment #(\d+)/i, %{<a href="/comments/\\1">comment #\\1</a>})
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>})
str = str.gsub(/\bartist #(\d+)/i, %{<a href="/artists/\\1">artist #\\1</a>})
str = str.gsub(/\bissue #(\d+)/i, %{<a href="https://github.com/r888888888/danbooru/issues/\\1">issue #\\1</a>})
str = str.gsub(/\bpixiv #(\d+)(?!\/p\d|\d)/i, %{<a href="http://www.pixiv.net/member_illust.php?mode=medium&illust_id=\\1">pixiv #\\1</a>})
str = str.gsub(/\bpixiv #(\d+)\/p(\d+)/i, %{<a href="http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id=\\1&page=\\2">pixiv #\\1/p\\2</a>})
end
def self.parse_list(str, options = {})
html = ""
current_item = ""
layout = []
nest = 0
str.split(/\n/).each do |line|
if line =~ /^\s*(\*+) (.+)/
if nest > 0
html += "<li>#{current_item}</li>"
elsif not current_item.strip.empty?
html += "<p>#{current_item}</p>"
end
nest = $1.size
current_item = parse_inline($2)
else
current_item += parse_inline(line)
end
if nest > layout.size
html += "<ul>"
layout << "ul"
end
while nest < layout.size
elist = layout.pop
if elist
html += "</#{elist}>"
end
end
end
html += "<li>#{current_item}</li>"
while layout.any?
elist = layout.pop
html += "</#{elist}>"
end
html
end
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*\[code\](?!\])/m, "\n\n[code]\n\n")
str.gsub!(/\[\/code\]\s*/m, "\n\n[/code]\n\n")
str.gsub!(/\s*\[spoilers?\](?!\])\s*/m, "\n\n[spoiler]\n\n")
str.gsub!(/\s*\[\/spoilers?\]\s*/m, "\n\n[/spoiler]\n\n")
str.gsub!(/^(h[1-6](\#[A-z][_A-z0-9-]+)?\.\s*.+)$/, "\n\n\\1\n\n")
str.gsub!(/\s*\[expand(\=[^\]]*)?\](?!\])\s*/m, "\n\n[expand\\1]\n\n")
str.gsub!(/\s*\[\/expand\]\s*/m, "\n\n[/expand]\n\n")
str.gsub!(/\s*\[table\](?!\])\s*/m, "\n\n[table]\n\n")
str.gsub!(/\s*\[\/table\]\s*/m, "\n\n[/table]\n\n")
end
str.gsub!(/(?:\r?\n){3,}/, "\n\n")
str.strip!
blocks = str.split(/(?:\r?\n){2}/)
stack = []
flags = {}
html = blocks.map do |block|
case block
when /\A(h[1-6])\.\s*(.+)\Z/
tag = $1
content = $2
if options[:inline]
"<h6>" + parse_inline(content, options) + "</h6>"
else
"<#{tag}>" + parse_inline(content, options) + "</#{tag}>"
end
when /\A(h[1-6])\#([A-z][_A-z0-9-]+)\.\s*(.+)\Z/
tag = $1
header_id = $2
content = $3
if options[:inline]
"<h6 id=\"dtext-#{header_id}\">" + parse_inline(content, options) + "</h6>"
else
"<#{tag} id=\"dtext-#{header_id}\">" + parse_inline(content, options) + "</#{tag}>"
end
when /^\s*\*+ /
parse_list(block, options)
when "[quote]"
if options[:inline]
""
else
stack << "blockquote"
"<blockquote>"
end
when "[/quote]"
if options[:inline]
""
elsif stack.last == "blockquote"
stack.pop
'</blockquote>'
else
""
end
when "[spoiler]"
stack << "spoiler"
'<div class="spoiler">'
when "[/spoiler]"
if stack.last == "spoiler"
stack.pop
"</div>"
else
""
end
when "[table]"
stack << "table"
flags[:table] = true
'<table class="striped">'
when "[/table]"
if stack.last == "table"
stack.pop
flags[:table] = false
"</table>"
else
""
end
when /\[code\](?!\])/
flags[:code] = true
stack << "pre"
'<pre>'
when /\[\/code\](?!\])/
flags[:code] = false
if stack.last == "pre"
stack.pop
"</pre>"
else
""
end
when /\[expand(?:\=([^\]]*))?\](?!\])/
stack << "expandable"
expand_html = '<div class="expandable"><div class="expandable-header">'
expand_html << "<span>#{h($1)}</span>" if $1.present?
expand_html << '<input type="button" value="Show" class="expandable-button"/></div>'
expand_html << '<div class="expandable-content">'
expand_html
when /\[\/expand\](?!\])/
if stack.last == "expandable"
stack.pop
'</div></div>'
end
else
if flags[:code]
CGI.escape_html(block) + "\n\n"
elsif flags[:table]
parse_table_elements(block)
else
'<p>' + parse_inline(block) + '</p>'
end
end
end
stack.reverse.each do |tag|
if tag == "blockquote"
html << "</blockquote>"
elsif tag == "div"
html << "</div>"
elsif tag == "pre"
html << "</pre>"
elsif tag == "spoiler"
html << "</div>"
elsif tag == "expandable"
html << "</div></div>"
elsif tag == "table"
html << "</table>"
end
end
html.join("").html_safe
end
def self.parse_strip(s)
strip(s)
end
def self.strip(s)
return "" if s.blank?
s.gsub!(/[\r\n]+/m, " ")
s.gsub!(/\[\/?(?:b|i|s|u|tn|tr|td|th|thead|tbody|quote|code|spoilers|spoiler|expand|table)\]/, "")
s.gsub!(/\[\[([^\|\]]+)\|([^\]]+)\]\]/m, '\2')
s.gsub!(/\[\[([^\]]+)\]\]/, '\1')
s.gsub!(/\{\{([^\}]+)\}\}/, '\1')
s.gsub!(/("[^"]+":(https?:\/\/|\/)[^\s\r\n<>]+|https?:\/\/[^\s\r\n<>]+|"[^"]+":\[(https?:\/\/|\/)[^\s\r\n<>\]]+\])+/) do |url|
if url =~ /^"([^"]+)":\[(.+)\]$/
$1
elsif url =~ /^"([^"]+)":(.+)$/
$1
else
url
end
end
s
end
def self.from_html(text, &block)
html = Nokogiri::HTML.fragment(text)

View File

@@ -10,7 +10,7 @@ class WikiPagePresenter
end
def blurb
DText.strip(excerpt.to_s)
DTextRagel.parse_strip(excerpt.to_s)
end
# Produce a formatted page that shows the difference between two versions of a page.

View File

@@ -15,7 +15,7 @@
<section id="original-artist-commentary">
<h3><%= artist_commentary.original_title %></h3>
<div class="prose">
<%= format_text(artist_commentary.original_description, :ragel => true, :disable_mentions => true) %>
<%= format_text(artist_commentary.original_description, :disable_mentions => true) %>
</div>
</section>
<% end %>
@@ -31,9 +31,9 @@
</h3>
<div class="prose">
<% if artist_commentary.translated_description.present? %>
<%= format_text(artist_commentary.translated_description, :ragel => true, :disable_mentions => true) %>
<%= format_text(artist_commentary.translated_description, :disable_mentions => true) %>
<% else %>
<span class="disabled"><%= format_text(artist_commentary.original_description, :ragel => true, :disable_mentions => true) %></span>
<span class="disabled"><%= format_text(artist_commentary.original_description, :disable_mentions => true) %></span>
<% end %>
</div>
</section>

View File

@@ -19,13 +19,13 @@
<td>
<h3><%= h(commentary.original_title) %></h3>
<div class="prose">
<%= format_text(commentary.original_description, :ragel => true) %>
<%= format_text(commentary.original_description, :disable_mentions => true) %>
</div>
</td>
<td>
<h3><%= h(commentary.translated_title) %></h3>
<div class="prose">
<%= format_text(commentary.translated_description, :ragel => true) %>
<%= format_text(commentary.translated_description, :disable_mentions => true) %>
</div>
</td>
</tr>

View File

@@ -34,12 +34,13 @@
<h3><%= h(commentary_version.original_title) %></h3>
<div class="prose">
<%= format_text(commentary_version.original_description) %>
<%= format_text(commentary_version.original_description, :disable_mentions => true) %>
</div>
</td>
<td>
<h3><%= h(commentary_version.translated_title) %></h3>
<div class="prose">
<%= format_text(commentary_version.translated_description) %>
<%= format_text(commentary_version.translated_description, :disable_mentions => true) %>
</div>
</td>
<% if CurrentUser.is_moderator? %>

View File

@@ -4,7 +4,7 @@
<% if @artist.notes.present? && @artist.visible? %>
<div class="prose">
<%= format_text(@artist.notes, :ragel => true, :disable_mentions => true) %>
<%= format_text(@artist.notes, :disable_mentions => true) %>
</div>
<p><%= link_to "View wiki page", @artist.wiki_page %></p>

View File

@@ -28,7 +28,7 @@
</td>
<td><%= time_ago_in_words_tagged(ban.created_at) %></td>
<td><%= humanized_duration(ban.created_at, ban.expires_at) %></td>
<td class="col-expand"><%= format_text ban.reason, :ragel => true %></td>
<td class="col-expand"><%= format_text ban.reason %></td>
<td>
<% if CurrentUser.is_moderator? %>
<%= link_to "Edit", edit_ban_path(ban) %>

View File

@@ -4,7 +4,7 @@
<ul style="margin-bottom: 1em;">
<li><strong>User</strong>: <%= link_to_user(@ban.user) %></li>
<li><strong>Expires</strong>: <%= compact_time @ban.expires_at %></li>
<li><strong>Reason</strong>: <%= format_text @ban.reason, :ragel => true %></li>
<li><strong>Reason</strong>: <%= format_text @ban.reason %></li>
</ul>
<%= form_tag(ban_path(@ban), :method => :delete) do %>

View File

@@ -14,7 +14,7 @@
</div>
<div class="content">
<div class="body prose">
<%= format_text(comment.body, :ragel => true) %>
<%= format_text(comment.body) %>
<% if comment.updated_at - comment.created_at > 5.minutes %>
<p class="info">Updated by <%= link_to_user comment.updater %> <%= time_ago_in_words_tagged(comment.updated_at) %></p>

View File

@@ -15,7 +15,7 @@
<h3>Body</h3>
<div class="prose">
<%= format_text(@dmail.body, :ragel => true) %>
<%= format_text(@dmail.body) %>
<% if @dmail.is_automated? %>
<p class="tn">

View File

@@ -13,7 +13,7 @@
</div>
<div class="content">
<div class="prose">
<%= format_text(forum_post.body, :ragel => true) %>
<%= format_text(forum_post.body) %>
</div>
<% if forum_post.updated_at - forum_post.created_at > 5.minutes %>
<p class="info">Updated by <%= link_to_user forum_post.updater %> <%= time_ago_in_words_tagged(forum_post.updated_at) %></p>

View File

@@ -16,7 +16,7 @@
<h3>Body</h3>
<div class="prose">
<%= format_text(@dmail.body, :ragel => true) %>
<%= format_text(@dmail.body) %>
</div>
</div>

View File

@@ -14,7 +14,7 @@
<tr>
<td><%= compact_time mod_action.created_at %></td>
<td><%= link_to_user mod_action.creator %></td>
<td><%= format_text(mod_action.description, :ragel => true) %></td>
<td><%= format_text(mod_action.description) %></td>
</tr>
<% end %>
</tbody>

View File

@@ -10,7 +10,7 @@
<% @dashboard.mod_actions.each do |mod_action| %>
<tr>
<td><%= link_to_user mod_action.creator %></td>
<td><%= format_text(mod_action.description, :ragel => true) %></td>
<td><%= format_text(mod_action.description) %></td>
</tr>
<% end %>
</tbody>

View File

@@ -11,7 +11,7 @@
<% @dashboard.user_feedbacks.each do |record| %>
<tr class="feedback-category-<%= record.category %>">
<td><%= link_to_user(record.user) %></td>
<td><%= format_text(record.body, :ragel => true) %></td>
<td><%= format_text(record.body) %></td>
<td><%= time_ago_in_words_tagged(record.created_at) %></td>
</tr>
<% end %>

View File

@@ -9,7 +9,7 @@
</h1>
<div id="description" class="prose">
<%= format_text(@pool.description, :ragel => true) %>
<%= format_text(@pool.description) %>
</div>
<%= render "posts/partials/common/inline_blacklist" %>

View File

@@ -1,4 +1,4 @@
<%= format_text(WikiPage.titled(Danbooru.config.appeal_notice_wiki_page).first.try(&:body), :ragel => true) %>
<%= format_text(WikiPage.titled(Danbooru.config.appeal_notice_wiki_page).first.try(&:body)) %>
<!-- XXX dtext_field expects there to be a `post_appeal` instance variable. -->
<% @post_appeal = post_appeal %>

View File

@@ -19,7 +19,7 @@
<% @post_appeals.each do |post_appeal| %>
<tr>
<td><%= PostPresenter.preview(post_appeal.post, :tags => "status:any") %></td>
<td><%= format_text post_appeal.reason, :ragel => true %></td>
<td><%= format_text post_appeal.reason %></td>
<td>
<%= link_to post_appeal.post.appeals.size, post_appeals_path(search: { post_id: post_appeal.post_id }) %>
</td>

View File

@@ -12,6 +12,6 @@
<% end %>
<% if disapprovals.map(&:message).any?(&:present?) %>
(messages: <%= disapprovals.map(&:message).select(&:present?).map { |msg| format_text(msg, ragel: true, inline: true) }.to_sentence.html_safe %>)
(messages: <%= disapprovals.map(&:message).select(&:present?).map { |msg| format_text(msg, inline: true) }.to_sentence.html_safe %>)
<% end %>
<% end %>

View File

@@ -15,7 +15,7 @@
<% end %>
<% if disapprovals.map(&:message).any?(&:present?) %>
Messages: <%= disapprovals.map(&:message).select(&:present?).map { |msg| format_text(msg, ragel: true, inline: true) }.to_sentence.html_safe %>.
Messages: <%= disapprovals.map(&:message).select(&:present?).map { |msg| format_text(msg, inline: true) }.to_sentence.html_safe %>.
<% end %>
</p>
<% end %>

View File

@@ -23,7 +23,7 @@
<i>hidden</i>
<% end %>
</td>
<td><%= format_text event.reason, :ragel => true %></td>
<td><%= format_text event.reason %></td>
<td>
<% if event.is_resolved %>
yes

View File

@@ -1,4 +1,4 @@
<%= format_text(WikiPage.titled(Danbooru.config.flag_notice_wiki_page).first.try(&:body), :ragel => true) %>
<%= format_text(WikiPage.titled(Danbooru.config.flag_notice_wiki_page).first.try(&:body)) %>
<!-- XXX dtext_field expects there to be a `post_flag` instance variable. -->
<% @post_flag = post_flag %>

View File

@@ -21,7 +21,7 @@
<tr class="resolved-<%= post_flag.is_resolved? %>">
<td><%= PostPresenter.preview(post_flag.post, :tags => "status:any") %></td>
<td>
<%= format_text post_flag.reason, :ragel => true %>
<%= format_text post_flag.reason %>
</td>
<td>
<%= link_to post_flag.post.flags.size, post_flags_path(search: { post_id: post_flag.post_id }) %>

View File

@@ -1,4 +1,4 @@
<%= format_text(WikiPage.titled(Danbooru.config.replacement_notice_wiki_page).first.try(&:body), ragel: true) %>
<%= format_text(WikiPage.titled(Danbooru.config.replacement_notice_wiki_page).first.try(&:body)) %>
<%= simple_form_for(post_replacement, url: post_replacements_path(post_id: post_replacement.post_id), method: :post) do |f| %>
<%= f.input :replacement_file, label: "File", as: :file %>

View File

@@ -8,7 +8,7 @@
<% if artist.visible? %>
<% unless artist.notes.blank? %>
<div class="prose">
<%= format_text(artist.notes, :ragel => true) %>
<%= format_text(artist.notes) %>
</div>
<% end %>
@@ -30,7 +30,7 @@
<p><%= wiki_page_other_names_list(wiki_page) %></p>
<% end %>
<%= format_text(wiki_page.presenter.excerpt, :ragel => true) %>
<%= format_text(wiki_page.presenter.excerpt) %>
<%= wiki_page_alias_and_implication_list(wiki_page) %>
<p class="links">
@@ -49,7 +49,7 @@
</h4>
<div id="description" class="prose">
<%= format_text(post_set.pool.description, :ragel => true) %>
<%= format_text(post_set.pool.description) %>
</div>
<p class="links">

View File

@@ -9,7 +9,7 @@
<li><strong>Creator</strong> <%= link_to_user @tag_alias.creator %></li>
<li><strong>Date</strong> <%= @tag_alias.created_at %></li>
<% if @tag_alias.respond_to?(:reason) && @tag_alias.reason.present? %>
<li><strong>Reason</strong> <%= format_text @tag_alias.reason, :ragel => true %></li>
<li><strong>Reason</strong> <%= format_text @tag_alias.reason %></li>
<% end %>
</ul>

View File

@@ -9,7 +9,7 @@
<li><strong>Creator</strong> <%= link_to_user @tag_implication.creator %></li>
<li><strong>Date</strong> <%= @tag_implication.created_at %></li>
<% if @tag_implication.respond_to?(:reason) && @tag_implication.reason.present? %>
<li><strong>Reason</strong> <%= format_text @tag_implication.reason, :ragel => true %></li>
<li><strong>Reason</strong> <%= format_text @tag_implication.reason %></li>
<% end %>
</ul>

View File

@@ -4,7 +4,7 @@
<% if CurrentUser.can_upload? %>
<div id="upload-guide-notice">
<%= format_text(@upload_notice_wiki.try(&:body), :ragel => true) %>
<%= format_text(@upload_notice_wiki.try(&:body)) %>
</div>
<% unless CurrentUser.can_upload_free? %>

View File

@@ -18,7 +18,7 @@
<td><%= link_to_user feedback.user %></td>
<td><%= link_to_user feedback.creator %></td>
<td><%= compact_time(feedback.created_at) %></td>
<td><%= format_text(feedback.body, :ragel => true) %></td>
<td><%= format_text(feedback.body) %></td>
<td>
<% if feedback.editable_by?(CurrentUser.user) %>
<%= link_to "edit", edit_user_feedback_path(feedback) %>

View File

@@ -6,7 +6,7 @@
<li><strong>Creator</strong> <%= link_to_user @user_feedback.creator %></li>
<li><strong>Date</strong> <%= @user_feedback.created_at %></li>
<li><strong>Category</strong> <%= @user_feedback.category %></li>
<li><strong>Message</strong> <%= format_text @user_feedback.body, :ragel => true %></li>
<li><strong>Message</strong> <%= format_text @user_feedback.body %></li>
</ul>
<% if @user_feedback.editable_by?(CurrentUser.user) %>

View File

@@ -4,7 +4,7 @@
<p>
<strong><%= forum_post.creator_name %> said:</strong>
</p>
<%= format_text(forum_post.body, :ragel => true) %>
<%= format_text(forum_post.body) %>
<br>
<hr>
<br>

View File

@@ -1,5 +1,5 @@
<div class="ui-corner-all ui-state-error" id="ban-notice">
<h1>Your account has been temporarily banned</h1>
<p>Reason: <%= format_text CurrentUser.user.recent_ban.reason, :ragel => true %></p>
<p>Reason: <%= format_text CurrentUser.user.recent_ban.reason %></p>
<p>Your ban will expire in <%= time_ago_in_words(CurrentUser.user.recent_ban.expires_at) %></p>
</div>

View File

@@ -25,7 +25,7 @@
<% if user.is_banned? && user.recent_ban %>
<tr>
<th>Ban reason</th>
<td><%= format_text presenter.ban_reason, :ragel => true %></td>
<td><%= format_text presenter.ban_reason %></td>
</tr>
<% end %>

View File

@@ -11,7 +11,7 @@
<p><%= wiki_page_other_names_list(@wiki_page_version) %></p>
<% end %>
<%= format_text(@wiki_page_version.body, :ragel => true) %>
<%= format_text(@wiki_page_version.body) %>
<% else %>
<p>The artist has requested removal of this page.</p>
<% end %>

View File

@@ -22,7 +22,7 @@
<p><%= wiki_page_other_names_list(@wiki_page) %></p>
<% end %>
<%= format_text(@wiki_page.body, :ragel => true) %>
<%= format_text(@wiki_page.body) %>
<% if @wiki_page.artist %>
<p><%= link_to "View artist", @wiki_page.artist %></p>

View File

@@ -1,196 +0,0 @@
require "test_helper"
class DTextTest < ActiveSupport::TestCase
def p(s)
DText.parse(s)
end
def test_mentions
assert_equal('<p><a href="/users?name=bob">@bob</a></p>', p("@bob"))
assert_equal('<p>hi <a href="/users?name=bob">@bob</a></p>', p("hi @bob"))
assert_equal('<p>this is not @.@ @_@ <a href="/users?name=bob">@bob</a></p>', p("this is not @.@ @_@ @bob"))
assert_equal('<p>multiple <a href="/users?name=bob">@bob</a> <a href="/users?name=anna">@anna</a></p>', p("multiple @bob @anna"))
end
def test_sanitize_heart
assert_equal('<p>&lt;3</p>', p("<3"))
end
def test_sanitize_less_than
assert_equal('<p>&lt;</p>', p("<"))
end
def test_sanitize_greater_than
assert_equal('<p>&gt;</p>', p(">"))
end
def test_sanitize_ampersand
assert_equal('<p>&amp;</p>', p("&"))
end
def test_wiki_links
assert_equal("<p>a <a href=\"/wiki_pages/show_or_new?title=b\">b</a> c</p>", p("a [[b]] c"))
end
def test_wiki_links_spoiler
assert_equal("<p>a <a href=\"/wiki_pages/show_or_new?title=spoiler\">spoiler</a> c</p>", p("a [[spoiler]] c"))
end
def test_spoilers_inline
assert_equal("<p>this is</p><div class=\"spoiler\"><p>an inline spoiler</p></div><p>.</p>", p("this is [spoiler]an inline spoiler[/spoiler]."))
end
def test_spoilers_block
assert_equal("<p>this is</p><div class=\"spoiler\"><p>a block spoiler</p></div><p>.</p>", p("this is\n\n[spoiler]\na block spoiler\n[/spoiler]."))
end
def test_spoilers_with_no_closing_tag_1
assert_equal("<div class=\"spoiler\"><p>this is a spoiler with no closing tag</p><p>new text</p></div>", p("[spoiler]this is a spoiler with no closing tag\n\nnew text"))
end
def test_spoilers_with_no_closing_tag_2
assert_equal("<div class=\"spoiler\"><p>this is a spoiler with no closing tag<br>new text</p></div>", p("[spoiler]this is a spoiler with no closing tag\nnew text"))
end
def test_spoilers_with_no_closing_tag_block
assert_equal("<div class=\"spoiler\"><p>this is a block spoiler with no closing tag</p></div>", p("[spoiler]\nthis is a block spoiler with no closing tag"))
end
def test_spoilers_nested
assert_equal("<div class=\"spoiler\"><p>this is</p><div class=\"spoiler\"><p>a nested</p></div><p>spoiler</p></div>", p("[spoiler]this is [spoiler]a nested[/spoiler] spoiler[/spoiler]"))
end
def test_paragraphs
assert_equal("<p>abc</p>", p("abc"))
end
def test_paragraphs_with_newlines_1
assert_equal("<p>a<br>b<br>c</p>", p("a\nb\nc"))
end
def test_paragraphs_with_newlines_2
assert_equal("<p>a</p><p>b</p>", p("a\n\nb"))
end
def test_headers
assert_equal("<h1>header</h1>", p("h1. header"))
end
def test_headers_with_ids
assert_equal("<h1 id=\"dtext-header-id\">header</h1>", p("h1#header-id. header"))
end
def test_quote_blocks
assert_equal('<blockquote><p>test</p></blockquote>', p("[quote]\ntest\n[/quote]"))
end
def test_quote_blocks_nested
assert_equal("<blockquote><p>a</p><blockquote><p>b</p></blockquote><p>c</p></blockquote>", p("[quote]\na\n[quote]\nb\n[/quote]\nc\n[/quote]"))
end
def test_code
assert_equal("<pre>for (i=0; i&lt;5; ++i) {\n printf(1);\n}\n\nexit(1);\n\n</pre>", p("[code]for (i=0; i<5; ++i) {\n printf(1);\n}\n\nexit(1);"))
end
def test_urls
assert_equal('<p>a <a href="http://test.com">http://test.com</a> b</p>', p('a http://test.com b'))
end
def test_urls_with_newline
assert_equal('<p><a href="http://test.com">http://test.com</a><br>b</p>', p("http://test.com\nb"))
end
def test_urls_with_paths
assert_equal('<p>a <a href="http://test.com/~bob/image.jpg">http://test.com/~bob/image.jpg</a> b</p>', p('a http://test.com/~bob/image.jpg b'))
end
def test_urls_with_fragment
assert_equal('<p>a <a href="http://test.com/home.html#toc">http://test.com/home.html#toc</a> b</p>', p('a http://test.com/home.html#toc b'))
end
def test_auto_urls
assert_equal('<p>a <a href="http://test.com">http://test.com</a>. b</p>', p('a http://test.com. b'))
end
def test_auto_urls_in_parentheses
assert_equal('<p>a (<a href="http://test.com">http://test.com</a>) b</p>', p('a (http://test.com) b'))
end
def test_old_style_links
assert_equal('<p><a href="http://test.com">test</a></p>', p('"test":http://test.com'))
end
def test_old_style_links_with_special_entities
assert_equal('<p>"1" <a href="http://three.com">2 &amp; 3</a></p>', p('"1" "2 & 3":http://three.com'))
end
def test_new_style_links
assert_equal('<p><a href="http://test.com">test</a></p>', p('"test":[http://test.com]'))
end
def test_new_style_links_with_parentheses
assert_equal('<p><a href="http://test.com/(parentheses)">test</a></p>', p('"test":[http://test.com/(parentheses)]'))
assert_equal('<p>(<a href="http://test.com/(parentheses)">test</a>)</p>', p('("test":[http://test.com/(parentheses)])'))
assert_equal('<p>[<a href="http://test.com/(parentheses)">test</a>]</p>', p('["test":[http://test.com/(parentheses)]]'))
end
def test_lists_1
assert_equal('<ul><li>a</li></ul>', p('* a'))
end
def test_lists_2
assert_equal('<ul><li>a</li><li>b</li></ul>', p("* a\n* b").gsub(/\n/, ""))
end
def test_lists_nested
assert_equal('<ul><li>a</li><ul><li>b</li></ul></ul>', p("* a\n** b").gsub(/\n/, ""))
end
def test_lists_inline
assert_equal('<ul><li><a href="/posts/1">post #1</a></li></ul>', p("* post #1").gsub(/\n/, ""))
end
def test_lists_not_preceded_by_newline
assert_equal('<p>ab</p><ul><li>c</li><li>d</li></ul>', p("a\nb\n* c\n* d").gsub(/\n/, ""))
end
def test_lists_with_multiline_items
assert_equal('<p>a</p><ul><li>bc</li><li>de</li></ul>', p("a\n* b\nc\n* d\ne").gsub(/\n/, ""))
end
def test_inline_tags
assert_equal('<p><a rel="nofollow" href="/posts?tags=tag">tag</a></p>', p("{{tag}}"))
end
def test_inline_tags_conjunction
assert_equal('<p><a rel="nofollow" href="/posts?tags=tag1+tag2">tag1 tag2</a></p>', p("{{tag1 tag2}}"))
end
def test_inline_tags_special_entities
assert_equal('<p><a rel="nofollow" href="/posts?tags=%3C3">&lt;3</a></p>', p("{{<3}}"))
end
def test_extra_newlines
assert_equal('<p>a</p><p>b</p>', p("a\n\n\n\n\n\n\nb\n\n\n\n"))
end
def test_complex_links_1
assert_equal("<p><a href=\"/wiki_pages/show_or_new?title=1\">2 3</a> | <a href=\"/wiki_pages/show_or_new?title=4\">5 6</a></p>", p("[[1|2 3]] | [[4|5 6]]"))
end
def test_complex_links_2
assert_equal("<p>Tags <strong>(<a href=\"/wiki_pages/show_or_new?title=howto%3Atag\">Tagging Guidelines</a> | <a href=\"/wiki_pages/show_or_new?title=howto%3Atag_checklist\">Tag Checklist</a> | <a href=\"/wiki_pages/show_or_new?title=tag_groups\">Tag Groups</a>)</strong></p>", p("Tags [b]([[howto:tag|Tagging Guidelines]] | [[howto:tag_checklist|Tag Checklist]] | [[Tag Groups]])[/b]"))
end
def test_table
assert_equal("<table class=\"striped\"><thead><tr><th>header</th></tr></thead><tbody><tr><td><a href=\"/posts/100\">post #100</a></td></tr></tbody></table>", p("[table][thead][tr][th]header[/th][/tr][/thead][tbody][tr][td]post #100[/td][/tr][/tbody][/table]"))
end
def test_table_with_newlines
assert_equal("<table class=\"striped\"><thead>\n<tr>\n<th>header</th></tr></thead><tbody><tr><td><a href=\"/posts/100\">post #100</a></td></tr></tbody></table>", p("[table]\n[thead]\n[tr]\n[th]header[/th][/tr][/thead][tbody][tr][td]post #100[/td][/tr][/tbody][/table]"))
end
def test_forum_links
assert_equal('<p><a href="/forum_topics/1234?page=4">topic #1234/p4</a></p>', p("topic #1234/p4"))
end
end