Skip to content
Snippets Groups Projects
Commit 38f102a4 authored by pabois's avatar pabois
Browse files

Merge branch 'master' of github.com:noesya/osuny

parents 5bf00b87 7cf804f7
No related branches found
No related tags found
No related merge requests found
......@@ -122,7 +122,7 @@ class Communication::Website::Imported::Post < ApplicationRecord
content_type: featured_medium.file.blob.content_type
)
else
fragment = Nokogiri::HTML.fragment(post.text.to_s)
fragment = Nokogiri::HTML.fragment(post.text.body.to_html)
image = fragment.css('img').first
if image.present?
begin
......@@ -135,6 +135,6 @@ class Communication::Website::Imported::Post < ApplicationRecord
end
end
end
post.update(text: rich_text_with_attachments(post.text.to_s))
post.update(text: rich_text_with_attachments(post.text.body.to_html))
end
end
module Communication::Website::Imported::WithRichText
extend ActiveSupport::Concern
# https://github.com/basecamp/trix/blob/7940a9a3b7129f8190ef37e086809260d7ccfe32/src/trix/models/attachment.coffee#L4
TRIX_PREVIEWABLE_PATTERN = /^image(\/(gif|png|jpe?g)|$)/
protected
def rich_text_with_attachments(text)
......@@ -16,7 +19,14 @@ module Communication::Website::Imported::WithRichText
begin
url = node.attr(attribute_name)
blob = load_blob_from_url(url)
node.replace ActionText::Attachment.from_attachable(blob).node.to_s
blob.analyze
blob_path = Rails.application.routes.url_helpers.rails_blob_path(blob, only_path: true)
attachment_node = ActionText::Attachment.from_attachable(blob).node
attachment_node['url'] = "#{university.url}#{blob_path}"
attachment_node['width'] = blob.metadata['width']
attachment_node['height'] = blob.metadata['height']
attachment_node['presentation'] = TRIX_PREVIEWABLE_PATTERN.match?(blob.content_type) ? 'gallery' : nil
node.replace attachment_node.to_s
rescue
end
end
......
......@@ -24,6 +24,7 @@ class Wordpress
]
}),
elements: Set.new(Sanitize::Config::RELAXED[:elements]) - ['div', 'style'] + ['iframe'],
remove_contents: ['math', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'xmp'],
whitespace_elements: {
'div' => { :before => "", :after => "" }
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment