CKEditor从Rails中的span类中剥离样式元素

时间:2015-11-03 18:49:12

标签: javascript html css ruby-on-rails ckeditor

我使用的是Rails 4.1.4和ruby 2.1.2以及CKeditor 4.1.1。我正在使用它与Rails管理员。当我将文本放入文本区域并选择字体或字体大小时,它会保存它。但是,在进入视图时,我希望: <span style="font-size 36pt">text</span>而我有<span>text</span>

我同时尝试了config.allowedContent = true;config.extraAllowedContent = 'style;*[id,rel](*){*}';以及两者。

我认为这可能是rails_html_sanitizer的一个问题,所以这就是我现在所拥有的: HTML::WhiteListSanitizer.allowed_tags.merge(%w(iframe table tbody tr td tfoot thead colgroup col style)) HTML::WhiteListSanitizer.allowed_attributes.merge(%w(target))

我希望能够将CKeditors选项用于字体和字体大小,但是现在它正在从span类中剥离出样式。我已经读到了config.js文件的所有其他答案,但到目前为止它还没有为我工作。任何其他方向将不胜感激。感谢。

1 个答案:

答案 0 :(得分:0)

以前,在我看来,我有: <% @docs.each do |doc| %> <%= doc.title.html_safe %> <%= doc.discription.html_safe %> <%= doc.text.html_safe %> <% end %>

我通过添加'sanitize'来修复此问题(因为我使用的是rails_html_sanitizer,如原始Q中所示,将'样式'列入白名单):

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

你也可以通过'raw'解决这个问题:

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

相关问题