简体   繁体   中英

CKEditor Stripping Style elements from span classes in Rails

I am using Rails 4.1.4 and ruby 2.1.2 and CKeditor 4.1.1. I am using it with Rails Admin. When I put text into the text area and select a font or font size, it saves it. However, when going to the view I expect: <span style="font-size 36pt">text</span> and instead I have <span>text</span> .

I have tried both config.allowedContent = true; and config.extraAllowedContent = 'style;*[id,rel](*){*}'; and both of them together, too.

I thought it might be a problem with rails_html_sanitizer, so this is what I have for that right now: HTML::WhiteListSanitizer.allowed_tags.merge(%w(iframe table tbody tr td tfoot thead colgroup col style)) HTML::WhiteListSanitizer.allowed_attributes.merge(%w(target))

I would like to be able to use CKeditors options for font and font size, but right now it is stripping the style out of the span classes. Every other answer I've read points to the config.js file, but it's so far not working for me. Any other direction would be appreciated. Thanks.

Previous, in my view, I had: <% @docs.each do |doc| %> <%= doc.title.html_safe %> <%= doc.discription.html_safe %> <%= doc.text.html_safe %> <% end %> <% @docs.each do |doc| %> <%= doc.title.html_safe %> <%= doc.discription.html_safe %> <%= doc.text.html_safe %> <% end %>

I fixed this by adding 'sanitize' (since I am using rails_html_sanitizer, as as shown in original Q, have 'style' whitelisted):

<% @docs.each do |doc| %> <%= sanitize doc.title.html_safe %> <%= sanitize doc.discription.html_safe %> <%= sanitize doc.text.html_safe %> <% end %>

You could also fix this by having 'raw':

<% @docs.each do |doc| %> <%= sanitize doc.title.html_safe %> <%= sanitize doc.discription.html_safe %> <%= sanitize doc.text.html_safe %> <% end %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM