[DText] Prevent zalgo from overflowing

Deeply nested sections still exceed the expected width.
This commit is contained in:
Earlopain 2021-11-06 19:02:08 +01:00
parent b2b5938d5c
commit bad4340e15
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
51 changed files with 73 additions and 84 deletions

View File

@ -1,24 +1,7 @@
class DtextPreviewsController < ApplicationController
def create
@body = params[:body] || ""
@post_ids = Set.new
@html = ""
begin
parsed = DTextRagel.parse(@body, disable_mentions: true, allow_color: CurrentUser.user.is_privileged?)
raise DTextRagel::Error.new if parsed.nil?
@post_ids.merge(parsed[1]) if parsed[1].present?
@html = parsed[0].html_safe
rescue DTextRagel::Error => e
end
render json: {html: @html, posts: deferred_posts(@post_ids)}
end
private
def deferred_posts(ids)
Post.includes(:uploader).where(id: ids.to_a).find_each.reduce({}) do |post_hash, p|
post_hash[p.id] = p.minimal_attributes
post_hash
end
body = params[:body] || ""
dtext = helpers.format_text(body, allow_color: CurrentUser.user.is_privileged?)
render json: { html: dtext, posts: deferred_posts }
end
end

View File

@ -81,7 +81,7 @@ module ApplicationHelper
render "application/hideable_form_search", path: path, show_on_load: show_on_load, block: block
end
def format_text(text, **options)
def dtext_ragel(text, **options)
options.merge!(disable_mentions: true)
parsed = DTextRagel.parse(text, **options)
return raw "" if parsed.nil?
@ -91,8 +91,17 @@ module ApplicationHelper
raw ""
end
def format_text(text, **options)
# preserve the currrent inline behaviour
if options[:inline]
dtext_ragel(text, options)
else
raw %(<div class="styled-dtext">#{dtext_ragel(text, options)}</div>)
end
end
def strip_dtext(text)
format_text(text, strip: true)
dtext_ragel(text, strip: true)
end
def error_messages_for(instance_name)

View File

@ -1,4 +1,8 @@
.dtext-container {
overflow: auto;
word-wrap: anywhere;
overflow-wrap: anywhere;
}
.styled-dtext {
line-height: 1.4em;

View File

@ -3,7 +3,6 @@
div#c-blips {
article.blip {
margin-bottom: $base-padding;
word-wrap: break-word;
&[data-is-deleted="true"] {
background-color: $blip-hidden-background;

View File

@ -6,7 +6,6 @@ div.comments-for-post {
div.list-of-comments {
article.comment {
border-radius: $border-radius-half;
word-wrap: break-word;
margin-bottom: $padding-050;
&:target {
@ -83,7 +82,6 @@ div#c-comments {
padding-left: $padding-050;
padding-bottom: $padding-025;
margin-bottom: $padding-100;
word-wrap: break-word;
.comments {
margin-left: 2rem;

View File

@ -3,7 +3,6 @@
div.list-of-forum-posts {
article {
margin: 1em 0em;
word-wrap: break-word;
a.voted {
font-weight: bold;

View File

@ -40,8 +40,6 @@ div#c-users {
}
div {
flex-basis: 50%;
word-wrap: anywhere;
overflow-wrap: anywhere;
}
}

View File

@ -12,7 +12,7 @@
<% unless @user %>
<h4>On <%= link_to_user staff_note.user %></h4>
<% end %>
<div class="body styled-dtext">
<div class="body dtext-container">
<%= format_text(staff_note.body, allow_color: true) %>
</div>
</div>

View File

@ -14,7 +14,7 @@
<% if artist_commentary.original_present? %>
<%= tag.section id: "original-artist-commentary", style: ("display: none" if artist_commentary.translated_present?) do %>
<h4><%= artist_commentary.original_title %></h4>
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(artist_commentary.original_description) %>
</div>
<% end %>
@ -29,7 +29,7 @@
<span class="disabled"><%= artist_commentary.original_title %></span>
<% end %>
</h4>
<div class="styled-dtext">
<div class="dtext-container">
<% if artist_commentary.translated_description.present? %>
<%= format_text(artist_commentary.translated_description, :disable_mentions => true) %>
<% else %>

View File

@ -18,13 +18,13 @@
<td><%= PostPresenter.preview(commentary.post, :tags => "status:any") %></td>
<td>
<h3><%= h(commentary.original_title) %></h3>
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(commentary.original_description) %>
</div>
</td>
<td>
<h3><%= h(commentary.translated_title) %></h3>
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(commentary.translated_description) %>
</div>
</td>

View File

@ -21,13 +21,13 @@
<td><%= link_to commentary_version.post_id, post_path(commentary_version.post_id) %></td>
<td>
<h3><%= h(commentary_version.original_title) %></h3>
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(commentary_version.original_description) %>
</div>
</td>
<td>
<h3><%= h(commentary_version.translated_title) %></h3>
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(commentary_version.translated_description) %>
</div>
</td>

View File

@ -20,13 +20,13 @@
<td><%= link_to "#{commentary_version.post_id}.#{commentary_version.id}»", artist_commentary_versions_path(search: {post_id: commentary_version.post_id}) %></td>
<td>
<h3><%= h(commentary_version.original_title) %></h3>
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(commentary_version.original_description) %>
</div>
</td>
<td>
<h3><%= h(commentary_version.translated_title) %></h3>
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(commentary_version.translated_description) %>
</div>
</td>

View File

@ -3,7 +3,7 @@
<h1>Artist: <%= link_to @artist.pretty_name, posts_path(:tags => @artist.name), :class => "tag-type-#{@artist.category_name}" %></h1>
<% if @artist.notes.present? && @artist.visible? %>
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(@artist.notes) %>
</div>

View File

@ -30,7 +30,7 @@
<td><%= time_ago_in_words_tagged(ban.created_at) %></td>
<td><%= ban.humanized_duration %></td>
<td><%= ban.humanized_expiration %></td>
<td class="col-expand styled-dtext"><%= format_text ban.reason %></td>
<td class="col-expand dtext-container"><%= format_text ban.reason %></td>
<td>
<% if CurrentUser.is_moderator? %>
<%= link_to "Edit", edit_ban_path(ban) %>

View File

@ -5,7 +5,7 @@
<li><strong>User</strong>: <%= link_to_user(@ban.user) %></li>
<li><strong>Expires</strong>: <%= @ban.humanized_expiration %></li>
<li><strong>Reason</strong>:
<div class="styled-dtext"><%= format_text @ban.reason %>
<div class="dtext-container"><%= format_text @ban.reason %>
</div>
</li>
</ul>

View File

@ -20,7 +20,7 @@
<% if blip.response? %>
<h6><%= link_to "In response to blip ##{blip.response_to}", blip_path(id: blip.response_to) %> </h6>
<% end %>
<div class="body styled-dtext">
<div class="body dtext-container">
<%= format_text(blip.body, allow_color: blip.creator.is_privileged?) %>
</div>
<% if blip.was_warned? %>

View File

@ -19,7 +19,7 @@
</div>
</div>
<div class="content">
<div class="body styled-dtext">
<div class="body dtext-container">
<%= format_text(comment.body, allow_color: comment.creator.is_privileged?) %>
<%= render "application/update_notice", record: comment %>

View File

@ -16,7 +16,7 @@
<td><%= link_to post.id, post_path(post) %></td>
<td><%= link_to_user post.uploader %></td>
<td><%= post.tag_string %></td>
<td class="styled-dtext"><%= format_text(post.flags.order(id: :desc).first&.reason) %></td>
<td class="dtext-container"><%= format_text(post.flags.order(id: :desc).first&.reason) %></td>
</tr>
<% end %>
</tbody>

View File

@ -14,7 +14,7 @@
</ul>
<h3>Body</h3>
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(@dmail.body) %>
<% if @dmail.is_automated? %>

View File

@ -8,7 +8,7 @@
<% else %>
<input type="text" id="<%= input_id %>" class="text optional <%= input_classes %>" name="<%= input_name %>" value="<%= value %>">
<% end %>
<div id="<%= preview_id %>" class="dtext-preview styled-dtext"></div>
<div id="<%= preview_id %>" class="dtext-preview dtext-container"></div>
</div>
<span class="hint">All text is formatted using <%= link_to "DText", help_page_path(id: "dtext"), :target => "_blank", tabindex: "-1" %></span>
</div>

View File

@ -19,7 +19,7 @@
</div>
</div>
<div class="content">
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(parse_embedded_tag_request_text(forum_post.body), allow_color: forum_post.creator.is_privileged?) %>
</div>
<%= render "application/update_notice", record: forum_post %>

View File

@ -4,7 +4,7 @@
<section id="content">
<div style="margin-bottom: 1em;">
<h1><%= "Help: #{HelpPage.title(@help.name)}" %></h1>
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(@wiki_page.body, allow_color: true) %>
</div>
</div>

View File

@ -15,7 +15,7 @@
</ul>
<h3>Body</h3>
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(@dmail.body) %>
</div>
</div>

View File

@ -17,7 +17,7 @@
<tr>
<td><%= compact_time mod_action.created_at %></td>
<td><%= link_to_user mod_action.creator %></td>
<td class="styled-dtext"><%= format_text(mod_action.format_description) %></td>
<td class="dtext-container"><%= format_text(mod_action.format_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 class="styled-dtext"><%= format_text(mod_action.format_description) %></td>
<td class="dtext-container"><%= format_text(mod_action.format_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 class="styled-dtext"><%= format_text(record.body) %></td>
<td class="dtext-container"><%= format_text(record.body) %></td>
<td><%= time_ago_in_words_tagged(record.created_at) %></td>
</tr>
<% end %>

View File

@ -5,6 +5,6 @@
(<%= time_ago_in_words NewsUpdate.recent[0].created_at %> ago)
<span id="news-showtext" class="showtext">Click to show.</span>
</h6>
<div class="newsbody styled-dtext"><%= format_text(NewsUpdate.recent[0].message) %></div>
<div class="newsbody dtext-container"><%= format_text(NewsUpdate.recent[0].message) %></div>
</div>
<% end %>

View File

@ -1,3 +1,3 @@
<% if NewsUpdate.recent.present? %>
<div class="styled-dtext"><%= format_text(NewsUpdate.recent[0].message) %></div>
<div class="dtext-container"><%= format_text(NewsUpdate.recent[0].message) %></div>
<% end %>

View File

@ -18,7 +18,7 @@
<tr id="news-update-<%= news_update.id %>">
<td><%= link_to_user news_update.creator %></td>
<td><%= compact_time news_update.updated_at %></td>
<td><div class="styled-dtext"><%= format_text news_update.message %></div></td>
<td><div class="dtext-container"><%= format_text news_update.message %></div></td>
<% if CurrentUser.is_moderator? %>
<td><%= link_to "Edit", edit_news_update_path(news_update) %> | <%= link_to "Delete", news_update_path(news_update), :method => :delete %></td>
<% end %>

View File

@ -8,7 +8,7 @@
<% end %>
</h2>
<div id="description" class="styled-dtext">
<div id="description" class="dtext-container">
<%= format_text(@pool.description) %>
</div>

View File

@ -1,5 +1,5 @@
<div class="appeal-dialog-body">
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(WikiPage.titled(Danbooru.config.appeal_notice_wiki_page).first.try(&:body)) %>
</div>

View File

@ -23,7 +23,7 @@
<% end %>
<br><%= time_ago_in_words_tagged event.created_at %>
</td>
<td class="col-expand styled-dtext"><%= format_text event.reason %></td>
<td class="col-expand dtext-container"><%= format_text event.reason %></td>
<td><%= event.is_resolved %></td>
</tr>
<% end %>

View File

@ -5,7 +5,7 @@
</div>
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(WikiPage.titled(Danbooru.config.flag_notice_wiki_page).first.try(&:body)) %>
</div>
</div>
@ -23,7 +23,7 @@
<% Danbooru.config.flag_reasons.each do |flag_reason| %>
<%= radio_button_tag "post_flag[reason_name]", flag_reason[:name], false %>
<label for="post_flag_reason_name_<%= flag_reason[:name] %>"><%= format_text(flag_reason[:reason], inline: true) %></label>
<div class="styled-dtext"><%= format_text(flag_reason[:text]) %></div>
<div class="dtext-container"><%= format_text(flag_reason[:text]) %></div>
<% if flag_reason[:parent] %>
<%= f.input :parent_id, as: :integer, label: "Inferior of Post #" %>
@ -36,7 +36,7 @@
<%= radio_button_tag "post_flag[reason_name]", "user", false, disabled: !(@post.uploader_id == CurrentUser.id && @post.created_at > 48.hours.ago) %>
<label for="post_flag_reason_name_user">I'm the uploader, and I uploaded the file by mistake (only possible within 48 hours of uploading).</label>
<div class="styled-dtext"><%= format_text(Danbooru.config.flag_reason_48hours) %></div>
<div class="dtext-container"><%= format_text(Danbooru.config.flag_reason_48hours) %></div>
<% if @post.uploader_id == CurrentUser.id && @post.created_at > 48.hours.ago %>
<%= dtext_field "post_flag", "user_reason", name: "Reason", preview_id: "dtext-preview-for-post-flag", type: "string" %>
<% end %>

View File

@ -20,7 +20,7 @@
<% @post_flags.each do |post_flag| %>
<tr class="resolved-<%= post_flag.is_resolved? %>">
<td><%= PostPresenter.preview(post_flag.post, :tags => "status:any") %></td>
<td class="styled-dtext">
<td class="dtext-container">
<%= format_text post_flag.reason %>
</td>
<td>

View File

@ -1,5 +1,5 @@
<div class="replace-image-dialog-body">
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(WikiPage.titled(Danbooru.config.replacement_notice_wiki_page).first.try(&:body)) %>
</div>

View File

@ -25,7 +25,7 @@
<% if @post_set.description.blank? %>
<div class='set-description'>No description.</div>
<% else %>
<div class='set-description styled-dtext'><%= format_text @post_set.description %></div>
<div class='set-description dtext-container'><%= format_text @post_set.description %></div>
<% end %>
<div class='set-description-bottom'></div>

View File

@ -43,7 +43,7 @@
<h2>Description</h2>
<div class="closebutton">X</div>
<div class='desc-popup-inner'>
<p class="styled-dtext"><%= format_text(post_version.description) %></p>
<p class="dtext-container"><%= format_text(post_version.description) %></p>
</div>
</div>
<% end %>
@ -74,4 +74,3 @@
</div>
<% end %>
</div>

View File

@ -5,7 +5,7 @@
<% post_set.artist.tap do |artist| %>
<% if artist.visible? %>
<% unless artist.notes.blank? %>
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(artist.notes) %>
</div>
<% end %>
@ -23,7 +23,7 @@
<% end %>
<% elsif post_set.wiki_page.present? %>
<% post_set.wiki_page.tap do |wiki_page| %>
<div class="styled-dtext">
<div class="dtext-container">
<% if wiki_page.other_names.present? %>
<p><%= wiki_page_other_names_list(wiki_page) %></p>
<% end %>
@ -46,7 +46,7 @@
<% end %>
</h4>
<div id="description" class="styled-dtext">
<div id="description" class="dtext-container">
<%= format_text(post_set.pool.description) %>
</div>

View File

@ -156,7 +156,7 @@
<span class="section-arrow"></span>
<span>Description</span>
</div>
<div class="expandable-content styled-dtext original-artist-commentary">
<div class="expandable-content dtext-container original-artist-commentary">
<%= format_text(@post.description, max_thumbs: 0) %>
</div>
</div>

View File

@ -1,7 +1,7 @@
<div id="c-static">
<div id="a-terms-of-service">
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(@page.body, allow_color: true) %>
</div>

View File

@ -101,7 +101,7 @@
<% if !@takedown.notes.blank? && @takedown.notes.downcase != "none" %>
<h3>Admin notes</h3>
<div class="box-section styled-dtext">
<div class="box-section dtext-container">
<% if !@takedown.reason_hidden || CurrentUser.is_admin? %>
<%= format_text(@takedown.notes) %>
<% if @takedown.reason_hidden %><span class="redtext">(HIDDEN)</span><% end %>

View File

@ -64,7 +64,7 @@
<% end %>
<% if @ticket.can_see_reason?(CurrentUser) %>
<td class="styled-dtext"><%= format_text(@ticket.reason) %></td>
<td class="dtext-container"><%= format_text(@ticket.reason) %></td>
<% else %>
<td><span style="cursor:help;" class="redtext" title="Due to privacy concerns, this information is confidential">Confidential</span></td>
<% end %>
@ -83,7 +83,7 @@
<tr>
<td><span class='title'>Response</span></td>
<% if @ticket.can_see_response?(CurrentUser) %>
<td class="styled-dtext"><%= format_text(!@ticket.response.blank? ? @ticket.response : "No response.") %></td>
<td class="dtext-container"><%= format_text(!@ticket.response.blank? ? @ticket.response : "No response.") %></td>
<% else %>
<td><span style="cursor:help;" class="redtext" title="Due to privacy concerns, this information is confidential">Confidential</span></td>
<% end %>

View File

@ -19,7 +19,7 @@
<td><%= link_to_user feedback.creator %></td>
<td><%= compact_time(feedback.created_at) %></td>
<td>
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(feedback.body) %>
</div>
<%= render "application/update_notice", record: feedback, interval: 0.minutes %>

View File

@ -7,7 +7,7 @@
<li><strong>Date</strong> <%= @user_feedback.created_at %></li>
<li><strong>Category</strong> <%= @user_feedback.category %></li>
<li><strong>Message</strong>
<div class="styled-dtext"><%= format_text @user_feedback.body %></div></li>
<div class="dtext-container"><%= format_text @user_feedback.body %></div></li>
</ul>
<% if @user_feedback.editable_by?(CurrentUser.user) %>

View File

@ -3,7 +3,7 @@
<body>
<p><%= @dmail.from.name %> said:</p>
<div class="styled-dtext">
<div class="dtext-container">
<%= format_text(@dmail.body, base_url: root_url, max_thumbs: 0) %>
</div>

View File

@ -2,13 +2,13 @@
<% if user.profile_about.present? %>
<div class="box-section about-piece" id="about-info">
<h3>About:</h3>
<div class="content styled-dtext"><%= format_text(user.profile_about, allow_color: true) %></div>
<div class="content dtext-container"><%= format_text(user.profile_about, allow_color: true) %></div>
</div>
<% end %>
<% if user.profile_artinfo.present? %>
<div class="box-section about-piece" id="about-artinfo">
<h3>Artist Information:</h3>
<div class="content styled-dtext"><%= format_text(user.profile_artinfo, allow_color: true) %></div>
<div class="content dtext-container"><%= format_text(user.profile_artinfo, allow_color: true) %></div>
</div>
<% end %>
</div>

View File

@ -1,5 +1,5 @@
<div class="ui-corner-all site-notice" id="ban-notice">
<h1>Your account has been banned</h1>
<div class="styled-dtext">Reason: <%= format_text CurrentUser.user.recent_ban.reason %></div>
<div class="dtext-container">Reason: <%= format_text CurrentUser.user.recent_ban.reason %></div>
<p>Ban expires: <%= CurrentUser.user.recent_ban.expire_days %></p>
</div>

View File

@ -23,7 +23,7 @@
<% if user.is_banned? && user.recent_ban %>
<tr>
<th>Ban reason</th>
<td class="styled-dtext"><%= format_text presenter.ban_reason %></td>
<td class="dtext-container"><%= format_text presenter.ban_reason %></td>
</tr>
<% end %>

View File

@ -5,7 +5,7 @@
<section id="content">
<h1 id="wiki-page-title"><%= @wiki_page_version.pretty_title %> <span class="version">(<%= time_ago_in_words_tagged(@wiki_page_version.updated_at) %>)</span></h1>
<div id="wiki-page-body" class="dtext styled-dtext">
<div id="wiki-page-body" class="dtext dtext-container">
<% if @wiki_page_version.visible? %>
<% if @wiki_page_version.other_names.present? %>
<p><%= wiki_page_other_names_list(@wiki_page_version) %></p>

View File

@ -16,7 +16,7 @@
<% end %>
</h1>
<div id="wiki-page-body" class="styled-dtext">
<div id="wiki-page-body" class="dtext-container">
<% if @wiki_page.visible? %>
<%= format_text(@wiki_page.body, allow_color: true, max_thumbs: 75) %>

View File

@ -6,7 +6,7 @@
<h1 id="wiki-page-title">
<%= link_to @wiki_page.pretty_title_with_category, posts_path(:tags => @wiki_page.title), :class => "tag-type-#{@wiki_page.category_name}" %>
</h1>
<div id="wiki-page-body" class="styled-dtext">
<div id="wiki-page-body" class="dtext-container">
<p>This wiki page does not exist. <%= link_to "Create new wiki page", new_wiki_page_path(:wiki_page => {:title => params[:title]}) %>.</p>
</div>