diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb index b93033f8c39..b228b28ddd0 100644 --- a/app/helpers/user_notifications_helper.rb +++ b/app/helpers/user_notifications_helper.rb @@ -1,4 +1,12 @@ module UserNotificationsHelper + + def self.sanitize_options + return @sanitize_options if @sanitize_options + @sanitize_options = Sanitize::Config::RELAXED.deep_dup + @sanitize_options[:elements] << 'aside' << 'div' + @sanitize_options[:attributes][:all] << 'class' + @sanitize_options + end def indent(text, by=2) spacer = " " * by @@ -29,14 +37,25 @@ module UserNotificationsHelper "#{@site_name}" end + def first_paragraph_from(html) + doc = Nokogiri::HTML(html) + doc.css('p').each do |p| + return p if p.text.present? + end + + # If there is no first paragaph, return the first div (onebox) + doc.css('div').first + end + def email_excerpt(html, posts_count) # If there's only one post, include the whole thing. if posts_count == 1 - return raw Sanitize.clean(html, Sanitize::Config::RELAXED) + raw Sanitize.clean(html, sanitize_options) else # Otherwise, try just the first paragraph. - first_paragraph = Nokogiri::HTML(html).at('p') - return raw Sanitize.clean(first_paragraph.to_s, Sanitize::Config::RELAXED) + para = first_paragraph_from(html) + Rails.logger.info ">>> #{para}" + raw Sanitize.clean(para.to_s, UserNotificationsHelper.sanitize_options) end end end diff --git a/lib/email/styles.rb b/lib/email/styles.rb index 9b5364b3cc8..d1f2be693ff 100644 --- a/lib/email/styles.rb +++ b/lib/email/styles.rb @@ -63,6 +63,20 @@ module Email style('pre', 'word-wrap: break-word; max-width: 694px;') style('code', 'background-color: #f1f1ff; padding: 2px 5px;') style('pre code', 'display: block; background-color: #f1f1ff; padding: 5px;') + + # Links to other topics + style('aside.quote', 'border-left: 5px solid #bebebe; background-color: #f1f1f1; padding: 12px;') + style('aside.quote blockquote', 'border: 0px; padding: 0') + style('aside.quote div.info-line', 'color: #666; margin: 10px 0') + style('aside.quote .avatar', 'margin-right: 5px') + + # Oneboxes + style('div.onebox-result', "padding: 12px 25px 12px 12px; border-left: 5px solid #bebebe; background: #eee;") + style('div.onebox-result img', "max-height: 80%; max-width: 25%; height: auto; float: left; margin-right: 10px;") + style('div.onebox-result h3', "border-bottom: 0") + style('div.onebox-result .source', "margin-bottom: 8px") + style('div.onebox-result .source a[href]', "color: #333; font-weight: normal") + style('div.clearfix', "clear: both") end def to_html