mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:04:11 +08:00
FIX: Digest styling for oneboxes
This commit is contained in:
parent
959218c7cd
commit
2d15c82b26
|
@ -1,5 +1,13 @@
|
|||
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
|
||||
result = ""
|
||||
|
@ -29,14 +37,25 @@ module UserNotificationsHelper
|
|||
"<a href='#{Discourse.base_url}'>#{@site_name}</a>"
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user